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


##########
maintenance/jobs/src/main/java/org/apache/gravitino/maintenance/jobs/iceberg/IcebergJobUtils.java:
##########
@@ -232,6 +234,104 @@ public static String escapeSqlIdentifier(String 
identifier) {
     return "`" + escaped + "`";
   }
 
+  /**
+   * Builds a backtick-quoted {@code catalog.ns…table} SQL reference from a 
Spark table identifier
+   * that may include hierarchical Iceberg namespace levels (e.g. {@code 
a.b.c.events}).
+   *
+   * @param catalogName Spark catalog name
+   * @param sparkTableIdentifier dotted schema…table identifier
+   * @return qualified SQL identifier
+   */
+  public static String qualifyCatalogTableSql(String catalogName, String 
sparkTableIdentifier) {
+    Preconditions.checkArgument(
+        StringUtils.isNotBlank(catalogName), "catalogName must not be blank");
+    StringBuilder sql = new 
StringBuilder(escapeSqlIdentifier(catalogName.trim()));
+    for (String level : 
IdentifierUtils.sparkTableIdentifierLevels(sparkTableIdentifier)) {
+      sql.append('.').append(escapeSqlIdentifier(level));
+    }
+    return sql.toString();
+  }
+
+  /**
+   * Qualifies an Iceberg metadata table such as {@code files} or {@code 
all_files}.
+   *
+   * @param catalogName Spark catalog name
+   * @param sparkTableIdentifier dotted schema…table identifier
+   * @param metadataTable metadata table name (for example {@code files})
+   * @return qualified SQL identifier including the metadata table
+   */
+  public static String qualifyCatalogMetadataTableSql(
+      String catalogName, String sparkTableIdentifier, String metadataTable) {
+    Preconditions.checkArgument(
+        StringUtils.isNotBlank(metadataTable), "metadataTable must not be 
blank");
+    return qualifyCatalogTableSql(catalogName, sparkTableIdentifier)
+        + "."
+        + escapeSqlIdentifier(metadataTable.trim());
+  }
+
+  /**
+   * Converts a Spark table identifier back to Gravitino {@code 
catalog.schema.table}, joining
+   * multi-level namespaces with the default external schema separator.
+   *
+   * @param catalogName catalog name
+   * @param sparkTableIdentifier Spark table id
+   * @return Gravitino catalog.schema.table identifier
+   */
+  public static NameIdentifier toGravitinoTableIdentifier(
+      String catalogName, String sparkTableIdentifier) {
+    return IdentifierUtils.fromSparkTableIdentifier(
+        catalogName, sparkTableIdentifier, 
IdentifierUtils.DEFAULT_SCHEMA_SEPARATOR);

Review Comment:
   Thanks for catching this.
   
   **Fix:** both stats jobs (`IcebergUpdateStatsAndMetricsJob` / 
`IcebergUpdateManifestStatsJob`) no longer use `DEFAULT_SCHEMA_SEPARATOR` (`:`) 
when reconstructing the Gravitino id. They load the live 
`gravitino.schema.separator` from the unauthenticated `GET /configs` endpoint 
via `GravitinoClientUtils.fetchSchemaSeparator(gravitino_uri)`, then call 
`IdentifierUtils.fromSparkTableIdentifier(..., schemaSeparator)`.
   
   So with separator `|`, Spark `a.b.events` becomes 
`NameIdentifier.of(catalog, "a|b", "events")` as you asked — not `a:b`.
   
   We intentionally did **not** add a new jobConf arg for the separator; the 
job already has `gravitino_uri` in `updater_options`, and `/configs` already 
exposes `gravitino.schema.separator` publicly.
   
   **Regression:** Spark e2e tests mock `/configs` returning `|`, then assert 
the updater receives `NameIdentifier.of(..., "a|b", "events")` for both 
update-stats and update-manifest-stats.
   
   Related follow-ups on the same path (forward mapping + CLI):
   - The four strategy job adapters / `GravitinoJobSubmitter` also take the 
separator from `/configs` (no silent `:` fallback when Env is missing).
   - `submit-update-stats-job` documents that dry-run still needs a reachable 
`gravitino_uri` for `/configs`, and accepts hierarchical identifiers in 
Gravitino form (`catalog.a|b.t`) or Spark-physical form (`catalog.a.b.t`).
   
   Pushed in `b696344fdf`.



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