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


##########
maintenance/optimizer/src/main/java/org/apache/gravitino/maintenance/optimizer/recommender/job/PartitionUtils.java:
##########
@@ -110,25 +114,35 @@ private static String getColumnName(Transform transform) {
     throw new IllegalArgumentException("Unsupported transform: " + 
transform.getClass().getName());
   }
 
+  /**
+   * Builds the left-hand side of a partition predicate using Iceberg Spark 
system functions.
+   *
+   * <p>Temporal transforms use plural names ({@code years}/{@code 
months}/{@code days}/{@code
+   * hours}) matching {@code 
org.apache.iceberg.spark.functions.SparkFunctions}. {@code bucket} and
+   * {@code truncate} put the width argument first, matching Iceberg's Spark 
UDF signatures.
+   */
   private static String buildExpression(Transform transform, String 
columnName) {
     if (transform instanceof Transforms.IdentityTransform) {
       return columnName;
-    } else if (transform instanceof Transforms.YearTransform
-        || transform instanceof Transforms.MonthTransform
-        || transform instanceof Transforms.DayTransform
-        || transform instanceof Transforms.HourTransform) {
-      return transform.name() + "(" + columnName + ")";
+    } else if (transform instanceof Transforms.YearTransform) {
+      return "years(" + columnName + ")";
+    } else if (transform instanceof Transforms.MonthTransform) {
+      return "months(" + columnName + ")";
+    } else if (transform instanceof Transforms.DayTransform) {
+      return "days(" + columnName + ")";
+    } else if (transform instanceof Transforms.HourTransform) {
+      return "hours(" + columnName + ")";

Review Comment:
   hours() compares to a bare int while days() compares to a DATE literal; is 
hours() in Iceberg Spark really IntegerType, and are years()/months() as well? 
Please confirm with an integration test, since only string comparisons are 
covered now.



##########
maintenance/optimizer/src/main/java/org/apache/gravitino/maintenance/optimizer/recommender/job/PartitionUtils.java:
##########
@@ -137,12 +151,21 @@ private static String buildExpression(Transform 
transform, String columnName) {
   private static String formatLiteral(Transform transform, Column column, 
String rawValue) {
     if (transform instanceof Transforms.YearTransform
         || transform instanceof Transforms.MonthTransform
-        || transform instanceof Transforms.DayTransform
         || transform instanceof Transforms.HourTransform
         || transform instanceof Transforms.BucketTransform) {
       return rawValue;
     }
 
+    // Iceberg Spark days() returns DATE; CALL where => '...' also eats 
single-quoted DATE
+    // literals (escapeSqlString doubling still parses as unquoted). Use 
double-quoted DATE.
+    // Epoch-day -> ISO date mirrors Iceberg DateTimeUtil.daysToIsoDate 
without depending on
+    // iceberg-api (ofEpochDay + ISO_LOCAL_DATE == 
dateFromDays(...).format(ISO_LOCAL_DATE)).
+    if (transform instanceof Transforms.DayTransform) {
+      String isoDate =
+          
LocalDate.ofEpochDay(Integer.parseInt(rawValue)).format(DateTimeFormatter.ISO_LOCAL_DATE);

Review Comment:
   Integer.parseInt on the raw day partition value throws NumberFormatException 
if the value is already an ISO date string or has any other format. Handle both 
an epoch-day integer and an ISO date, or fail with a clear 
IllegalArgumentException, and add a test for the non-integer case.



##########
maintenance/optimizer/src/main/java/org/apache/gravitino/maintenance/optimizer/recommender/job/PartitionUtils.java:
##########
@@ -156,11 +179,12 @@ private static String formatLiteral(Transform transform, 
Column column, String r
       case DECIMAL:
         return rawValue;
       case DATE:
-        return "DATE '" + rawValue + "'";
+        // Double quotes: CALL where => '...' eats single-quoted typed 
literals.
+        return "DATE \"" + rawValue + "\"";
       case TIMESTAMP:
-        return "TIMESTAMP '" + rawValue + "'";
+        return "TIMESTAMP \"" + rawValue + "\"";

Review Comment:
   Typed literals now rely on double quotes (TIMESTAMP "...") being parsed as 
strings by Spark, which breaks if spark.sql.ansi.doubleQuotedIdentifiers is 
enabled. Please verify against a real Spark/Iceberg CALL rewrite_data_files, or 
escape any quote characters in rawValue.



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