gyang94 commented on code in PR #3558:
URL: https://github.com/apache/fluss/pull/3558#discussion_r3585516766


##########
fluss-server/src/main/java/org/apache/fluss/server/utils/TableDescriptorValidation.java:
##########
@@ -518,6 +554,25 @@ private static void checkPartition(
                                             + "partition is enabled, please 
set table property '%s'.",
                                     
ConfigOptions.TABLE_AUTO_PARTITION_TIME_UNIT.key()));
                 }
+
+                if (enforceDateDayFormatCompatibility
+                        && autoPartition.timeUnit() == 
AutoPartitionTimeUnit.DAY) {
+                    String autoPartitionKey =
+                            
StringUtils.isNullOrWhitespaceOnly(autoPartition.key())
+                                    ? partitionKeys.get(0)
+                                    : autoPartition.key();
+                    DataType autoPartitionDataType =
+                            
rowType.getTypeAt(rowType.getFieldIndex(autoPartitionKey));
+                    if (autoPartitionDataType.getTypeRoot() == 
DataTypeRoot.DATE
+                            && autoPartition.dayFormat() != 
AutoPartitionDayFormat.YYYY_MM_DD) {
+                        throw new InvalidTableException(
+                                String.format(
+                                        "Table property '%s' must be '%s' when 
auto partition key '%s' has DATE type.",
+                                        
ConfigOptions.TABLE_AUTO_PARTITION_DAY_FORMAT.key(),
+                                        
AutoPartitionDayFormat.YYYY_MM_DD.pattern(),
+                                        autoPartitionKey));

Review Comment:
   When we convert a DATE type value to a partition name( in 'string' type), we 
have a hidden assumption that it is in the 'yyyy-MM-dd' fomat. See 
`PartitionNameConverters.dayToString()` and 
`PartitionNameConverters.parseDayString()`.
   
   ```
   public static String dayToString(int days) {
       OffsetDateTime day = EPOCH.plusDays(days);
       return String.format(
               Locale.ROOT,
               "%04d-%02d-%02d",
               day.getYear(),
               day.getMonth().getValue(),
               day.getDayOfMonth());
   }
   
   public static int parseDayString(String dayStr) {
       String[] parts = dayStr.split("-");
       int year = Integer.parseInt(parts[0]);
       int month = Integer.parseInt(parts[1]);
       int day = Integer.parseInt(parts[2]);
       LocalDateTime date = LocalDateTime.of(year, month, day, 0, 0);
       long epochDay = date.toLocalDate().toEpochDay();
       return (int) epochDay;
   }
   ```
   Thus if our auto partition is not in `yyyy-MM-dd`, the partition name of a 
row data will not match the auto partition name.
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to