lasdf1234 commented on code in PR #14883:
URL: https://github.com/apache/gravitino/pull/14883#discussion_r4596333324
##########
maintenance/optimizer/src/main/java/org/apache/gravitino/maintenance/optimizer/recommender/job/PartitionUtils.java:
##########
@@ -81,93 +128,260 @@ public static String getWhereClauseForPartition(
PartitionEntry entry = partition.get(i);
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);
+ // Keep transform field-name components (do not join/split on '.') so
names like user-id
+ // stay one component through schema lookup and SQL rendering.
+ String[] fieldName = getFieldName(transform);
+ Preconditions.checkArgument(
+ fieldName != null && fieldName.length > 0, "transform field name
cannot be empty");
+ Column column = columnMap.get(fieldName[0].toLowerCase(Locale.ROOT));
Review Comment:
Thanks — fixed in 800ebe3868.
**Root cause:** `FromIcebergPartitionSpec` / `FromIcebergSortOrder` passed
Iceberg `schema.idToName()` values (e.g. `event.user-id`) into the
`Transforms.*(String)` / `NamedReference.field(String)` overloads, which treat
the whole dotted string as **one** field component `["event.user-id"]`.
`PartitionUtils` then looked up a top-level column of that name and failed with
`Column 'event.user-id' not found`.
**Fix:**
- Added `ConvertUtil.splitIcebergNameToFieldPath` to split `idToName` on `.`
into real components (`["event", "user-id"]`).
- `FromIcebergPartitionSpec` now uses the `String[]` / `String[][]`
overloads for identity / day / year / month / hour / truncate / bucket.
- Same split applied in `FromIcebergSortOrder`.
**Regression (production path Jerry asked for):**
`TestPartitionUtilsFromIcebergPartitionSpec` builds an Iceberg
`PartitionSpec` on nested hyphenated `event.user-id`, converts via
`FromIcebergPartitionSpec`, then feeds the converted transform into
`PartitionUtils` — so it no longer bypasses catalog conversion the way the
hand-built Spark tests did.
Also covered nested hyphenated identity/day in
`TestFromIcebergPartitionSpec` and nested sort fields in
`TestFromIcebergSortOrder`.
##########
maintenance/optimizer/src/test/java/org/apache/gravitino/maintenance/optimizer/recommender/job/TestGravitinoCompactionJobAdapter.java:
##########
@@ -56,6 +62,143 @@ public void testSortStrategyAndSortOrder() {
jobAdapter.jobConfig(mockCompactionJobContext("sort",
"zorder(c1,c2)")));
}
+ @Test
+ public void testWhereClauseForDayPartitionUsesIsoDateFromStatsPath() {
+ // Mirrors CLI submit-strategy-jobs: update-stats stores day as ISO date,
adapter builds where.
+ Column[] columns =
+ new Column[] {
+ ColumnDTO.builder()
+ .withName("ts")
+ .withDataType(Types.TimestampType.withoutTimeZone())
+ .build()
+ };
+ Transform[] partitioning = new Transform[] {Transforms.day("ts")};
+ List<PartitionPath> partitions =
+ List.of(PartitionPath.of(List.of(new PartitionEntryImpl("ts_day",
"2026-01-01"))));
+
+ Map<String, String> conf =
+ new GravitinoCompactionJobAdapter()
+ .jobConfig(
+ new CompactionJobContext(
+ NameIdentifier.of("catalog", "db", "table"),
+ Map.of("target_file_size_bytes", "1073741824"),
+ "compaction-job-template",
+ "binpack",
+ "",
+ columns,
+ partitioning,
+ partitions));
+
+ Assertions.assertEquals(
+ "(`catalog`.system.days(`ts`) = DATE '2026-01-01')",
conf.get("where_clause"));
+ }
+
+ @Test
+ public void testWhereClauseUsesSubmitterSparkCatalogWhenNamesDiffer() {
+ // Gravitino table catalog "lake" vs Spark CALL catalog_name "ice" from
jobSubmitterConfig.
+ Column[] columns =
+ new Column[] {
+ ColumnDTO.builder()
+ .withName("ts")
+ .withDataType(Types.TimestampType.withoutTimeZone())
+ .build()
+ };
+ Transform[] partitioning = new Transform[] {Transforms.day("ts")};
+ List<PartitionPath> partitions =
+ List.of(PartitionPath.of(List.of(new PartitionEntryImpl("ts_day",
"2026-01-01"))));
+ CompactionJobContext context =
+ new CompactionJobContext(
+ NameIdentifier.of("lake", "db", "events"),
+ Map.of("target_file_size_bytes", "1073741824"),
+ "compaction-job-template",
+ "binpack",
+ "",
+ columns,
+ partitioning,
+ partitions);
+ OptimizerConfig config =
+ new OptimizerConfig(
+ Map.of(OptimizerConfig.JOB_SUBMITTER_CONFIG_PREFIX +
"catalog_name", "ice"));
+
+ Map<String, String> conf =
+ GravitinoJobSubmitter.buildJobConfig(config, context, new
GravitinoCompactionJobAdapter());
+
+ Assertions.assertEquals("ice", conf.get("catalog_name"));
+ Assertions.assertEquals(
+ "(`ice`.system.days(`ts`) = DATE '2026-01-01')",
conf.get("where_clause"));
+ }
+
+ @Test
+ public void testHierarchicalSchemaTableIdentifierAndQuotedFieldWhere() {
+ // Gravitino hierarchical schema is one schema segment joined by ':'
(default separator),
+ // e.g. a:b:c — not catalog.a.b.c levels. table_identifier keeps that
logical schema name.
+ Column[] columns =
+ new Column[] {
+ ColumnDTO.builder()
+ .withName("event")
+ .withDataType(
+ Types.StructType.of(
+ Types.StructType.Field.notNullField("user-id",
Types.IntegerType.get())))
+ .build()
+ };
+ Transform[] partitioning =
+ new Transform[] {Transforms.identity(new String[] {"event",
"user-id"})};
+ List<PartitionPath> partitions =
+ List.of(PartitionPath.of(List.of(new
PartitionEntryImpl("event.user-id", "7"))));
+
+ Map<String, String> conf =
+ new GravitinoCompactionJobAdapter()
+ .jobConfig(
+ new CompactionJobContext(
+ NameIdentifier.of("catalog", "a:b:c", "events"),
+ Map.of("target_file_size_bytes", "1073741824"),
+ "compaction-job-template",
+ "binpack",
+ "",
+ columns,
+ partitioning,
+ partitions));
+
+ Assertions.assertEquals("a:b:c.events", conf.get("table_identifier"));
Review Comment:
Thanks for the catch.
For this PR we are **not** wiring hierarchical schema (`a:b:c`) → Spark
physical namespace translation into the adapters / CALL path. That
strategy-submission concern is outside the scope of the partition `where`
quoting / conversion fixes here; we will open a follow-up issue to track
translating the adapter-produced identifier for Spark (including feeding it
through a real CALL regression).
**What we did instead (narrow as you suggested):**
- Removed the hierarchical / multi-level-namespace tests that mixed
`table_identifier` / dotted Spark namespaces with field-quoting coverage
(`TestGravitinoCompactionJobAdapter.testHierarchicalSchemaTableIdentifierAndQuotedFieldWhere`,
`TestIcebergRewriteDataFilesJobWithSpark.testPartitionUtilsWhereInNestedNamespaceThroughSparkCall`).
- Kept this change focused on nested field-path quoting and the
`FromIcebergPartitionSpec` → `PartitionUtils` conversion fix from the P1 thread.
--
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]