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


##########
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:
   [P2] When gravitino.schema.separator is configured as `|`, collecting 
statistics for Spark table `a.b.events` reconstructs Gravitino schema `a:b` 
here instead of `a|b`. Both statistics jobs pass that identifier to the 
updater, which then loads the wrong Gravitino table. Please carry the 
configured separator (or the original Gravitino identifier) into the job 
instead of always using DEFAULT_SCHEMA_SEPARATOR, and add a regression 
asserting the updater receives `NameIdentifier.of("catalog", "a|b", "events")`.



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