anilkumgopalap commented on code in PR #14862:
URL: https://github.com/apache/gravitino/pull/14862#discussion_r4603277741


##########
catalogs/catalog-lakehouse-generic/src/main/java/org/apache/gravitino/catalog/lakehouse/generic/GenericCatalogOperations.java:
##########
@@ -169,10 +172,56 @@ public NameIdentifier[] listSchemas(Namespace namespace) 
throws NoSuchCatalogExc
     return schemaOps.listSchemas(namespace);
   }
 
+  /**
+   * Creates a schema, asking the {@link TableLocationProvider} for its 
location first when the
+   * provider implements {@link SupportsSchemaLocations}.
+   *
+   * <p>A schema that already exists is rejected before the provider is 
consulted, so that a
+   * provider is never asked to allocate for a name that is taken. A provider 
that throws fails the
+   * creation, and a non-null location it returns is stored as the schema's 
{@code location}.
+   *
+   * @param ident the identifier of the schema to create
+   * @param comment the comment of the schema
+   * @param properties the properties of the schema
+   * @return the created schema
+   * @throws NoSuchCatalogException if the catalog does not exist
+   * @throws SchemaAlreadyExistsException if the schema already exists
+   */
   @Override
   public Schema createSchema(NameIdentifier ident, String comment, Map<String, 
String> properties)
       throws NoSuchCatalogException, SchemaAlreadyExistsException {
-    return schemaOps.createSchema(ident, comment, properties);
+    TableLocationProvider provider = tableLocationProvider;
+    if (!(provider instanceof SupportsSchemaLocations)) {
+      return schemaOps.createSchema(ident, comment, properties);
+    }
+
+    try {
+      if (store.exists(ident, SCHEMA)) {
+        throw new SchemaAlreadyExistsException("Schema %s already exists", 
ident);
+      }
+    } catch (IOException e) {
+      throw new RuntimeException("Failed to check if schema " + ident + " 
exists", e);
+    }
+
+    String location =
+        ((SupportsSchemaLocations) provider)
+            .provisionSchemaLocation(
+                SchemaLocationContext.builder()
+                    .withSchemaIdentifier(ident)
+                    .withSchemaProperties(properties)
+                    .withCatalogProperties(catalogProperties)
+                    .build());
+    Map<String, String> schemaProperties = properties;
+    if (location != null) {

Review Comment:
   Done. Null or blank both leave the request's properties unchanged now, and 
the precondition is gone.



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