Copilot commented on code in PR #10560:
URL: https://github.com/apache/gravitino/pull/10560#discussion_r3007975841


##########
flink-connector/flink/src/main/java/org/apache/gravitino/flink/connector/utils/FactoryUtils.java:
##########
@@ -36,6 +41,20 @@ private FactoryUtils() {}
 
   private static final Logger LOG = 
LoggerFactory.getLogger(FactoryUtils.class);
 
+  /** The list of Gravitino catalog factory identifiers. */
+  public static final ImmutableList<String> GRAVITINO_FACTORY_LIST =
+      ImmutableList.<String>builder()
+          .add(GravitinoHiveCatalogFactoryOptions.IDENTIFIER)
+          .add(GravitinoIcebergCatalogFactoryOptions.IDENTIFIER)
+          .add(GravitinoJdbcCatalogFactoryOptions.MYSQL_IDENTIFIER)
+          .add(GravitinoJdbcCatalogFactoryOptions.POSTGRESQL_IDENTIFIER)
+          .add(GravitinoPaimonCatalogFactoryOptions.IDENTIFIER)
+          .build();
+
+  public static boolean isBuiltInCatalog(String type) {
+    return GRAVITINO_FACTORY_LIST.contains(type);
+  }
+
   /**

Review Comment:
   `isBuiltInCatalog` is misleading here: it currently returns true when the 
type matches Gravitino catalog factory identifiers (e.g., `gravitino-jdbc-*`), 
not Flink built-in/third-party identifiers. Renaming this method (e.g., 
`isGravitinoCatalogType` / `isGravitinoManagedCatalogType`) would prevent 
future callers from inverting the storage logic by mistake.
   ```suggestion
     /**
      * Returns {@code true} if the given catalog {@code type} is one of the 
Gravitino-managed
      * catalog factory identifiers.
      *
      * @param type the catalog type identifier to check
      * @return {@code true} if the type matches a Gravitino catalog factory 
identifier, {@code false}
      *     otherwise
      */
     public static boolean isGravitinoCatalogType(String type) {
       return GRAVITINO_FACTORY_LIST.contains(type);
     }
   
     /**
      * @deprecated Use {@link #isGravitinoCatalogType(String)} instead.
      */
     @Deprecated
     public static boolean isBuiltInCatalog(String type) {
       return isGravitinoCatalogType(type);
     }
   
     /**
   ```



##########
flink-connector/flink/src/main/java/org/apache/gravitino/flink/connector/store/GravitinoSessionCatalogStore.java:
##########
@@ -0,0 +1,120 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.gravitino.flink.connector.store;
+
+import static 
org.apache.gravitino.flink.connector.utils.FactoryUtils.isBuiltInCatalog;
+
+import java.util.HashSet;
+import java.util.Optional;
+import java.util.Set;
+import org.apache.flink.table.catalog.AbstractCatalogStore;
+import org.apache.flink.table.catalog.CatalogDescriptor;
+import org.apache.flink.table.catalog.CommonCatalogOptions;
+import org.apache.flink.table.catalog.GenericInMemoryCatalogStore;
+import org.apache.flink.table.catalog.exceptions.CatalogException;
+import org.apache.flink.util.Preconditions;
+
+/**
+ * A catalog store that combines a session-scoped in-memory
+ * {@link GenericInMemoryCatalogStore} with a persistent {@link 
GravitinoCatalogStore}.
+ *
+ * <p>Catalogs for built-in catalog types are stored only in the in-memory 
store, while all
+ * other catalogs are stored in the Gravitino-backed store. When retrieving, 
listing, or
+ * removing catalogs, entries in the in-memory store take precedence over 
entries in the
+ * Gravitino-backed store.

Review Comment:
   The class JavaDoc contradicts the implementation and the PR behavior 
description: `storeCatalog` persists Gravitino-managed types to the 
Gravitino-backed store and puts other (third-party) catalogs into the in-memory 
store, but this JavaDoc says the opposite. Please update the JavaDoc so it 
matches the actual routing and precedence rules.
   ```suggestion
    * <p>Catalogs for Gravitino-managed (built-in) catalog types are stored in 
the
    * Gravitino-backed store, while all other (third-party) catalogs are stored 
only in the
    * in-memory store. When retrieving, listing, or removing catalogs, entries 
in the in-memory
    * store take precedence over entries in the Gravitino-backed store.
   ```



##########
flink-connector/flink/src/main/java/org/apache/gravitino/flink/connector/store/GravitinoSessionCatalogStore.java:
##########
@@ -0,0 +1,120 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.gravitino.flink.connector.store;
+
+import static 
org.apache.gravitino.flink.connector.utils.FactoryUtils.isBuiltInCatalog;
+
+import java.util.HashSet;
+import java.util.Optional;
+import java.util.Set;
+import org.apache.flink.table.catalog.AbstractCatalogStore;
+import org.apache.flink.table.catalog.CatalogDescriptor;
+import org.apache.flink.table.catalog.CommonCatalogOptions;
+import org.apache.flink.table.catalog.GenericInMemoryCatalogStore;
+import org.apache.flink.table.catalog.exceptions.CatalogException;
+import org.apache.flink.util.Preconditions;
+
+/**
+ * A catalog store that combines a session-scoped in-memory
+ * {@link GenericInMemoryCatalogStore} with a persistent {@link 
GravitinoCatalogStore}.
+ *
+ * <p>Catalogs for built-in catalog types are stored only in the in-memory 
store, while all
+ * other catalogs are stored in the Gravitino-backed store. When retrieving, 
listing, or
+ * removing catalogs, entries in the in-memory store take precedence over 
entries in the
+ * Gravitino-backed store.
+ *
+ * <p>This store is intended to be used per Flink session, keeping transient 
catalogs in
+ * memory while delegating persistent catalogs to Apache Gravitino.
+ */
+public class GravitinoSessionCatalogStore extends AbstractCatalogStore {
+  private final GenericInMemoryCatalogStore memoryCatalogStore;
+  private final GravitinoCatalogStore gravitinoCatalogStore;
+
+  public GravitinoSessionCatalogStore(
+      GravitinoCatalogStore gravitinoCatalogStore, GenericInMemoryCatalogStore 
memoryCatalogStore) {
+    this.gravitinoCatalogStore =
+        Preconditions.checkNotNull(gravitinoCatalogStore, "CatalogStore cannot 
be null");
+    this.memoryCatalogStore =
+        Preconditions.checkNotNull(memoryCatalogStore, "MemoryCatalogStore 
cannot be null");
+  }
+
+  @Override
+  public void storeCatalog(String catalogName, CatalogDescriptor descriptor)
+      throws CatalogException {
+    String catalogType = 
descriptor.getConfiguration().get(CommonCatalogOptions.CATALOG_TYPE);
+    if (!isBuiltInCatalog(catalogType)) {

Review Comment:
   This PR adds new routing behavior between an in-memory catalog store and the 
Gravitino-backed store, but the repo currently has no 
`TestGravitinoSessionCatalogStore` (and no other tests covering this new 
class/behavior). Please add unit tests that verify at least: (1) CREATE routes 
Gravitino catalog types to `GravitinoCatalogStore` and others to 
`GenericInMemoryCatalogStore`, (2) get/remove precedence prefers memory, and 
(3) listCatalogs returns the union.



##########
flink-connector/flink/src/main/java/org/apache/gravitino/flink/connector/utils/FactoryUtils.java:
##########
@@ -36,6 +41,20 @@ private FactoryUtils() {}
 
   private static final Logger LOG = 
LoggerFactory.getLogger(FactoryUtils.class);
 
+  /** The list of Gravitino catalog factory identifiers. */
+  public static final ImmutableList<String> GRAVITINO_FACTORY_LIST =
+      ImmutableList.<String>builder()
+          .add(GravitinoHiveCatalogFactoryOptions.IDENTIFIER)
+          .add(GravitinoIcebergCatalogFactoryOptions.IDENTIFIER)
+          .add(GravitinoJdbcCatalogFactoryOptions.MYSQL_IDENTIFIER)

Review Comment:
   `GRAVITINO_FACTORY_LIST` is used for membership checks (`contains`), but 
it’s declared as an `ImmutableList`, making lookups O(n) and suggesting ordered 
semantics that aren’t needed. Consider using an `ImmutableSet` (or `Set`) and 
renaming the constant to reflect it’s a set of Gravitino-managed catalog type 
identifiers (not a general “factory list”).



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