freesinger commented on code in PR #11113:
URL: https://github.com/apache/gravitino/pull/11113#discussion_r3577827959


##########
lance/lance-common/src/main/java/org/apache/gravitino/lance/common/ops/gravitino/GravitinoLanceNamespaceWrapper.java:
##########
@@ -135,4 +169,400 @@ public Catalog loadAndValidateLakehouseCatalog(String 
catalogName) {
     }
     return catalog;
   }
+
+  String[] listSchemas(Catalog catalog) throws NoSuchCatalogException {
+    SchemaDispatcher schemaDispatcher = currentSchemaDispatcher();
+    if (schemaDispatcher != null) {
+      return 
Arrays.stream(schemaDispatcher.listSchemas(Namespace.of(metalakeName, 
catalog.name())))
+          .map(NameIdentifier::name)
+          .toArray(String[]::new);
+    }
+
+    if (catalog instanceof BaseCatalog) {
+      CatalogOperations ops = ((BaseCatalog<?>) catalog).ops();
+      if (ops instanceof SupportsSchemas) {
+        return Arrays.stream(((SupportsSchemas) 
ops).listSchemas(Namespace.of()))
+            .map(NameIdentifier::name)
+            .toArray(String[]::new);
+      }
+    }
+
+    return catalog.asSchemas().listSchemas();
+  }
+
+  boolean schemaExists(Catalog catalog, String schemaName) {
+    SchemaDispatcher schemaDispatcher = currentSchemaDispatcher();
+    if (schemaDispatcher != null) {
+      return schemaDispatcher.schemaExists(schemaIdent(catalog.name(), 
schemaName));
+    }
+
+    if (catalog instanceof BaseCatalog) {
+      CatalogOperations ops = ((BaseCatalog<?>) catalog).ops();
+      if (ops instanceof SupportsSchemas) {
+        return ((SupportsSchemas) 
ops).schemaExists(NameIdentifier.of(schemaName));
+      }
+    }
+
+    return catalog.asSchemas().schemaExists(schemaName);
+  }
+
+  Schema loadSchema(Catalog catalog, String schemaName) {
+    SchemaDispatcher schemaDispatcher = currentSchemaDispatcher();
+    if (schemaDispatcher != null) {
+      return schemaDispatcher.loadSchema(schemaIdent(catalog.name(), 
schemaName));
+    }
+
+    if (catalog instanceof BaseCatalog) {
+      CatalogOperations ops = ((BaseCatalog<?>) catalog).ops();
+      if (ops instanceof SupportsSchemas) {
+        return ((SupportsSchemas) 
ops).loadSchema(NameIdentifier.of(schemaName));
+      }
+    }
+
+    return catalog.asSchemas().loadSchema(schemaName);
+  }
+
+  Schema createSchema(
+      Catalog catalog, String schemaName, String comment, Map<String, String> 
properties) {
+    SchemaDispatcher schemaDispatcher = currentSchemaDispatcher();
+    if (schemaDispatcher != null) {
+      return schemaDispatcher.createSchema(
+          schemaIdent(catalog.name(), schemaName), comment, properties);
+    }
+
+    if (catalog instanceof BaseCatalog) {
+      CatalogOperations ops = ((BaseCatalog<?>) catalog).ops();
+      if (ops instanceof SupportsSchemas) {
+        return ((SupportsSchemas) ops)
+            .createSchema(NameIdentifier.of(schemaName), comment, properties);
+      }
+    }
+
+    return catalog.asSchemas().createSchema(schemaName, comment, properties);
+  }
+
+  Schema alterSchema(Catalog catalog, String schemaName, SchemaChange... 
changes) {
+    SchemaDispatcher schemaDispatcher = currentSchemaDispatcher();
+    if (schemaDispatcher != null) {
+      return schemaDispatcher.alterSchema(schemaIdent(catalog.name(), 
schemaName), changes);
+    }
+
+    if (catalog instanceof BaseCatalog) {
+      CatalogOperations ops = ((BaseCatalog<?>) catalog).ops();
+      if (ops instanceof SupportsSchemas) {
+        return ((SupportsSchemas) 
ops).alterSchema(NameIdentifier.of(schemaName), changes);
+      }
+    }
+
+    return catalog.asSchemas().alterSchema(schemaName, changes);
+  }
+
+  boolean dropSchema(Catalog catalog, String schemaName, boolean cascade) {
+    SchemaDispatcher schemaDispatcher = currentSchemaDispatcher();
+    if (schemaDispatcher != null) {
+      return schemaDispatcher.dropSchema(schemaIdent(catalog.name(), 
schemaName), cascade);
+    }
+
+    if (catalog instanceof BaseCatalog) {
+      CatalogOperations ops = ((BaseCatalog<?>) catalog).ops();
+      if (ops instanceof SupportsSchemas) {
+        return ((SupportsSchemas) 
ops).dropSchema(NameIdentifier.of(schemaName), cascade);
+      }
+    }
+
+    return catalog.asSchemas().dropSchema(schemaName, cascade);
+  }
+
+  TableCatalog asTableCatalog(Catalog catalog) {
+    TableDispatcher tableDispatcher = currentTableDispatcher();
+    if (tableDispatcher != null) {
+      return new InternalTableCatalogAdapter(catalog.name(), tableDispatcher);
+    }
+
+    if (catalog instanceof BaseCatalog) {
+      CatalogOperations ops = ((BaseCatalog<?>) catalog).ops();
+      if (ops instanceof TableCatalog) {
+        return (TableCatalog) ops;
+      }
+    }
+
+    return catalog.asTableCatalog();
+  }
+
+  private NameIdentifier schemaIdent(String catalogName, String schemaName) {
+    return NameIdentifierUtil.ofSchema(metalakeName, catalogName, schemaName);
+  }
+
+  private NameIdentifier tableIdent(String catalogName, NameIdentifier ident) {
+    return NameIdentifierUtil.ofTable(
+        metalakeName, catalogName, ident.namespace().level(0), ident.name());
+  }
+
+  private Namespace tableNamespace(String catalogName, Namespace namespace) {
+    return Namespace.of(metalakeName, catalogName, namespace.level(0));
+  }
+
+  private SchemaDispatcher currentSchemaDispatcher() {
+    if (!config().isAuxMode()) {
+      return null;
+    }
+
+    return GravitinoEnv.getInstance().schemaDispatcher();
+  }
+
+  private TableDispatcher currentTableDispatcher() {
+    if (!config().isAuxMode()) {
+      return null;
+    }
+
+    return GravitinoEnv.getInstance().tableDispatcher();
+  }
+
+  @VisibleForTesting
+  CatalogOperator createCatalogOperator(String metalakeName) {
+    return config().isAuxMode()
+        ? new InternalCatalogOperator(metalakeName)
+        : new HttpCatalogOperator(
+            config().get(NAMESPACE_BACKEND_URI), metalakeName, config(), 
extractClientProperties());
+  }
+
+  @VisibleForTesting
+  void setCatalogOperator(CatalogOperator catalogOperator) {
+    this.catalogOperator = catalogOperator;
+  }
+
+  private Map<String, String> extractClientProperties() {
+    Map<String, String> clientProperties = new HashMap<>();
+    config()
+        .getAllConfig()
+        .forEach(
+            (key, value) -> {
+              if (key.startsWith("gravitino.client.")) {
+                clientProperties.put(key, value);
+                LOG.info("Applying client config: {} = {}", key, value);
+              }
+            });
+    return clientProperties;
+  }

Review Comment:
   Changed to log only the key at DEBUG level to avoid leaking sensitive 
gravitino.client.* values. Done.



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