jerryshao commented on code in PR #14883:
URL: https://github.com/apache/gravitino/pull/14883#discussion_r4595120275
##########
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:
[P2] For a Gravitino schema `a:b:c`, this test expects `a:b:c.events`, while
the Spark regression supplies a dotted namespace directly. The production CALL
forwards the adapter value unchanged, so these tests bypass the step that
determines whether Spark can find the table. Please feed the adapter-produced
identifier into the Spark regression and translate the logical namespace to its
physical components, or narrow the tests to field quoting if hierarchical
strategy submission is outside this change.
##########
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:
[P1] Loading an Iceberg table partitioned by `event.user-id` produces a
transform with `["event.user-id"]` because `FromIcebergPartitionSpec` passes
`schema.idToName()` values to the String overloads. This lookup then throws
`Column 'event.user-id' not found in table schema`. Please preserve the actual
field components during catalog conversion or normalize the catalog
representation before lookup. A regression that starts with an Iceberg
`PartitionSpec` and passes its converted transform into `PartitionUtils` would
exercise the path the current Spark tests bypass.
--
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]