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


##########
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:
   Thanks — verified.
   
   Double-quoted typed literals (`DATE \"...\"` / `TIMESTAMP \"...\"` / `TIME 
\"...\"`) are intentional: single-quoted forms are eaten inside `CALL ... where 
=> '...'`.
   
   Verified with real Spark/Iceberg `rewrite_data_files` under both 
`spark.sql.ansi.doubleQuotedIdentifiers=false` and `true` (CLI CALL matrix + 
`TestBuiltinIcebergRewriteDataFiles.testPartitionUtilsWhereClausesAgainstIcebergRewriteCall`).
 String values also escape `\` / `"` in the literal.



##########
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:
   Thanks — verified; double-quoted typed literals are intentional here and do 
not break under `spark.sql.ansi.doubleQuotedIdentifiers`.
   
   **Why double quotes (not single quotes)**  
   The compaction job embeds the predicate in `CALL ... rewrite_data_files(..., 
where => '<predicate>')`. With single-quoted typed literals such as `DATE 
'2024-01-01'`, the outer CALL string consumes the inner quotes (even with SQL 
escaping / quote doubling), so Iceberg ends up seeing something like `DATE 
2024-01-01` and fails to parse. Double-quoted forms (`DATE "yyyy-MM-dd"`, 
`TIMESTAMP "..."`, `TIME "..."`, and plain `"string"`) survive that embedding.
   
   **Why `ansi.doubleQuotedIdentifiers=true` does not break this path**  
   Jerry’s concern is valid for ordinary Spark SQL: with that flag, `"x"` is an 
identifier, not a string. For `rewrite_data_files` `where`, Iceberg does not 
evaluate the clause as a free-standing Spark SQL query under the session’s ANSI 
identifier rules in the same way. It parses the predicate via Iceberg’s Spark 
filter path (`SparkV2Filters` / expression conversion) so that system functions 
like `days` / `years` resolve and push down. In that path, the double-quoted 
typed literals we emit are still accepted as date/timestamp/string constants.
   
   **What we verified**  
   Real Spark + Iceberg REST `CALL rewrite_data_files` with the exact 
predicates `PartitionUtils` emits, under both:
   - `spark.sql.ansi.doubleQuotedIdentifiers=false`
   - `spark.sql.ansi.doubleQuotedIdentifiers=true`
   
   Covered for identity string/date/timestamp, `days` (`DATE "..."`), and the 
other transforms. String literals also escape embedded `\` and `"` via 
`escapeStringLiteral`.
   
   So: double quotes are required for CALL embedding correctness, and ansi 
double-quoted-identifiers does not invalidate them on this rewrite `where` path.



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