jerryshao commented on code in PR #14883:
URL: https://github.com/apache/gravitino/pull/14883#discussion_r4537234816


##########
maintenance/optimizer/src/main/java/org/apache/gravitino/maintenance/optimizer/recommender/job/PartitionUtils.java:
##########
@@ -156,16 +197,41 @@ private static String formatLiteral(Transform transform, 
Column column, String r
       case DECIMAL:
         return rawValue;
       case DATE:
-        return "DATE '" + rawValue + "'";
       case TIMESTAMP:
-        return "TIMESTAMP '" + rawValue + "'";
       case TIME:
-        return "TIME '" + rawValue + "'";
+        // Same CALL embedding constraint as days(); see class Javadoc.
+        return type.name() + " \"" + rawValue + "\"";

Review Comment:
   rawValue is inserted unescaped for DATE, TIMESTAMP and TIME, unlike the 
string case that uses escapeStringLiteral. A value containing a double quote or 
backslash would break the CALL where clause; escape it or validate the value 
against the expected format.



##########
maintenance/optimizer/src/main/java/org/apache/gravitino/maintenance/optimizer/recommender/job/PartitionUtils.java:
##########
@@ -82,11 +105,14 @@ public static String getWhereClauseForPartition(
       Transform transform = partitioning[i];
 
       String columnName = getColumnName(transform);
-      Column column =
-          Preconditions.checkNotNull(
-              columnMap.get(columnName.toLowerCase(Locale.ROOT)),
-              "Column '%s' not found in table schema",
-              columnName);
+      // Nested paths like event.ts are absent from schema; fall back to 
top-level event.
+      Column column = columnMap.get(columnName.toLowerCase(Locale.ROOT));
+      if (column == null && columnName.indexOf('.') >= 0) {

Review Comment:
   For a nested path like event.ts, the fallback uses the top-level struct 
column, so formatLiteral sees a STRUCT type and quotes the value as a plain 
string. An identity partition on a nested int or timestamp then compares 
against the wrong type; resolve the real nested field type, or reject nested 
identity columns with a clear error. Please also add a test for it.



##########
maintenance/optimizer/src/main/java/org/apache/gravitino/maintenance/optimizer/recommender/job/PartitionUtils.java:
##########
@@ -156,16 +197,41 @@ private static String formatLiteral(Transform transform, 
Column column, String r
       case DECIMAL:
         return rawValue;
       case DATE:
-        return "DATE '" + rawValue + "'";
       case TIMESTAMP:
-        return "TIMESTAMP '" + rawValue + "'";
       case TIME:
-        return "TIME '" + rawValue + "'";
+        // Same CALL embedding constraint as days(); see class Javadoc.
+        return type.name() + " \"" + rawValue + "\"";
       default:
         return "\"" + escapeStringLiteral(rawValue) + "\"";
     }
   }
 
+  /**
+   * Converts a day-partition stored value to {@code yyyy-MM-dd}.
+   *
+   * <p>Update-stats persists Spark {@code date} partition fields via {@code 
String.valueOf}, which
+   * yields ISO dates (for example {@code 2026-01-01}). Iceberg metadata may 
also expose the raw
+   * epoch-day integer. Accept both; reject anything else with a clear error.
+   */
+  private static String toIsoDateFromDayPartitionValue(String rawValue) {
+    try {
+      return LocalDate.parse(rawValue, DateTimeFormatter.ISO_LOCAL_DATE)
+          .format(DateTimeFormatter.ISO_LOCAL_DATE);
+    } catch (DateTimeParseException ignored) {
+      // fall through to epoch-day
+    }
+    try {
+      // Mirrors Iceberg DateTimeUtil.daysToIsoDate without depending on 
iceberg-api.
+      return LocalDate.ofEpochDay(Integer.parseInt(rawValue))

Review Comment:
   A pure-digit value is always read as epoch-day, so a compact date like 
20260101 would silently become a date around year 57000. Consider bounding the 
accepted range or documenting that only ISO dates and epoch-day integers are 
supported.



-- 
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