Skip to content

World's most powerful open data catalog for building a high-performance, geo-distributed and federated metadata lake.

[#14756] improvement(flink-connector): Add excludedCatalogs option (#14905)

geyanggang09e4d92c2812
diff --git a/docs/flink-connector/flink-connector.md b/docs/flink-connector/flink-connector.md
index 1340e2f383..fd229a0179 100644
--- a/docs/flink-connector/flink-connector.md
+++ b/docs/flink-connector/flink-connector.md
@@ -53,6 +53,7 @@ Do not mix runtime JARs from different Flink minor versions in the same Flink de
| table.catalog-store.gravitino.gravitino.metalake | string | (none) | The metalake name that flink connector used to request to Gravitino. | Yes |
| table.catalog-store.gravitino.gravitino.uri | string | (none) | The uri of Gravitino server address. | Yes |
| table.catalog-store.gravitino.gravitino.enableSessionCatalogSupport | boolean | false | Whether to enable support for Flink's session catalog in the Gravitino catalog store. | No |
+| table.catalog-store.gravitino.gravitino.excludedCatalogs | list | (none) | Semicolon-separated catalog names that are never resolved against Gravitino in this session. Only valid when `enableSessionCatalogSupport` is `true`. See [Use a session catalog with the name of a Gravitino catalog](#use-a-session-catalog-with-the-name-of-a-gravitino-catalog). | No |
| table.catalog-store.gravitino.gravitino.client. | string | (none) | The configuration key prefix for the Gravitino client config. | No |
When `table.catalog-store.gravitino.gravitino.enableSessionCatalogSupport` is set to `true`, Gravitino uses `GravitinoSessionCatalogStore`, which combines a `GravitinoCatalogStore` (backed by the Gravitino server) with an in-memory store to support Flink's session catalog. When `false` (the default), only `GravitinoCatalogStore` is used.
@@ -64,7 +65,7 @@ When session catalog support is enabled, the following behaviors apply:
- **DROP CATALOG**: The in-memory store is checked first. If the catalog exists there it is removed from memory; otherwise it is removed from the Gravitino server.
- **SHOW / LIST CATALOGS**: Returns the combined set of catalogs from both the in-memory store and the Gravitino server.
- **Session scope**: Catalogs stored only in memory are session-scoped and will not survive when Flink restarts.
-- **Name conflict**: If a catalog with the same name exists in both stores, the in-memory entry takes precedence.
+- **Name conflict**: `CREATE CATALOG` fails if a catalog with the same name already exists in either store, including a Gravitino catalog created by another client. If a Gravitino catalog with the same name as an existing in-memory catalog is created later, the in-memory entry takes precedence in this session. To create a session catalog with the name of an existing Gravitino catalog, use `excludedCatalogs`.
To configure the Gravitino client, use properties prefixed with `table.catalog-store.gravitino.gravitino.client.`. These properties will be passed to the Gravitino client after removing the `table.catalog-store.gravitino.` prefix.
@@ -114,6 +115,28 @@ INSERT INTO hive_students VALUES (1, 'Alice'), (2, 'Bob');
SELECT * FROM hive_students;
```
+## Use a session catalog with the name of a Gravitino catalog
+
+Existing Flink jobs may create a session catalog, such as a native Paimon catalog, with the same name as a catalog managed by Gravitino. To keep the job's own catalog configuration, add the catalog name to `table.catalog-store.gravitino.gravitino.excludedCatalogs`. Separate multiple names with semicolons.
+
+```yaml
+table.catalog-store.gravitino.gravitino.enableSessionCatalogSupport: true
+table.catalog-store.gravitino.gravitino.excludedCatalogs: paimon_catalog
+```
+
+For each excluded name, the Flink session behaves as follows:
+
+- The Gravitino catalog with that name is not visible: `SHOW CATALOGS`, `USE CATALOG`, and table lookups never resolve it from Gravitino.
+- `CREATE CATALOG` with a non-Gravitino-managed type, such as `paimon` or `hive`, creates a session catalog in memory. Creating a second catalog with the same name still fails.
+- `ALTER CATALOG` and `DROP CATALOG` only affect the session catalog. `DROP CATALOG` never drops the Gravitino catalog.
+- Creating a Gravitino-managed catalog type, such as `gravitino-paimon`, fails, because it would be persisted to Gravitino.
+
+Exclusion only affects the current Flink session. The Gravitino catalog and its metadata are not modified, and other sessions still see it. Names are case-sensitive.
+
+:::caution
+A session catalog uses its own connector configuration and authentication. Gravitino does not authorize access through a session catalog, regardless of whether its name is excluded. Excluding a name does not grant any additional access, but make sure that session catalogs are permitted by your platform's access policy.
+:::
+
## Catalog Naming Restrictions
:::caution
diff --git a/flink-connector/flink-common/src/main/java/org/apache/gravitino/flink/connector/store/GravitinoCatalogStoreFactory.java b/flink-connector/flink-common/src/main/java/org/apache/gravitino/flink/connector/store/GravitinoCatalogStoreFactory.java
index 1cc1f0ab9a..24f34dc98e 100644
--- a/flink-connector/flink-common/src/main/java/org/apache/gravitino/flink/connector/store/GravitinoCatalogStoreFactory.java
+++ b/flink-connector/flink-common/src/main/java/org/apache/gravitino/flink/connector/store/GravitinoCatalogStoreFactory.java
@@ -23,15 +23,18 @@ import static org.apache.flink.table.factories.FactoryUtil.createCatalogStoreFac
import static org.apache.gravitino.flink.connector.store.GravitinoCatalogStoreFactoryOptions.GRAVITINO;
import static org.apache.gravitino.flink.connector.store.GravitinoCatalogStoreFactoryOptions.GRAVITINO_CLIENT_CONFIG;
import static org.apache.gravitino.flink.connector.store.GravitinoCatalogStoreFactoryOptions.GRAVITINO_ENABLE_SESSION_CATALOG_SUPPORT;
+import static org.apache.gravitino.flink.connector.store.GravitinoCatalogStoreFactoryOptions.GRAVITINO_EXCLUDED_CATALOGS;
import static org.apache.gravitino.flink.connector.store.GravitinoCatalogStoreFactoryOptions.GRAVITINO_METALAKE;
import static org.apache.gravitino.flink.connector.store.GravitinoCatalogStoreFactoryOptions.GRAVITINO_URI;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableSet;
+import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
+import org.apache.commons.lang3.StringUtils;
import org.apache.flink.configuration.ConfigOption;
import org.apache.flink.configuration.ReadableConfig;
import org.apache.flink.table.catalog.CatalogStore;
@@ -41,9 +44,13 @@ import org.apache.flink.table.factories.CatalogStoreFactory;
import org.apache.flink.table.factories.FactoryUtil;
import org.apache.gravitino.client.GravitinoClientConfiguration;
import org.apache.gravitino.flink.connector.catalog.GravitinoCatalogManager;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/** The Factory for creating {@link GravitinoCatalogStore}. */
public class GravitinoCatalogStoreFactory implements CatalogStoreFactory {
+ private static final Logger LOG = LoggerFactory.getLogger(GravitinoCatalogStoreFactory.class);
+
private GravitinoCatalogManager catalogManager;
private boolean enableSessionCatalogSupport;
private GravitinoCatalogStore gravitinoCatalogStore;
@@ -71,15 +78,28 @@ public class GravitinoCatalogStoreFactory implements CatalogStoreFactory {
GRAVITINO_URI.key(),
GRAVITINO_METALAKE.key());
+ boolean sessionCatalogSupport = options.get(GRAVITINO_ENABLE_SESSION_CATALOG_SUPPORT);
+ // Validate before creating the Gravitino client so that a misconfiguration does not leave an
+ // unused client behind.
+ Set<String> excludedCatalogs =
+ parseExcludedCatalogs(options.get(GRAVITINO_EXCLUDED_CATALOGS), sessionCatalogSupport);
+
this.catalogManager =
GravitinoCatalogManager.create(gravitinoUri, gravitinoName, extractClientConfig(options));
- this.enableSessionCatalogSupport = options.get(GRAVITINO_ENABLE_SESSION_CATALOG_SUPPORT);
+ this.enableSessionCatalogSupport = sessionCatalogSupport;
this.gravitinoCatalogStore = new GravitinoCatalogStore(catalogManager);
if (enableSessionCatalogSupport) {
this.memoryCatalogStore = new GenericInMemoryCatalogStore();
this.memoryCatalogStore.open();
+ if (!excludedCatalogs.isEmpty()) {
+ LOG.info(
+ "Catalogs {} are excluded from Gravitino in this session; only session catalogs "
+ + "can use these names.",
+ excludedCatalogs);
+ }
this.catalogStore =
- new GravitinoSessionCatalogStore(gravitinoCatalogStore, memoryCatalogStore);
+ new GravitinoSessionCatalogStore(
+ gravitinoCatalogStore, memoryCatalogStore, excludedCatalogs);
} else {
this.catalogStore = gravitinoCatalogStore;
}
@@ -107,7 +127,42 @@ public class GravitinoCatalogStoreFactory implements CatalogStoreFactory {
@Override
public Set<ConfigOption<?>> optionalOptions() {
- return ImmutableSet.of(GRAVITINO_CLIENT_CONFIG, GRAVITINO_ENABLE_SESSION_CATALOG_SUPPORT);
+ return ImmutableSet.of(
+ GRAVITINO_CLIENT_CONFIG,
+ GRAVITINO_ENABLE_SESSION_CATALOG_SUPPORT,
+ GRAVITINO_EXCLUDED_CATALOGS);
+ }
+
+ /**
+ * Validates and normalizes the configured excluded catalog names.
+ *
+ * @param catalogNames the configured catalog names
+ * @param sessionCatalogSupport whether session catalog support is enabled
+ * @return the trimmed, de-duplicated catalog names
+ * @throws IllegalArgumentException if a name is blank, or names are configured while session
+ * catalog support is disabled
+ */
+ @VisibleForTesting
+ static Set<String> parseExcludedCatalogs(
+ List<String> catalogNames, boolean sessionCatalogSupport) {
+ if (catalogNames == null || catalogNames.isEmpty()) {
+ return ImmutableSet.of();
+ }
+ Preconditions.checkArgument(
+ sessionCatalogSupport,
+ "%s can only be set when %s is true",
+ GRAVITINO_EXCLUDED_CATALOGS.key(),
+ GRAVITINO_ENABLE_SESSION_CATALOG_SUPPORT.key());
+ ImmutableSet.Builder<String> builder = ImmutableSet.builder();
+ for (String catalogName : catalogNames) {
+ Preconditions.checkArgument(
+ StringUtils.isNotBlank(catalogName),
+ "%s must not contain blank catalog names, but got %s",
+ GRAVITINO_EXCLUDED_CATALOGS.key(),
+ catalogNames);
+ builder.add(catalogName.trim());
+ }
+ return builder.build();
}
@VisibleForTesting
diff --git a/flink-connector/flink-common/src/main/java/org/apache/gravitino/flink/connector/store/GravitinoCatalogStoreFactoryOptions.java b/flink-connector/flink-common/src/main/java/org/apache/gravitino/flink/connector/store/GravitinoCatalogStoreFactoryOptions.java
index 6c2d0085fb..9a4ea1a451 100644
--- a/flink-connector/flink-common/src/main/java/org/apache/gravitino/flink/connector/store/GravitinoCatalogStoreFactoryOptions.java
+++ b/flink-connector/flink-common/src/main/java/org/apache/gravitino/flink/connector/store/GravitinoCatalogStoreFactoryOptions.java
@@ -20,6 +20,7 @@
package org.apache.gravitino.flink.connector.store;
import com.google.common.collect.ImmutableMap;
+import java.util.List;
import java.util.Map;
import org.apache.flink.configuration.ConfigOption;
import org.apache.flink.configuration.ConfigOptions;
@@ -47,6 +48,24 @@ public class GravitinoCatalogStoreFactoryOptions {
.withDescription(
"Whether to enable support for Flink's session catalog in the Gravitino catalog store");
+ /**
+ * Catalog names that are never resolved against Gravitino in the current Flink session. A session
+ * catalog can then be created under the same name as an existing Gravitino catalog without
+ * loading, modifying, or dropping the Gravitino catalog. Only valid when {@link
+ * #GRAVITINO_ENABLE_SESSION_CATALOG_SUPPORT} is {@code true}.
+ */
+ public static final ConfigOption<List<String>> GRAVITINO_EXCLUDED_CATALOGS =
+ ConfigOptions.key("gravitino.excludedCatalogs")
+ .stringType()
+ .asList()
+ .defaultValues()
+ .withDescription(
+ "Semicolon-separated catalog names that are never resolved against Gravitino in "
+ + "this Flink session. Session catalogs can be created under these names even "
+ + "if Gravitino has catalogs with the same names, and the Gravitino catalogs "
+ + "are never loaded, modified, or dropped by this session. Only valid when "
+ + "'gravitino.enableSessionCatalogSupport' is true.");
+
public static final ConfigOption<Map<String, String>> GRAVITINO_CLIENT_CONFIG =
ConfigOptions.key("gravitino.client")
.mapType()
diff --git a/flink-connector/flink-common/src/main/java/org/apache/gravitino/flink/connector/store/GravitinoSessionCatalogStore.java b/flink-connector/flink-common/src/main/java/org/apache/gravitino/flink/connector/store/GravitinoSessionCatalogStore.java
index ffb0045247..f31ca1d9d1 100644
--- a/flink-connector/flink-common/src/main/java/org/apache/gravitino/flink/connector/store/GravitinoSessionCatalogStore.java
+++ b/flink-connector/flink-common/src/main/java/org/apache/gravitino/flink/connector/store/GravitinoSessionCatalogStore.java
@@ -21,6 +21,8 @@ package org.apache.gravitino.flink.connector.store;
import static org.apache.gravitino.flink.connector.utils.FactoryUtils.isGravitinoManagedCatalogType;
+import com.google.common.collect.ImmutableSet;
+import java.util.Collections;
import java.util.HashSet;
import java.util.Optional;
import java.util.Set;
@@ -45,8 +47,14 @@ import org.apache.flink.util.Preconditions;
* stored in the session-scoped in-memory store only and are not persisted to Gravitino.
* </ul>
*
- * <p>When retrieving, listing, or removing catalogs, entries in the in-memory store take precedence
- * over entries in the Gravitino-backed store.
+ * <p>When retrieving or removing catalogs, entries in the in-memory store take precedence over
+ * entries in the Gravitino-backed store.
+ *
+ * <p>Catalog names in the excluded set are never resolved against the Gravitino-backed store: every
+ * lookup, existence check, listing, and removal for these names consults the in-memory store only.
+ * This allows a session catalog to use the same name as an existing Gravitino catalog without
+ * loading, modifying, or dropping the Gravitino catalog. Gravitino-managed catalog types cannot be
+ * created under an excluded name because they would be persisted to Gravitino.
*
* <p>This store is intended to be used per Flink session, keeping transient catalogs in memory
* while delegating persistent catalogs to Apache Gravitino.
@@ -54,13 +62,37 @@ import org.apache.flink.util.Preconditions;
public class GravitinoSessionCatalogStore extends AbstractCatalogStore {
private final GenericInMemoryCatalogStore memoryCatalogStore;
private final GravitinoCatalogStore gravitinoCatalogStore;
+ private final Set<String> excludedCatalogs;
+ /**
+ * Creates a session catalog store without excluded catalog names.
+ *
+ * @param gravitinoCatalogStore the Gravitino-backed catalog store
+ * @param memoryCatalogStore the session-scoped in-memory catalog store
+ */
public GravitinoSessionCatalogStore(
GravitinoCatalogStore gravitinoCatalogStore, GenericInMemoryCatalogStore memoryCatalogStore) {
+ this(gravitinoCatalogStore, memoryCatalogStore, Collections.emptySet());
+ }
+
+ /**
+ * Creates a session catalog store.
+ *
+ * @param gravitinoCatalogStore the Gravitino-backed catalog store
+ * @param memoryCatalogStore the session-scoped in-memory catalog store
+ * @param excludedCatalogs catalog names that are never resolved against the Gravitino-backed
+ * store
+ */
+ public GravitinoSessionCatalogStore(
+ GravitinoCatalogStore gravitinoCatalogStore,
+ GenericInMemoryCatalogStore memoryCatalogStore,
+ Set<String> excludedCatalogs) {
Preconditions.checkArgument(gravitinoCatalogStore != null, "CatalogStore cannot be null");
Preconditions.checkArgument(memoryCatalogStore != null, "MemoryCatalogStore cannot be null");
+ Preconditions.checkArgument(excludedCatalogs != null, "ExcludedCatalogs cannot be null");
this.gravitinoCatalogStore = gravitinoCatalogStore;
this.memoryCatalogStore = memoryCatalogStore;
+ this.excludedCatalogs = ImmutableSet.copyOf(excludedCatalogs);
}
@Override
@@ -75,6 +107,15 @@ public class GravitinoSessionCatalogStore extends AbstractCatalogStore {
catalogName, CommonCatalogOptions.CATALOG_TYPE.key()));
}
if (isGravitinoManagedCatalogType(catalogType)) {
+ if (isExcluded(catalogName)) {
+ throw new CatalogException(
+ String.format(
+ "Cannot create Gravitino-managed catalog '%s' of type '%s': the catalog name is "
+ + "excluded from Gravitino by '%s', so only session catalogs can use it.",
+ catalogName,
+ catalogType,
+ GravitinoCatalogStoreFactoryOptions.GRAVITINO_EXCLUDED_CATALOGS.key()));
+ }
gravitinoCatalogStore.storeCatalog(catalogName, descriptor);
} else {
memoryCatalogStore.storeCatalog(catalogName, descriptor);
@@ -82,7 +123,8 @@ public class GravitinoSessionCatalogStore extends AbstractCatalogStore {
}
/**
- * Removes the specified catalog.
+ * Removes the specified catalog. Excluded catalog names are only removed from the in-memory
+ * store, so the Gravitino catalog with the same name is never dropped.
*
* @param catalogName name of the catalog to remove
* @param ignoreIfNotExists if true, ignore when the catalog does not exist
@@ -90,7 +132,7 @@ public class GravitinoSessionCatalogStore extends AbstractCatalogStore {
*/
@Override
public void removeCatalog(String catalogName, boolean ignoreIfNotExists) throws CatalogException {
- if (memoryCatalogStore.contains(catalogName)) {
+ if (isExcluded(catalogName) || memoryCatalogStore.contains(catalogName)) {
memoryCatalogStore.removeCatalog(catalogName, ignoreIfNotExists);
} else {
gravitinoCatalogStore.removeCatalog(catalogName, ignoreIfNotExists);
@@ -98,7 +140,7 @@ public class GravitinoSessionCatalogStore extends AbstractCatalogStore {
}
/**
- * Get a catalog by name.
+ * Get a catalog by name. Excluded catalog names are only looked up in the in-memory store.
*
* @param catalogName name of the catalog to retrieve
* @return the requested catalog or empty if the catalog does not exist
@@ -107,25 +149,55 @@ public class GravitinoSessionCatalogStore extends AbstractCatalogStore {
@Override
public Optional<CatalogDescriptor> getCatalog(String catalogName) throws CatalogException {
Optional<CatalogDescriptor> descriptor = memoryCatalogStore.getCatalog(catalogName);
- return descriptor.isPresent() ? descriptor : gravitinoCatalogStore.getCatalog(catalogName);
+ if (descriptor.isPresent() || isExcluded(catalogName)) {
+ return descriptor;
+ }
+ return gravitinoCatalogStore.getCatalog(catalogName);
}
+ /**
+ * Lists the catalogs of both stores. Gravitino catalogs whose names are excluded are omitted.
+ *
+ * @return the names of all catalogs visible in this session
+ * @throws CatalogException if the catalogs cannot be listed
+ */
@Override
public Set<String> listCatalogs() throws CatalogException {
Set<String> catalogs = new HashSet<>();
catalogs.addAll(memoryCatalogStore.listCatalogs());
+ Set<String> gravitinoCatalogs;
try {
- catalogs.addAll(gravitinoCatalogStore.listCatalogs());
+ gravitinoCatalogs = gravitinoCatalogStore.listCatalogs();
} catch (CatalogException e) {
throw new CatalogException("Failed to list catalog.", e);
} catch (RuntimeException e) {
throw new CatalogException("Failed to list catalog.", e);
}
+ for (String catalogName : gravitinoCatalogs) {
+ if (!isExcluded(catalogName)) {
+ catalogs.add(catalogName);
+ }
+ }
return catalogs;
}
+ /**
+ * Checks whether a catalog exists. Excluded catalog names are only checked in the in-memory
+ * store.
+ *
+ * @param catalogName name of the catalog to check
+ * @return true if the catalog exists in this session
+ * @throws CatalogException if the existence cannot be checked
+ */
@Override
public boolean contains(String catalogName) throws CatalogException {
- return memoryCatalogStore.contains(catalogName) || gravitinoCatalogStore.contains(catalogName);
+ if (memoryCatalogStore.contains(catalogName)) {
+ return true;
+ }
+ return !isExcluded(catalogName) && gravitinoCatalogStore.contains(catalogName);
+ }
+
+ private boolean isExcluded(String catalogName) {
+ return excludedCatalogs.contains(catalogName);
}
}
diff --git a/flink-connector/flink-common/src/main/java/org/apache/gravitino/flink/connector/utils/FactoryUtils.java b/flink-connector/flink-common/src/main/java/org/apache/gravitino/flink/connector/utils/FactoryUtils.java
index fc6fc9fb32..4556b6565b 100644
--- a/flink-connector/flink-common/src/main/java/org/apache/gravitino/flink/connector/utils/FactoryUtils.java
+++ b/flink-connector/flink-common/src/main/java/org/apache/gravitino/flink/connector/utils/FactoryUtils.java
@@ -23,12 +23,20 @@ import static org.apache.flink.table.factories.FactoryUtil.validateWatermarkOpti
import com.google.common.annotations.VisibleForTesting;
import com.google.common.collect.ImmutableSet;
+import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
+import java.util.List;
+import java.util.Objects;
import java.util.ServiceConfigurationError;
import java.util.ServiceLoader;
import java.util.Set;
import java.util.stream.Collectors;
+import org.apache.flink.configuration.ConfigOption;
+import org.apache.flink.configuration.ConfigOptions;
+import org.apache.flink.configuration.ReadableConfig;
+import org.apache.flink.table.catalog.CommonCatalogOptions;
+import org.apache.flink.table.catalog.exceptions.CatalogException;
import org.apache.flink.table.factories.CatalogFactory;
import org.apache.flink.table.factories.Factory;
import org.apache.flink.table.factories.FactoryUtil;
@@ -37,6 +45,7 @@ import org.apache.gravitino.flink.connector.hive.GravitinoHiveCatalogFactoryOpti
import org.apache.gravitino.flink.connector.iceberg.GravitinoIcebergCatalogFactoryOptions;
import org.apache.gravitino.flink.connector.jdbc.GravitinoJdbcCatalogFactoryOptions;
import org.apache.gravitino.flink.connector.paimon.GravitinoPaimonCatalogFactoryOptions;
+import org.apache.gravitino.flink.connector.store.GravitinoCatalogStoreFactoryOptions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -46,6 +55,21 @@ public class FactoryUtils {
private static final Logger LOG = LoggerFactory.getLogger(FactoryUtils.class);
+ /**
+ * {@link GravitinoCatalogStoreFactoryOptions#GRAVITINO_EXCLUDED_CATALOGS} as seen in the session
+ * configuration, where catalog store options carry the {@code table.catalog-store.gravitino.}
+ * prefix.
+ */
+ private static final ConfigOption<List<String>> SESSION_EXCLUDED_CATALOGS =
+ ConfigOptions.key(
+ CommonCatalogOptions.TABLE_CATALOG_STORE_OPTION_PREFIX
+ + GravitinoCatalogStoreFactoryOptions.GRAVITINO
+ + "."
+ + GravitinoCatalogStoreFactoryOptions.GRAVITINO_EXCLUDED_CATALOGS.key())
+ .stringType()
+ .asList()
+ .noDefaultValue();
+
/** The set of catalog type identifiers managed by Gravitino. */
private static final ImmutableSet<String> GRAVITINO_CATALOG_TYPES =
ImmutableSet.of(
@@ -153,6 +177,10 @@ public class FactoryUtils {
/**
* Creates a utility that helps to validate options for a {@link CatalogFactory}.
*
+ * <p>Gravitino catalog factories must call this method before creating a catalog. It rejects
+ * catalog names excluded from Gravitino by {@link
+ * GravitinoCatalogStoreFactoryOptions#GRAVITINO_EXCLUDED_CATALOGS} in the current session.
+ *
* <p>Note: This utility checks for left-over options in the final step.
*
* @param factory The catalog factory to create the helper for
@@ -161,6 +189,42 @@ public class FactoryUtils {
*/
public static FactoryUtil.CatalogFactoryHelper createCatalogFactoryHelper(
CatalogFactory factory, CatalogFactory.Context context) {
+ checkCatalogNameNotExcluded(factory, context);
return new FactoryUtils.GravitinoCatalogFactoryHelper(factory, context);
}
+
+ /**
+ * Rejects creating a Gravitino-managed catalog whose name is excluded from Gravitino in the
+ * current session. Flink instantiates and registers a catalog before storing it in the catalog
+ * store, so the check must happen here: a Gravitino-managed catalog resolves the Gravitino
+ * catalog with the same name, which the exclusion must hide from the session.
+ *
+ * @param factory the Gravitino catalog factory
+ * @param context the catalog factory context, whose configuration is the session configuration
+ * @throws CatalogException if the catalog name is excluded from Gravitino
+ */
+ @VisibleForTesting
+ static void checkCatalogNameNotExcluded(CatalogFactory factory, CatalogFactory.Context context) {
+ ReadableConfig sessionConfiguration = context.getConfiguration();
+ if (sessionConfiguration == null) {
+ return;
+ }
+ List<String> excludedCatalogs =
+ sessionConfiguration.getOptional(SESSION_EXCLUDED_CATALOGS).orElse(Collections.emptyList());
+ String catalogName = context.getName();
+ boolean excluded =
+ excludedCatalogs.stream()
+ .filter(Objects::nonNull)
+ .map(String::trim)
+ .anyMatch(name -> name.equals(catalogName));
+ if (excluded) {
+ throw new CatalogException(
+ String.format(
+ "Cannot create Gravitino-managed catalog '%s' of type '%s': the catalog name is "
+ + "excluded from Gravitino by '%s', so only session catalogs can use it.",
+ catalogName,
+ factory.factoryIdentifier(),
+ GravitinoCatalogStoreFactoryOptions.GRAVITINO_EXCLUDED_CATALOGS.key()));
+ }
+ }
}
diff --git a/flink-connector/flink/src/test/java/org/apache/gravitino/flink/connector/integration/test/session/FlinkSupportsSessionCatalogIT.java b/flink-connector/flink-common/src/test/java/org/apache/gravitino/flink/connector/integration/test/session/FlinkSupportsSessionCatalogIT.java
similarity index 59%
rename from flink-connector/flink/src/test/java/org/apache/gravitino/flink/connector/integration/test/session/FlinkSupportsSessionCatalogIT.java
rename to flink-connector/flink-common/src/test/java/org/apache/gravitino/flink/connector/integration/test/session/FlinkSupportsSessionCatalogIT.java
index 4345d4ab9d..754c5c8573 100644
--- a/flink-connector/flink/src/test/java/org/apache/gravitino/flink/connector/integration/test/session/FlinkSupportsSessionCatalogIT.java
+++ b/flink-connector/flink-common/src/test/java/org/apache/gravitino/flink/connector/integration/test/session/FlinkSupportsSessionCatalogIT.java
@@ -26,6 +26,7 @@ import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Arrays;
import java.util.Comparator;
+import java.util.Map;
import java.util.Optional;
import java.util.stream.Stream;
import org.apache.flink.configuration.Configuration;
@@ -34,6 +35,7 @@ import org.apache.flink.table.api.TableEnvironment;
import org.apache.flink.table.catalog.Catalog;
import org.apache.flink.table.catalog.CatalogDescriptor;
import org.apache.flink.table.catalog.CommonCatalogOptions;
+import org.apache.flink.table.catalog.GenericInMemoryCatalog;
import org.apache.flink.table.catalog.hive.factories.HiveCatalogFactoryOptions;
import org.apache.gravitino.catalog.hive.HiveConstants;
import org.apache.gravitino.flink.connector.hive.GravitinoHiveCatalogFactoryOptions;
@@ -58,12 +60,15 @@ import org.slf4j.LoggerFactory;
* <li>Session-scoped catalog types (e.g. {@code generic_in_memory}) are held in memory only and
* never reach the Gravitino server.
* <li>Both stores contribute to the catalog list returned by {@code SHOW CATALOGS}.
+ * <li>Names listed in {@code gravitino.excludedCatalogs} are never resolved against Gravitino, so
+ * a session catalog can reuse the name of an existing Gravitino catalog without changing it.
* </ul>
*
- * <p>Requires a running Hive Docker container for the Gravitino-managed catalog tests.
+ * <p>Requires a running Hive Docker container for the Gravitino-managed catalog tests. Concrete
+ * subclasses live in the Flink-minor modules that support the Hive catalog.
*/
@Tag("gravitino-docker-test")
-public class FlinkSupportsSessionCatalogIT extends FlinkEnvIT {
+public abstract class FlinkSupportsSessionCatalogIT extends FlinkEnvIT {
private static final Logger LOG = LoggerFactory.getLogger(FlinkSupportsSessionCatalogIT.class);
@@ -88,8 +93,8 @@ public class FlinkSupportsSessionCatalogIT extends FlinkEnvIT {
"table.catalog-store.kind", GravitinoCatalogStoreFactoryOptions.GRAVITINO);
configuration.setString("table.catalog-store.gravitino.gravitino.metalake", GRAVITINO_METALAKE);
configuration.setString("table.catalog-store.gravitino.gravitino.uri", gravitinoUri);
- configuration.setBoolean(
- "table.catalog-store.gravitino.gravitino.enableSessionCatalogSupport", true);
+ configuration.setString(
+ "table.catalog-store.gravitino.gravitino.enableSessionCatalogSupport", "true");
EnvironmentSettings settings =
EnvironmentSettings.newInstance().withConfiguration(configuration).inBatchMode().build();
tableEnv = TableEnvironment.create(settings);
@@ -304,6 +309,204 @@ public class FlinkSupportsSessionCatalogIT extends FlinkEnvIT {
Assertions.assertFalse(droppedCatalog.isPresent(), "Catalog should be dropped");
}
+ /**
+ * Without exclusion, creating a session catalog with the name of an existing Gravitino catalog is
+ * rejected, and the Gravitino catalog is left unchanged.
+ */
+ @Test
+ public void testCreateSessionCatalogWithGravitinoCatalogNameFailsWithoutExclusion() {
+ tableEnv.useCatalog(DEFAULT_CATALOG);
+ String catalogName = "session_it_conflict_hive";
+ createGravitinoHiveCatalog(catalogName);
+
+ try {
+ Map<String, String> propertiesBefore = metalake.loadCatalog(catalogName).properties();
+
+ Assertions.assertThrows(
+ Exception.class,
+ () ->
+ tableEnv.executeSql(
+ String.format(
+ "CREATE CATALOG %s WITH ('type'='generic_in_memory')", catalogName)));
+
+ Assertions.assertTrue(metalake.catalogExists(catalogName));
+ Assertions.assertEquals(propertiesBefore, metalake.loadCatalog(catalogName).properties());
+ } finally {
+ tableEnv.useCatalog(DEFAULT_CATALOG);
+ tableEnv.executeSql("DROP CATALOG " + catalogName);
+ Assertions.assertFalse(metalake.catalogExists(catalogName));
+ }
+ }
+
+ /**
+ * With {@code gravitino.excludedCatalogs}, a session catalog can use the name of an existing
+ * Gravitino catalog. Creating, using, and dropping the session catalog never loads, modifies, or
+ * drops the Gravitino catalog, and other sessions keep seeing the Gravitino catalog.
+ */
+ @Test
+ public void testExcludedCatalogAllowsSessionCatalogWithGravitinoCatalogName() {
+ tableEnv.useCatalog(DEFAULT_CATALOG);
+ String catalogName = "session_it_excluded_hive";
+ String otherCatalogName = "session_it_not_excluded_hive";
+ String sessionDatabase = "session_it_native_db";
+ createGravitinoHiveCatalog(catalogName);
+ createGravitinoHiveCatalog(otherCatalogName);
+
+ try {
+ Map<String, String> propertiesBefore = metalake.loadCatalog(catalogName).properties();
+ TableEnvironment excludingEnv = createTableEnvExcluding(catalogName);
+
+ // The Gravitino catalog with the excluded name is hidden in this session only.
+ Assertions.assertFalse(Arrays.asList(excludingEnv.listCatalogs()).contains(catalogName));
+ Assertions.assertTrue(Arrays.asList(excludingEnv.listCatalogs()).contains(otherCatalogName));
+ Assertions.assertFalse(excludingEnv.getCatalog(catalogName).isPresent());
+
+ excludingEnv.executeSql(
+ String.format("CREATE CATALOG %s WITH ('type'='generic_in_memory')", catalogName));
+ Optional<Catalog> sessionCatalog = excludingEnv.getCatalog(catalogName);
+ Assertions.assertTrue(sessionCatalog.isPresent());
+ Assertions.assertInstanceOf(GenericInMemoryCatalog.class, sessionCatalog.get());
+
+ excludingEnv.useCatalog(catalogName);
+ excludingEnv.executeSql("CREATE DATABASE " + sessionDatabase);
+ Assertions.assertTrue(
+ Arrays.asList(excludingEnv.listDatabases()).contains(sessionDatabase),
+ "The database must be created in the session catalog");
+ excludingEnv.useCatalog(DEFAULT_CATALOG);
+
+ // The Gravitino catalog is untouched: no schema was created there and its properties are
+ // unchanged.
+ org.apache.gravitino.Catalog gravitinoCatalog = metalake.loadCatalog(catalogName);
+ Assertions.assertFalse(gravitinoCatalog.asSchemas().schemaExists(sessionDatabase));
+ Assertions.assertEquals(propertiesBefore, gravitinoCatalog.properties());
+
+ // Other sessions keep resolving the name to the Gravitino catalog.
+ Assertions.assertTrue(Arrays.asList(tableEnv.listCatalogs()).contains(catalogName));
+ Assertions.assertFalse(
+ tableEnv.getCatalog(catalogName).get() instanceof GenericInMemoryCatalog);
+
+ // Dropping the session catalog never drops the Gravitino catalog.
+ excludingEnv.executeSql("DROP CATALOG " + catalogName);
+ Assertions.assertFalse(excludingEnv.getCatalog(catalogName).isPresent());
+ Assertions.assertTrue(metalake.catalogExists(catalogName));
+ Assertions.assertThrows(
+ Exception.class, () -> excludingEnv.executeSql("DROP CATALOG " + catalogName));
+ Assertions.assertTrue(metalake.catalogExists(catalogName));
+ Assertions.assertEquals(propertiesBefore, metalake.loadCatalog(catalogName).properties());
+
+ // Catalogs that are not excluded keep their existing behavior in the same session.
+ excludingEnv.useCatalog(otherCatalogName);
+ excludingEnv.listDatabases();
+ excludingEnv.useCatalog(DEFAULT_CATALOG);
+ excludingEnv.executeSql("DROP CATALOG " + otherCatalogName);
+ Assertions.assertFalse(metalake.catalogExists(otherCatalogName));
+ } finally {
+ tableEnv.useCatalog(DEFAULT_CATALOG);
+ tableEnv.executeSql("DROP CATALOG IF EXISTS " + catalogName);
+ tableEnv.executeSql("DROP CATALOG IF EXISTS " + otherCatalogName);
+ Assertions.assertFalse(metalake.catalogExists(catalogName));
+ Assertions.assertFalse(metalake.catalogExists(otherCatalogName));
+ }
+ }
+
+ /**
+ * A Gravitino-managed catalog type cannot be created under an excluded name, because it would be
+ * persisted to Gravitino. The existing Gravitino catalog must be left unchanged.
+ */
+ @Test
+ public void testExcludedCatalogRejectsGravitinoManagedCatalogType() {
+ tableEnv.useCatalog(DEFAULT_CATALOG);
+ String catalogName = "session_it_excluded_managed_hive";
+ createGravitinoHiveCatalog(catalogName);
+
+ try {
+ Map<String, String> propertiesBefore = metalake.loadCatalog(catalogName).properties();
+ TableEnvironment excludingEnv = createTableEnvExcluding(catalogName);
+
+ Exception exception =
+ Assertions.assertThrows(
+ Exception.class,
+ () ->
+ excludingEnv.executeSql(
+ String.format(
+ "CREATE CATALOG %s WITH ("
+ + "'type'='%s',"
+ + "'hive-conf-dir'='%s',"
+ + "'hive.metastore.uris'='%s'"
+ + ")",
+ catalogName,
+ GravitinoHiveCatalogFactoryOptions.IDENTIFIER,
+ hiveConfDir,
+ hiveMetastoreUri)));
+
+ Assertions.assertTrue(
+ containsMessage(exception, "gravitino.excludedCatalogs"), collectMessages(exception));
+ // The rejected catalog must not stay registered in the session, otherwise it would expose
+ // the excluded Gravitino catalog with the same name.
+ Assertions.assertFalse(Arrays.asList(excludingEnv.listCatalogs()).contains(catalogName));
+ Assertions.assertFalse(excludingEnv.getCatalog(catalogName).isPresent());
+ Assertions.assertThrows(Exception.class, () -> excludingEnv.useCatalog(catalogName));
+ Assertions.assertTrue(metalake.catalogExists(catalogName));
+ Assertions.assertEquals(propertiesBefore, metalake.loadCatalog(catalogName).properties());
+ } finally {
+ tableEnv.useCatalog(DEFAULT_CATALOG);
+ tableEnv.executeSql("DROP CATALOG IF EXISTS " + catalogName);
+ Assertions.assertFalse(metalake.catalogExists(catalogName));
+ }
+ }
+
+ private static boolean containsMessage(Throwable throwable, String expectedMessage) {
+ for (Throwable current = throwable; current != null; current = current.getCause()) {
+ if (current.getMessage() != null && current.getMessage().contains(expectedMessage)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ private static String collectMessages(Throwable throwable) {
+ StringBuilder messages = new StringBuilder();
+ for (Throwable current = throwable; current != null; current = current.getCause()) {
+ messages.append(current.getClass().getName()).append(": ").append(current.getMessage());
+ messages.append('\n');
+ }
+ return messages.toString();
+ }
+
+ private void createGravitinoHiveCatalog(String catalogName) {
+ tableEnv.executeSql(
+ String.format(
+ "CREATE CATALOG %s WITH ("
+ + "'type'='%s',"
+ + "'hive-conf-dir'='%s',"
+ + "'hive.metastore.uris'='%s'"
+ + ")",
+ catalogName,
+ GravitinoHiveCatalogFactoryOptions.IDENTIFIER,
+ hiveConfDir,
+ hiveMetastoreUri));
+ Assertions.assertTrue(metalake.catalogExists(catalogName));
+ }
+
+ /**
+ * Creates a separate Flink session that excludes the given catalog names. The session is not
+ * closed, because closing its catalog store would also close the Gravitino client shared with
+ * {@code tableEnv}.
+ */
+ private TableEnvironment createTableEnvExcluding(String... catalogNames) {
+ Configuration configuration = new Configuration();
+ configuration.setString(
+ "table.catalog-store.kind", GravitinoCatalogStoreFactoryOptions.GRAVITINO);
+ configuration.setString("table.catalog-store.gravitino.gravitino.metalake", GRAVITINO_METALAKE);
+ configuration.setString("table.catalog-store.gravitino.gravitino.uri", gravitinoUri);
+ configuration.setString(
+ "table.catalog-store.gravitino.gravitino.enableSessionCatalogSupport", "true");
+ configuration.setString(
+ "table.catalog-store.gravitino.gravitino.excludedCatalogs", String.join(";", catalogNames));
+ return TableEnvironment.create(
+ EnvironmentSettings.newInstance().withConfiguration(configuration).inBatchMode().build());
+ }
+
private static void initHiveConfDir() {
if (hiveConfDir != null) {
return;
diff --git a/flink-connector/flink-common/src/test/java/org/apache/gravitino/flink/connector/store/TestGravitinoCatalogStoreFactory.java b/flink-connector/flink-common/src/test/java/org/apache/gravitino/flink/connector/store/TestGravitinoCatalogStoreFactory.java
index 57c38875cb..30b0aeb3dc 100644
--- a/flink-connector/flink-common/src/test/java/org/apache/gravitino/flink/connector/store/TestGravitinoCatalogStoreFactory.java
+++ b/flink-connector/flink-common/src/test/java/org/apache/gravitino/flink/connector/store/TestGravitinoCatalogStoreFactory.java
@@ -21,7 +21,11 @@ package org.apache.gravitino.flink.connector.store;
import static org.apache.flink.table.factories.FactoryUtil.createCatalogStoreFactoryHelper;
import static org.mockito.Mockito.mock;
+import com.google.common.collect.ImmutableSet;
import java.lang.reflect.Field;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
import org.apache.flink.configuration.Configuration;
import org.apache.flink.table.catalog.CatalogStore;
import org.apache.flink.table.catalog.GenericInMemoryCatalogStore;
@@ -38,6 +42,9 @@ import org.junit.jupiter.api.Test;
*/
public class TestGravitinoCatalogStoreFactory {
+ private static final String EXCLUDED_CATALOGS_KEY =
+ "table.catalog-store.gravitino.gravitino.excludedCatalogs";
+
/**
* When {@code gravitino.enableSessionCatalogSupport=true} the factory must return a {@link
* GravitinoSessionCatalogStore}.
@@ -130,6 +137,82 @@ public class TestGravitinoCatalogStoreFactory {
Assertions.assertFalse(store instanceof GravitinoSessionCatalogStore);
}
+ // -------------------------------------------------------------------------
+ // excluded catalogs
+ // -------------------------------------------------------------------------
+
+ @Test
+ void testOptionParsing_excludedCatalogsAbsent_defaultsToEmpty() {
+ List<String> parsed = parseExcludedCatalogsOption(baseConfiguration());
+
+ Assertions.assertTrue(parsed.isEmpty());
+ Assertions.assertEquals(
+ ImmutableSet.of(), GravitinoCatalogStoreFactory.parseExcludedCatalogs(parsed, false));
+ }
+
+ @Test
+ @SuppressWarnings("deprecation")
+ void testOptionParsing_excludedCatalogs_isReadFromConfig() {
+ Configuration configuration = baseConfiguration();
+ configuration.setString(EXCLUDED_CATALOGS_KEY, "paimon_catalog; hive_catalog;paimon_catalog");
+
+ List<String> parsed = parseExcludedCatalogsOption(configuration);
+
+ Assertions.assertEquals(
+ ImmutableSet.of("paimon_catalog", "hive_catalog"),
+ GravitinoCatalogStoreFactory.parseExcludedCatalogs(parsed, true));
+ }
+
+ @Test
+ void testParseExcludedCatalogs_blankName_throwsIllegalArgumentException() {
+ IllegalArgumentException exception =
+ Assertions.assertThrows(
+ IllegalArgumentException.class,
+ () ->
+ GravitinoCatalogStoreFactory.parseExcludedCatalogs(
+ Arrays.asList("paimon_catalog", " "), true));
+
+ Assertions.assertTrue(
+ exception
+ .getMessage()
+ .contains(GravitinoCatalogStoreFactoryOptions.GRAVITINO_EXCLUDED_CATALOGS.key()));
+ }
+
+ @Test
+ void testParseExcludedCatalogs_sessionCatalogSupportDisabled_throwsIllegalArgumentException() {
+ IllegalArgumentException exception =
+ Assertions.assertThrows(
+ IllegalArgumentException.class,
+ () ->
+ GravitinoCatalogStoreFactory.parseExcludedCatalogs(
+ Collections.singletonList("paimon_catalog"), false));
+
+ Assertions.assertTrue(
+ exception
+ .getMessage()
+ .contains(
+ GravitinoCatalogStoreFactoryOptions.GRAVITINO_ENABLE_SESSION_CATALOG_SUPPORT
+ .key()));
+ }
+
+ /**
+ * The real {@link GravitinoCatalogStoreFactory#open} path must reject excluded catalogs when
+ * session catalog support is disabled, before any Gravitino client is created.
+ */
+ @Test
+ @SuppressWarnings("deprecation")
+ void testOpen_excludedCatalogsWithoutSessionCatalogSupport_failsFast() {
+ Configuration configuration = baseConfiguration();
+ configuration.setString(EXCLUDED_CATALOGS_KEY, "paimon_catalog");
+ CatalogStoreFactory.Context context =
+ TableFactoryUtil.buildCatalogStoreFactoryContext(
+ configuration, TestGravitinoCatalogStoreFactory.class.getClassLoader());
+ GravitinoCatalogStoreFactory factory = new GravitinoCatalogStoreFactory();
+
+ Assertions.assertThrows(IllegalArgumentException.class, () -> factory.open(context));
+ Assertions.assertNull(factory.createCatalogStore());
+ }
+
// -------------------------------------------------------------------------
// helpers
// -------------------------------------------------------------------------
@@ -190,6 +273,16 @@ public class TestGravitinoCatalogStoreFactory {
.get(GravitinoCatalogStoreFactoryOptions.GRAVITINO_ENABLE_SESSION_CATALOG_SUPPORT);
}
+ private static List<String> parseExcludedCatalogsOption(Configuration configuration) {
+ CatalogStoreFactory.Context context =
+ TableFactoryUtil.buildCatalogStoreFactoryContext(
+ configuration, TestGravitinoCatalogStoreFactory.class.getClassLoader());
+ FactoryUtil.FactoryHelper<CatalogStoreFactory> helper =
+ createCatalogStoreFactoryHelper(new GravitinoCatalogStoreFactory(), context);
+ helper.validate();
+ return helper.getOptions().get(GravitinoCatalogStoreFactoryOptions.GRAVITINO_EXCLUDED_CATALOGS);
+ }
+
private static Configuration baseConfiguration() {
Configuration configuration = new Configuration();
configuration.setString(
diff --git a/flink-connector/flink-common/src/test/java/org/apache/gravitino/flink/connector/store/TestGravitinoSessionCatalogStore.java b/flink-connector/flink-common/src/test/java/org/apache/gravitino/flink/connector/store/TestGravitinoSessionCatalogStore.java
index d564fc7415..a31037563a 100644
--- a/flink-connector/flink-common/src/test/java/org/apache/gravitino/flink/connector/store/TestGravitinoSessionCatalogStore.java
+++ b/flink-connector/flink-common/src/test/java/org/apache/gravitino/flink/connector/store/TestGravitinoSessionCatalogStore.java
@@ -19,12 +19,17 @@
package org.apache.gravitino.flink.connector.store;
import static org.apache.gravitino.flink.connector.utils.FactoryUtils.isGravitinoManagedCatalogType;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyBoolean;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import com.google.common.collect.ImmutableSet;
+import java.util.Locale;
import java.util.Optional;
import java.util.Set;
import org.apache.flink.configuration.Configuration;
@@ -51,6 +56,9 @@ public class TestGravitinoSessionCatalogStore {
*/
private static final String SESSION_CATALOG_TYPE = "hive";
+ /** A catalog name excluded from Gravitino in the session. */
+ private static final String EXCLUDED_CATALOG = "paimon_catalog";
+
private GravitinoCatalogStore gravitinoCatalogStore;
private GenericInMemoryCatalogStore memoryCatalogStore;
private GravitinoSessionCatalogStore sessionCatalogStore;
@@ -214,10 +222,152 @@ public class TestGravitinoSessionCatalogStore {
Assertions.assertFalse(sessionCatalogStore.contains("hive"));
}
+ // -------------------------------------------------------------------------
+ // excluded catalogs
+ // -------------------------------------------------------------------------
+
+ @Test
+ void testConstructor_nullExcludedCatalogs_throwsIllegalArgumentException() {
+ Assertions.assertThrows(
+ IllegalArgumentException.class,
+ () -> new GravitinoSessionCatalogStore(gravitinoCatalogStore, memoryCatalogStore, null));
+ }
+
+ @Test
+ void testExcludedCatalog_contains_onlyChecksMemory() {
+ GravitinoSessionCatalogStore store = storeExcluding(EXCLUDED_CATALOG);
+ when(memoryCatalogStore.contains(EXCLUDED_CATALOG)).thenReturn(false);
+ when(gravitinoCatalogStore.contains(EXCLUDED_CATALOG)).thenReturn(true);
+
+ Assertions.assertFalse(store.contains(EXCLUDED_CATALOG));
+ verify(gravitinoCatalogStore, never()).contains(EXCLUDED_CATALOG);
+
+ when(memoryCatalogStore.contains(EXCLUDED_CATALOG)).thenReturn(true);
+ Assertions.assertTrue(store.contains(EXCLUDED_CATALOG));
+ verify(gravitinoCatalogStore, never()).contains(EXCLUDED_CATALOG);
+ }
+
+ @Test
+ void testExcludedCatalog_getCatalog_neverFallsBackToGravitino() {
+ GravitinoSessionCatalogStore store = storeExcluding(EXCLUDED_CATALOG);
+ when(memoryCatalogStore.getCatalog(EXCLUDED_CATALOG)).thenReturn(Optional.empty());
+ when(gravitinoCatalogStore.getCatalog(EXCLUDED_CATALOG))
+ .thenReturn(Optional.of(descriptorWithType(GRAVITINO_CATALOG_TYPE)));
+
+ Assertions.assertFalse(store.getCatalog(EXCLUDED_CATALOG).isPresent());
+ verify(gravitinoCatalogStore, never()).getCatalog(EXCLUDED_CATALOG);
+
+ CatalogDescriptor sessionDescriptor = descriptorWithType(SESSION_CATALOG_TYPE);
+ when(memoryCatalogStore.getCatalog(EXCLUDED_CATALOG))
+ .thenReturn(Optional.of(sessionDescriptor));
+ Assertions.assertEquals(Optional.of(sessionDescriptor), store.getCatalog(EXCLUDED_CATALOG));
+ verify(gravitinoCatalogStore, never()).getCatalog(EXCLUDED_CATALOG);
+ }
+
+ @Test
+ void testExcludedCatalog_removeCatalog_neverRemovesFromGravitino() {
+ GravitinoSessionCatalogStore store = storeExcluding(EXCLUDED_CATALOG);
+ when(memoryCatalogStore.contains(EXCLUDED_CATALOG)).thenReturn(false);
+
+ store.removeCatalog(EXCLUDED_CATALOG, true);
+
+ verify(memoryCatalogStore).removeCatalog(EXCLUDED_CATALOG, true);
+ verify(gravitinoCatalogStore, never()).removeCatalog(anyString(), anyBoolean());
+ }
+
+ @Test
+ void testExcludedCatalog_removeMissingCatalog_propagatesMemoryStoreError() {
+ GravitinoSessionCatalogStore store = storeExcluding(EXCLUDED_CATALOG);
+ doThrow(new CatalogException("not found"))
+ .when(memoryCatalogStore)
+ .removeCatalog(EXCLUDED_CATALOG, false);
+
+ Assertions.assertThrows(
+ CatalogException.class, () -> store.removeCatalog(EXCLUDED_CATALOG, false));
+ verify(gravitinoCatalogStore, never()).removeCatalog(anyString(), anyBoolean());
+ }
+
+ @Test
+ void testExcludedCatalog_storeSessionCatalog_storesInMemory() {
+ GravitinoSessionCatalogStore store = storeExcluding(EXCLUDED_CATALOG);
+ CatalogDescriptor descriptor = descriptorWithType(SESSION_CATALOG_TYPE);
+
+ store.storeCatalog(EXCLUDED_CATALOG, descriptor);
+
+ verify(memoryCatalogStore).storeCatalog(EXCLUDED_CATALOG, descriptor);
+ verify(gravitinoCatalogStore, never()).storeCatalog(anyString(), any());
+ }
+
+ @Test
+ void testExcludedCatalog_storeGravitinoManagedCatalog_isRejected() {
+ GravitinoSessionCatalogStore store = storeExcluding(EXCLUDED_CATALOG);
+ CatalogDescriptor descriptor = descriptorWithType(GRAVITINO_CATALOG_TYPE);
+
+ CatalogException exception =
+ Assertions.assertThrows(
+ CatalogException.class, () -> store.storeCatalog(EXCLUDED_CATALOG, descriptor));
+
+ Assertions.assertTrue(exception.getMessage().contains(EXCLUDED_CATALOG));
+ Assertions.assertTrue(
+ exception
+ .getMessage()
+ .contains(GravitinoCatalogStoreFactoryOptions.GRAVITINO_EXCLUDED_CATALOGS.key()));
+ verify(gravitinoCatalogStore, never()).storeCatalog(anyString(), any());
+ verify(memoryCatalogStore, never()).storeCatalog(anyString(), any());
+ }
+
+ @Test
+ void testExcludedCatalog_listCatalogs_hidesGravitinoCatalogWithExcludedName() {
+ GravitinoSessionCatalogStore store = storeExcluding(EXCLUDED_CATALOG);
+ when(memoryCatalogStore.listCatalogs()).thenReturn(ImmutableSet.of("hive"));
+ when(gravitinoCatalogStore.listCatalogs())
+ .thenReturn(ImmutableSet.of(EXCLUDED_CATALOG, "gravitino-hive"));
+
+ Assertions.assertEquals(ImmutableSet.of("hive", "gravitino-hive"), store.listCatalogs());
+
+ when(memoryCatalogStore.listCatalogs()).thenReturn(ImmutableSet.of("hive", EXCLUDED_CATALOG));
+ Assertions.assertEquals(
+ ImmutableSet.of("hive", EXCLUDED_CATALOG, "gravitino-hive"), store.listCatalogs());
+ }
+
+ @Test
+ void testExcludedCatalog_otherCatalogNamesKeepExistingBehavior() {
+ GravitinoSessionCatalogStore store = storeExcluding(EXCLUDED_CATALOG);
+ CatalogDescriptor gravitinoDescriptor = descriptorWithType(GRAVITINO_CATALOG_TYPE);
+ when(memoryCatalogStore.contains("gravitino-hive")).thenReturn(false);
+ when(memoryCatalogStore.getCatalog("gravitino-hive")).thenReturn(Optional.empty());
+ when(gravitinoCatalogStore.contains("gravitino-hive")).thenReturn(true);
+ when(gravitinoCatalogStore.getCatalog("gravitino-hive"))
+ .thenReturn(Optional.of(gravitinoDescriptor));
+
+ Assertions.assertTrue(store.contains("gravitino-hive"));
+ Assertions.assertEquals(Optional.of(gravitinoDescriptor), store.getCatalog("gravitino-hive"));
+ store.storeCatalog("gravitino-hive", gravitinoDescriptor);
+ store.removeCatalog("gravitino-hive", false);
+
+ verify(gravitinoCatalogStore).storeCatalog("gravitino-hive", gravitinoDescriptor);
+ verify(gravitinoCatalogStore).removeCatalog("gravitino-hive", false);
+ }
+
+ @Test
+ void testExcludedCatalog_namesAreCaseSensitive() {
+ GravitinoSessionCatalogStore store = storeExcluding(EXCLUDED_CATALOG);
+ String otherCase = EXCLUDED_CATALOG.toUpperCase(Locale.ROOT);
+ when(memoryCatalogStore.contains(otherCase)).thenReturn(false);
+ when(gravitinoCatalogStore.contains(otherCase)).thenReturn(true);
+
+ Assertions.assertTrue(store.contains(otherCase));
+ }
+
// -------------------------------------------------------------------------
// helpers
// -------------------------------------------------------------------------
+ private GravitinoSessionCatalogStore storeExcluding(String... catalogNames) {
+ return new GravitinoSessionCatalogStore(
+ gravitinoCatalogStore, memoryCatalogStore, ImmutableSet.copyOf(catalogNames));
+ }
+
private static CatalogDescriptor descriptorWithType(String type) {
Configuration config = new Configuration();
config.setString(CommonCatalogOptions.CATALOG_TYPE.key(), type);
diff --git a/flink-connector/flink-common/src/test/java/org/apache/gravitino/flink/connector/store/TestGravitinoSessionCatalogStoreWithCatalogManager.java b/flink-connector/flink-common/src/test/java/org/apache/gravitino/flink/connector/store/TestGravitinoSessionCatalogStoreWithCatalogManager.java
new file mode 100644
index 0000000000..b086bd388f
--- /dev/null
+++ b/flink-connector/flink-common/src/test/java/org/apache/gravitino/flink/connector/store/TestGravitinoSessionCatalogStoreWithCatalogManager.java
@@ -0,0 +1,291 @@
+/*
+ * 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.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyBoolean;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.atLeastOnce;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import com.google.common.collect.ImmutableSet;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Optional;
+import java.util.ServiceLoader;
+import java.util.Set;
+import org.apache.flink.configuration.Configuration;
+import org.apache.flink.table.api.EnvironmentSettings;
+import org.apache.flink.table.api.TableEnvironment;
+import org.apache.flink.table.catalog.CatalogDescriptor;
+import org.apache.flink.table.catalog.CatalogManager;
+import org.apache.flink.table.catalog.CommonCatalogOptions;
+import org.apache.flink.table.catalog.GenericInMemoryCatalogStore;
+import org.apache.flink.table.factories.CatalogFactory;
+import org.apache.flink.table.factories.Factory;
+import org.apache.flink.types.Row;
+import org.apache.flink.util.CloseableIterator;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Assumptions;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+/**
+ * Verifies {@link GravitinoSessionCatalogStore} through a real Flink {@link TableEnvironment} and
+ * {@link CatalogManager}, which call the catalog store in version-specific orders. The
+ * Gravitino-backed store is mocked; this test is compiled into every supported Flink minor.
+ */
+public class TestGravitinoSessionCatalogStoreWithCatalogManager {
+
+ private static final String EXCLUDED_CATALOG = "paimon_catalog";
+ private static final String GRAVITINO_ONLY_CATALOG = "gravitino_only_catalog";
+ private static final String GRAVITINO_PAIMON = "gravitino-paimon";
+ private static final String CREATE_EXCLUDED_CATALOG =
+ "CREATE CATALOG " + EXCLUDED_CATALOG + " WITH ('type'='generic_in_memory')";
+
+ private GravitinoCatalogStore gravitinoCatalogStore;
+
+ @BeforeEach
+ void setUp() {
+ gravitinoCatalogStore = mock(GravitinoCatalogStore.class);
+ for (String catalogName : Arrays.asList(EXCLUDED_CATALOG, GRAVITINO_ONLY_CATALOG)) {
+ when(gravitinoCatalogStore.contains(catalogName)).thenReturn(true);
+ when(gravitinoCatalogStore.getCatalog(catalogName))
+ .thenReturn(Optional.of(inMemoryDescriptor(catalogName)));
+ }
+ when(gravitinoCatalogStore.listCatalogs())
+ .thenReturn(ImmutableSet.of(EXCLUDED_CATALOG, GRAVITINO_ONLY_CATALOG));
+ }
+
+ /** Without exclusion, a same-named session catalog is rejected (the behavior in #14756). */
+ @Test
+ void testCreateSessionCatalogWithGravitinoCatalogName_withoutExclusion_fails() {
+ TableEnvironment tableEnv = tableEnv(ImmutableSet.of());
+
+ Throwable exception =
+ Assertions.assertThrows(Exception.class, () -> execute(tableEnv, CREATE_EXCLUDED_CATALOG));
+
+ Assertions.assertTrue(
+ allMessages(exception).contains("already exists"), allMessages(exception));
+ verify(gravitinoCatalogStore, never()).storeCatalog(any(), any());
+ }
+
+ @Test
+ void testExcludedCatalog_fullLifecycle_neverTouchesGravitinoCatalog() {
+ TableEnvironment tableEnv = tableEnv(ImmutableSet.of(EXCLUDED_CATALOG));
+
+ // The Gravitino catalog with the excluded name is not visible in this session.
+ Assertions.assertFalse(listCatalogs(tableEnv).contains(EXCLUDED_CATALOG));
+ Assertions.assertTrue(listCatalogs(tableEnv).contains(GRAVITINO_ONLY_CATALOG));
+ Assertions.assertThrows(
+ Exception.class, () -> execute(tableEnv, "USE CATALOG " + EXCLUDED_CATALOG));
+
+ execute(tableEnv, CREATE_EXCLUDED_CATALOG);
+ Assertions.assertTrue(listCatalogs(tableEnv).contains(EXCLUDED_CATALOG));
+
+ // Flink's duplicate-name semantics are kept for the session catalog.
+ Throwable duplicate =
+ Assertions.assertThrows(Exception.class, () -> execute(tableEnv, CREATE_EXCLUDED_CATALOG));
+ Assertions.assertTrue(
+ allMessages(duplicate).contains("already exists"), allMessages(duplicate));
+
+ execute(tableEnv, "USE CATALOG " + EXCLUDED_CATALOG);
+ execute(tableEnv, "CREATE DATABASE session_db");
+ Assertions.assertTrue(collect(tableEnv, "SHOW DATABASES").contains("session_db"));
+ execute(tableEnv, "USE CATALOG default_catalog");
+
+ execute(tableEnv, "DROP CATALOG " + EXCLUDED_CATALOG);
+ Assertions.assertFalse(listCatalogs(tableEnv).contains(EXCLUDED_CATALOG));
+ Assertions.assertThrows(
+ Exception.class, () -> execute(tableEnv, "USE CATALOG " + EXCLUDED_CATALOG));
+
+ // A new session catalog can reuse the name after it was dropped.
+ execute(tableEnv, CREATE_EXCLUDED_CATALOG);
+ Assertions.assertTrue(listCatalogs(tableEnv).contains(EXCLUDED_CATALOG));
+
+ verifyGravitinoCatalogNeverTouched(EXCLUDED_CATALOG);
+ }
+
+ @Test
+ void testExcludedCatalog_dropWithoutSessionCatalog_neverDropsGravitinoCatalog() {
+ TableEnvironment tableEnv = tableEnv(ImmutableSet.of(EXCLUDED_CATALOG));
+
+ Throwable exception =
+ Assertions.assertThrows(
+ Exception.class, () -> execute(tableEnv, "DROP CATALOG " + EXCLUDED_CATALOG));
+ Assertions.assertTrue(
+ allMessages(exception).contains("does not exist"), allMessages(exception));
+ execute(tableEnv, "DROP CATALOG IF EXISTS " + EXCLUDED_CATALOG);
+
+ verifyGravitinoCatalogNeverTouched(EXCLUDED_CATALOG);
+ }
+
+ @Test
+ void testExcludedCatalog_otherGravitinoCatalogsKeepExistingBehavior() {
+ TableEnvironment tableEnv = tableEnv(ImmutableSet.of(EXCLUDED_CATALOG));
+ execute(tableEnv, CREATE_EXCLUDED_CATALOG);
+
+ execute(tableEnv, "USE CATALOG " + GRAVITINO_ONLY_CATALOG);
+ execute(tableEnv, "USE CATALOG default_catalog");
+ execute(tableEnv, "DROP CATALOG " + GRAVITINO_ONLY_CATALOG);
+
+ verify(gravitinoCatalogStore, atLeastOnce()).getCatalog(GRAVITINO_ONLY_CATALOG);
+ verify(gravitinoCatalogStore).removeCatalog(eq(GRAVITINO_ONLY_CATALOG), anyBoolean());
+ verifyGravitinoCatalogNeverTouched(EXCLUDED_CATALOG);
+ }
+
+ /**
+ * Creating a Gravitino-managed catalog type under an excluded name must fail before Flink
+ * instantiates and registers the catalog. Otherwise the registered catalog would resolve the
+ * excluded Gravitino catalog with the same name. Runs where the {@code gravitino-paimon} factory
+ * is registered, i.e. in the Flink-minor modules.
+ */
+ @Test
+ void testExcludedCatalog_gravitinoManagedType_isRejectedBeforeRegistration() {
+ Assumptions.assumeTrue(
+ isCatalogFactoryRegistered(GRAVITINO_PAIMON),
+ "The gravitino-paimon catalog factory is not registered in this module");
+ Configuration sessionConfiguration = new Configuration();
+ sessionConfiguration.setString(
+ "table.catalog-store.gravitino.gravitino.excludedCatalogs", EXCLUDED_CATALOG);
+ TableEnvironment tableEnv = tableEnv(ImmutableSet.of(EXCLUDED_CATALOG), sessionConfiguration);
+
+ Throwable exception =
+ Assertions.assertThrows(
+ Exception.class,
+ () ->
+ execute(
+ tableEnv,
+ "CREATE CATALOG "
+ + EXCLUDED_CATALOG
+ + " WITH ('type'='"
+ + GRAVITINO_PAIMON
+ + "', 'catalog-backend'='filesystem', 'warehouse'='/tmp/unused')"));
+
+ Assertions.assertTrue(
+ allMessages(exception).contains("gravitino.excludedCatalogs"), allMessages(exception));
+ Assertions.assertFalse(listCatalogs(tableEnv).contains(EXCLUDED_CATALOG));
+ Assertions.assertFalse(tableEnv.getCatalog(EXCLUDED_CATALOG).isPresent());
+ Assertions.assertThrows(
+ Exception.class, () -> execute(tableEnv, "USE CATALOG " + EXCLUDED_CATALOG));
+ verifyGravitinoCatalogNeverTouched(EXCLUDED_CATALOG);
+ }
+
+ /** {@code CREATE CATALOG IF NOT EXISTS} and {@code ALTER CATALOG} are available since 1.20. */
+ @Test
+ void testExcludedCatalog_createIfNotExistsAndAlter_onlyAffectSessionCatalog() {
+ Assumptions.assumeTrue(
+ Arrays.stream(CatalogManager.class.getMethods())
+ .anyMatch(method -> method.getName().equals("alterCatalog")),
+ "CREATE CATALOG IF NOT EXISTS and ALTER CATALOG require Flink 1.20 or later");
+ TableEnvironment tableEnv = tableEnv(ImmutableSet.of(EXCLUDED_CATALOG));
+
+ // The Gravitino catalog is hidden, so IF NOT EXISTS creates the session catalog.
+ execute(
+ tableEnv,
+ "CREATE CATALOG IF NOT EXISTS " + EXCLUDED_CATALOG + " WITH ('type'='generic_in_memory')");
+ Assertions.assertTrue(listCatalogs(tableEnv).contains(EXCLUDED_CATALOG));
+ execute(
+ tableEnv,
+ "CREATE CATALOG IF NOT EXISTS " + EXCLUDED_CATALOG + " WITH ('type'='generic_in_memory')");
+
+ execute(
+ tableEnv, "ALTER CATALOG " + EXCLUDED_CATALOG + " SET ('default-database'='session_db')");
+
+ Assertions.assertTrue(listCatalogs(tableEnv).contains(EXCLUDED_CATALOG));
+ Assertions.assertTrue(
+ collect(tableEnv, "DESCRIBE CATALOG " + EXCLUDED_CATALOG).contains("generic_in_memory"));
+ verifyGravitinoCatalogNeverTouched(EXCLUDED_CATALOG);
+ }
+
+ // -------------------------------------------------------------------------
+ // helpers
+ // -------------------------------------------------------------------------
+
+ private TableEnvironment tableEnv(Set<String> excludedCatalogs) {
+ return tableEnv(excludedCatalogs, new Configuration());
+ }
+
+ private TableEnvironment tableEnv(
+ Set<String> excludedCatalogs, Configuration sessionConfiguration) {
+ GenericInMemoryCatalogStore memoryCatalogStore = new GenericInMemoryCatalogStore();
+ memoryCatalogStore.open();
+ GravitinoSessionCatalogStore store =
+ new GravitinoSessionCatalogStore(
+ gravitinoCatalogStore, memoryCatalogStore, excludedCatalogs);
+ return TableEnvironment.create(
+ EnvironmentSettings.newInstance()
+ .withConfiguration(sessionConfiguration)
+ .inBatchMode()
+ .withCatalogStore(store)
+ .build());
+ }
+
+ private static boolean isCatalogFactoryRegistered(String identifier) {
+ for (Factory factory : ServiceLoader.load(Factory.class)) {
+ if (factory instanceof CatalogFactory && identifier.equals(factory.factoryIdentifier())) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ private void verifyGravitinoCatalogNeverTouched(String catalogName) {
+ verify(gravitinoCatalogStore, never()).contains(catalogName);
+ verify(gravitinoCatalogStore, never()).getCatalog(catalogName);
+ verify(gravitinoCatalogStore, never()).storeCatalog(eq(catalogName), any());
+ verify(gravitinoCatalogStore, never()).removeCatalog(eq(catalogName), anyBoolean());
+ }
+
+ private static CatalogDescriptor inMemoryDescriptor(String catalogName) {
+ Configuration configuration = new Configuration();
+ configuration.set(CommonCatalogOptions.CATALOG_TYPE, "generic_in_memory");
+ return CatalogDescriptor.of(catalogName, configuration);
+ }
+
+ private static List<String> listCatalogs(TableEnvironment tableEnv) {
+ return Arrays.asList(tableEnv.listCatalogs());
+ }
+
+ private static void execute(TableEnvironment tableEnv, String sql) {
+ collect(tableEnv, sql);
+ }
+
+ private static String collect(TableEnvironment tableEnv, String sql) {
+ List<String> rows = new ArrayList<>();
+ try (CloseableIterator<Row> iterator = tableEnv.executeSql(sql).collect()) {
+ iterator.forEachRemaining(row -> rows.add(row.toString()));
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ return String.join("\n", rows);
+ }
+
+ private static String allMessages(Throwable throwable) {
+ StringBuilder messages = new StringBuilder();
+ for (Throwable current = throwable; current != null; current = current.getCause()) {
+ messages.append(current.getMessage()).append('\n');
+ }
+ return messages.toString();
+ }
+}
diff --git a/flink-connector/flink-common/src/test/java/org/apache/gravitino/flink/connector/utils/TestFactoryUtils.java b/flink-connector/flink-common/src/test/java/org/apache/gravitino/flink/connector/utils/TestFactoryUtils.java
index 3bcea53ddb..fdc18d6d35 100644
--- a/flink-connector/flink-common/src/test/java/org/apache/gravitino/flink/connector/utils/TestFactoryUtils.java
+++ b/flink-connector/flink-common/src/test/java/org/apache/gravitino/flink/connector/utils/TestFactoryUtils.java
@@ -19,14 +19,59 @@
package org.apache.gravitino.flink.connector.utils;
import com.google.common.collect.ImmutableList;
+import java.util.HashMap;
import java.util.Iterator;
import java.util.ServiceConfigurationError;
+import org.apache.flink.configuration.Configuration;
+import org.apache.flink.table.catalog.exceptions.CatalogException;
+import org.apache.flink.table.factories.CatalogFactory;
import org.apache.flink.table.factories.Factory;
+import org.apache.flink.table.factories.FactoryUtil;
+import org.apache.gravitino.flink.connector.store.GravitinoCatalogStoreFactoryOptions;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
public class TestFactoryUtils {
+ private static final String EXCLUDED_CATALOGS_KEY =
+ "table.catalog-store.gravitino.gravitino.excludedCatalogs";
+
+ @Test
+ void testCreateCatalogFactoryHelper_excludedCatalogName_isRejected() {
+ Configuration sessionConfiguration = new Configuration();
+ sessionConfiguration.setString(EXCLUDED_CATALOGS_KEY, "other_catalog; paimon_catalog");
+
+ CatalogException exception =
+ Assertions.assertThrows(
+ CatalogException.class,
+ () ->
+ FactoryUtils.createCatalogFactoryHelper(
+ new FakeExternalCatalogFactory(),
+ catalogContext("paimon_catalog", sessionConfiguration)));
+
+ Assertions.assertTrue(exception.getMessage().contains("paimon_catalog"));
+ Assertions.assertTrue(exception.getMessage().contains(FakeExternalCatalogFactory.IDENTIFIER));
+ Assertions.assertTrue(
+ exception
+ .getMessage()
+ .contains(GravitinoCatalogStoreFactoryOptions.GRAVITINO_EXCLUDED_CATALOGS.key()));
+ }
+
+ @Test
+ void testCreateCatalogFactoryHelper_notExcludedCatalogName_isAllowed() {
+ Configuration sessionConfiguration = new Configuration();
+ sessionConfiguration.setString(EXCLUDED_CATALOGS_KEY, "paimon_catalog");
+
+ Assertions.assertNotNull(
+ FactoryUtils.createCatalogFactoryHelper(
+ new FakeExternalCatalogFactory(),
+ catalogContext("PAIMON_CATALOG", sessionConfiguration)));
+ Assertions.assertNotNull(
+ FactoryUtils.createCatalogFactoryHelper(
+ new FakeExternalCatalogFactory(),
+ catalogContext("paimon_catalog", new Configuration())));
+ }
+
@Test
void testBuiltInTypesAreGravitinoManaged() {
Assertions.assertTrue(FactoryUtils.isGravitinoManagedCatalogType("gravitino-hive"));
@@ -114,4 +159,13 @@ public class TestFactoryUtils {
};
Assertions.assertFalse(FactoryUtils.isProvidedByCatalogFactory(factories, "any"));
}
+
+ private static CatalogFactory.Context catalogContext(
+ String catalogName, Configuration sessionConfiguration) {
+ return new FactoryUtil.DefaultCatalogContext(
+ catalogName,
+ new HashMap<>(),
+ sessionConfiguration,
+ TestFactoryUtils.class.getClassLoader());
+ }
}
diff --git a/flink-connector/v1.19/flink/src/test/java/org/apache/gravitino/flink/connector/integration/test/session/FlinkSupportsSessionCatalogIT119.java b/flink-connector/v1.19/flink/src/test/java/org/apache/gravitino/flink/connector/integration/test/session/FlinkSupportsSessionCatalogIT119.java
new file mode 100644
index 0000000000..449a202480
--- /dev/null
+++ b/flink-connector/v1.19/flink/src/test/java/org/apache/gravitino/flink/connector/integration/test/session/FlinkSupportsSessionCatalogIT119.java
@@ -0,0 +1,22 @@
+/*
+ * 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.integration.test.session;
+
+/** Runs {@link FlinkSupportsSessionCatalogIT} against Flink 1.19. */
+public class FlinkSupportsSessionCatalogIT119 extends FlinkSupportsSessionCatalogIT {}
diff --git a/flink-connector/v1.20/flink/src/test/java/org/apache/gravitino/flink/connector/integration/test/session/FlinkSupportsSessionCatalogIT120.java b/flink-connector/v1.20/flink/src/test/java/org/apache/gravitino/flink/connector/integration/test/session/FlinkSupportsSessionCatalogIT120.java
new file mode 100644
index 0000000000..619a7e5e49
--- /dev/null
+++ b/flink-connector/v1.20/flink/src/test/java/org/apache/gravitino/flink/connector/integration/test/session/FlinkSupportsSessionCatalogIT120.java
@@ -0,0 +1,22 @@
+/*
+ * 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.integration.test.session;
+
+/** Runs {@link FlinkSupportsSessionCatalogIT} against Flink 1.20. */
+public class FlinkSupportsSessionCatalogIT120 extends FlinkSupportsSessionCatalogIT {}