lasdf1234 commented on code in PR #14883:
URL: https://github.com/apache/gravitino/pull/14883#discussion_r4537653398
##########
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:
Thanks — fixed.
For nested paths such as `event.ts`, we now walk the top-level struct and
resolve the leaf field type before `formatLiteral`, so nested identity emits
typed literals (e.g. `event.ts = TIMESTAMP "..."` / `event.id = 7`) instead of
quoting via the STRUCT default. Missing nested fields fail with a clear
`IllegalArgumentException`.
Covered by UT (nested timestamp/int + not-found) and Spark CALL IT for
nested identity timestamp/int.
##########
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:
Thanks — fixed.
`DATE` / `TIMESTAMP` / `TIME` typed literals (including the `days()` `DATE
"..."` path) now go through the existing `escapeStringLiteral`, same as plain
strings, so embedded `"` / `\` cannot break `CALL ... where => '...'`.
Added a UT that asserts escaping for a timestamp value containing
quote/backslash characters.
##########
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:
Thanks — documented (no behavior change).
Day partition strings are converted the same way as Iceberg `DateTimeUtil`:
ISO `yyyy-MM-dd` (`isoDateToDays`) or epoch-day integers
(`daysToIsoDate(int)`). Both appear because callers store values as
strings—update-stats uses `String.valueOf(Spark date)` (ISO), while metadata
may expose the raw epoch-day int.
We intentionally did not add a custom epoch-day range bound: Iceberg
`daysToIsoDate(int)` does not either. Compact forms like `20260101` are not ISO
dates; if all digits they are parsed as epoch-day (same as calling
`daysToIsoDate(20260101)`), not as a calendar compact date. This is spelled out
on `toIsoDateFromDayPartitionValue`.
--
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]