World's most powerful open data catalog for building a high-performance, geo-distributed and federated metadata lake.
Java ai-catalogdata-catalogdatalakefederated-querylakehousemetadatametalakemodel-catalogopendatacatalogskycomputingstratosphere
[#14837] fix(spark): Reject stale JDBC catalog settings (#15006)
Shabbir Hussain98c65decb42d
diff --git a/docs/spark-connector/spark-catalog-jdbc.md b/docs/spark-connector/spark-catalog-jdbc.mdindex f8e489b06c..921058337e 100644--- a/docs/spark-connector/spark-catalog-jdbc.md+++ b/docs/spark-connector/spark-catalog-jdbc.md@@ -90,6 +90,24 @@ SELECT * FROM employee WHERE date(hire_date) = '2021-01-01';```+Connection option names after `spark.bypass.` are case-insensitive. If both `spark.bypass.URL`+and `jdbc-url` are configured, `jdbc-url` takes precedence. Earlier connector versions could+select the bypass value when the names differed in case. Check for conflicting settings before+upgrading. Explicit Spark catalog options take precedence over catalog properties, and vended+JDBC credentials take precedence over configured user names and passwords.++## Changes during a Spark session++Spark keeps a JDBC catalog's connection settings for the lifetime of the session. The connector+checks the effective URL, user, password, and catalog creation time when resolving a JDBC table,+before creating or altering a table, and when building a scan or write or accessing table indexes.+If the settings change or the catalog is recreated, restart the Spark session before retrying.++A DataFrame resolved before the change is checked when Spark builds its scan. A physical plan or+writer already built can continue using the original connection. Finish in-flight jobs before+rotating credentials or switching databases. The metadata check and the JDBC operation are separate+requests, so a concurrent catalog change can also occur between them.+## Catalog PropertiesGravitino spark connector will transform below property names which are defined in catalog properties to Spark JDBC connector configuration.diff --git a/spark-connector/spark-common/src/main/java/org/apache/gravitino/spark/connector/catalog/BaseCatalog.java b/spark-connector/spark-common/src/main/java/org/apache/gravitino/spark/connector/catalog/BaseCatalog.javaindex b903d8b2c5..88ac26ff35 100644--- a/spark-connector/spark-common/src/main/java/org/apache/gravitino/spark/connector/catalog/BaseCatalog.java+++ b/spark-connector/spark-common/src/main/java/org/apache/gravitino/spark/connector/catalog/BaseCatalog.java@@ -201,11 +201,11 @@ public abstract class BaseCatalog implements TableCatalog, SupportsNamespaces, Fpublic void initialize(String name, CaseInsensitiveStringMap options) {this.catalogName = name;this.identity = gravitinoCatalogManager.currentIdentity();- Catalog gravitinoCatalog = gravitinoCatalogManager.getGravitinoCatalogInfo(name);+ Catalog gravitinoCatalog = initialGravitinoCatalog(name);String provider = gravitinoCatalog.provider();Preconditions.checkArgument(StringUtils.isNotBlank(provider), name + " catalog provider is empty");- Map<String, String> catalogProperties = propsWithSecrets(gravitinoCatalog);+ Map<String, String> catalogProperties = initializationProperties(gravitinoCatalog);this.sparkCatalog = createAndInitSparkCatalog(name, options, catalogProperties);this.propertiesConverter = getPropertiesConverter();this.sparkTransformConverter = getSparkTransformConverter();@@ -213,6 +213,11 @@ public abstract class BaseCatalog implements TableCatalog, SupportsNamespaces, Fthis.sparkTableChangeConverter = getSparkTableChangeConverter(sparkTypeConverter);}+ /** Returns the catalog metadata used to initialize this Spark session's catalog. */+ protected Catalog initialGravitinoCatalog(String name) {+ return gravitinoCatalogManager.getGravitinoCatalogInfo(name);+ }+@Overridepublic String name() {return catalogName;@@ -234,6 +239,18 @@ public abstract class BaseCatalog implements TableCatalog, SupportsNamespaces, Freturn gravitinoCatalogManager.getGravitinoCatalogInfo(identity, catalogName);}+ /**+ * Loads the current catalog metadata, bypassing the catalog metadata cache.+ *+ * <p>Source catalogs that retain connection settings after initialization use this before an IO+ * operation to prevent an altered Gravitino catalog from silently accessing the old source.+ *+ * @return the current Gravitino catalog for this Spark catalog's name and identity+ */+ protected Catalog refreshGravitinoCatalog() {+ return gravitinoCatalogManager.refreshGravitinoCatalogInfo(identity, catalogName);+ }+@Overridepublic Identifier[] listTables(String[] namespace) throws NoSuchNamespaceException {String gravitinoNamespace = getDatabase(namespace);@@ -259,6 +276,7 @@ public abstract class BaseCatalog implements TableCatalog, SupportsNamespaces, FIdentifier ident, StructType schema, Transform[] transforms, Map<String, String> properties)throws TableAlreadyExistsException, NoSuchNamespaceException {try {+ validateBeforeTableMutation();org.apache.gravitino.rel.Table gravitinoTable =createGravitinoTable(ident, schema, transforms, properties);org.apache.spark.sql.connector.catalog.Table sparkTable = loadSparkTable(ident);@@ -383,6 +401,7 @@ public abstract class BaseCatalog implements TableCatalog, SupportsNamespaces, Freturn loadTable(ident);}try {+ validateBeforeTableMutation();Supplier<Column[]> columns =Suppliers.memoize(() -> {@@ -846,18 +865,9 @@ public abstract class BaseCatalog implements TableCatalog, SupportsNamespaces, F}}- private static Map<String, String> propsWithSecrets(Catalog catalog) {- Map<String, String> props =- new HashMap<>(catalog.properties() == null ? Collections.emptyMap() : catalog.properties());- try {- Map<String, String> secrets = catalog.supportsSecrets().getSecrets();- if (secrets != null) {- props.putAll(secrets);- }- } catch (UnsupportedOperationException | NotFoundException e) {- // Stubs may not implement SupportsSecrets; older servers lack /secrets.- LOG.debug("Skipping getSecrets while resolving Spark catalog properties: {}", e.toString());- }+ /** Returns the properties used to initialize the underlying Spark catalog. */+ protected Map<String, String> initializationProperties(Catalog catalog) {+ Map<String, String> props = propertiesWithSecrets(catalog);try {Credential[] credentials = catalog.supportsCredentials().getCredentials();props.putAll(CredentialInfos.nonExpiringCredentialInfo(credentials));@@ -874,6 +884,25 @@ public abstract class BaseCatalog implements TableCatalog, SupportsNamespaces, Freturn props;}+ /** Returns a mutable copy of the catalog properties with available secrets resolved. */+ protected static Map<String, String> propertiesWithSecrets(Catalog catalog) {+ Map<String, String> props =+ new HashMap<>(catalog.properties() == null ? Collections.emptyMap() : catalog.properties());+ try {+ Map<String, String> secrets = catalog.supportsSecrets().getSecrets();+ if (secrets != null) {+ props.putAll(secrets);+ }+ } catch (UnsupportedOperationException | NotFoundException e) {+ // Stubs may not implement SupportsSecrets; older servers lack /secrets.+ LOG.debug("Skipping getSecrets while resolving Spark catalog properties: {}", e.toString());+ }+ return props;+ }++ /** Checks whether the initialized Spark catalog can return the result of a table mutation. */+ protected void validateBeforeTableMutation() {}+@Overridepublic void invalidateTable(Identifier ident) {sparkCatalog.invalidateTable(ident);diff --git a/spark-connector/spark-common/src/main/java/org/apache/gravitino/spark/connector/catalog/GravitinoCatalogManager.java b/spark-connector/spark-common/src/main/java/org/apache/gravitino/spark/connector/catalog/GravitinoCatalogManager.javaindex af3c8ff3a2..9135d3897c 100644--- a/spark-connector/spark-common/src/main/java/org/apache/gravitino/spark/connector/catalog/GravitinoCatalogManager.java+++ b/spark-connector/spark-common/src/main/java/org/apache/gravitino/spark/connector/catalog/GravitinoCatalogManager.java@@ -247,6 +247,24 @@ public class GravitinoCatalogManager {return cached.catalog;}+ /**+ * Loads the current catalog metadata from Gravitino and replaces the cached value.+ *+ * <p>Connectors whose source clients keep connection settings after initialization use this+ * method to detect an unsafe catalog change before accessing the source.+ *+ * @param identity the identity used to load the catalog+ * @param name the catalog name+ * @return the freshly loaded catalog+ */+ Catalog refreshGravitinoCatalogInfo(GravitinoIdentity identity, String name) {+ Preconditions.checkState(!isClosed, "GravitinoCatalogManager is already closed");+ GravitinoClient client = getClient(identity);+ Catalog catalog = loadCatalog(client, identity, name);+ gravitinoCatalogs.put(cacheKey(identity, name), new CachedCatalog(client, catalog));+ return catalog;+ }+/*** Loads the relational catalogs visible to the application identity. This runs at driver init,* before any Spark session exists, so it never consults session state.@@ -328,7 +346,7 @@ public class GravitinoCatalogManager {Catalog catalog = client.loadCatalog(catalogName);Preconditions.checkArgument(Catalog.Type.RELATIONAL.equals(catalog.type()), "Only support relational catalog");- LOG.info("Load catalog {} from Gravitino successfully for {}.", catalogName, identity);+ LOG.debug("Load catalog {} from Gravitino successfully for {}.", catalogName, identity);return catalog;}diff --git a/spark-connector/spark-common/src/main/java/org/apache/gravitino/spark/connector/jdbc/GravitinoJdbcCatalog.java b/spark-connector/spark-common/src/main/java/org/apache/gravitino/spark/connector/jdbc/GravitinoJdbcCatalog.javaindex f345824d31..d6939e8ce5 100644--- a/spark-connector/spark-common/src/main/java/org/apache/gravitino/spark/connector/jdbc/GravitinoJdbcCatalog.java+++ b/spark-connector/spark-common/src/main/java/org/apache/gravitino/spark/connector/jdbc/GravitinoJdbcCatalog.java@@ -23,10 +23,12 @@ import com.google.common.annotations.VisibleForTesting;import com.google.common.base.Preconditions;import com.google.common.collect.Maps;import java.sql.SQLException;+import java.time.Instant;import java.util.Arrays;import java.util.Collections;import java.util.HashMap;import java.util.IdentityHashMap;+import java.util.List;import java.util.Map;import java.util.Set;import java.util.stream.Collectors;@@ -35,6 +37,7 @@ import javax.annotation.Nullable;import org.apache.commons.collections4.MapUtils;import org.apache.gravitino.Catalog;import org.apache.gravitino.credential.Credential;+import org.apache.gravitino.credential.CredentialInfos;import org.apache.gravitino.credential.JdbcCredential;import org.apache.gravitino.spark.connector.PropertiesConverter;import org.apache.gravitino.spark.connector.SparkTransformConverter;@@ -64,18 +67,31 @@ public class GravitinoJdbcCatalog extends BaseCatalog {private static final String PREFER_TIMESTAMP_NTZ = "preferTimestampNTZ";+ private static final List<String> CONNECTION_KEYS =+ Arrays.asList(+ JdbcPropertiesConstants.SPARK_JDBC_URL,+ JdbcPropertiesConstants.SPARK_JDBC_USER,+ JdbcPropertiesConstants.SPARK_JDBC_PASSWORD);+private boolean useTimestampNtz;// The Spark JDBC options the catalog was initialized with, used to read a table's schema again.private Map<String, String> jdbcOptions = Collections.emptyMap();+ // The Spark catalog options supplied at initialization, retained when comparing refreshed+ // Gravitino catalog properties because they take precedence over catalog properties.+ private Map<String, String> sparkCatalogOptions = Collections.emptyMap();++ // The connection settings that initialized Spark's JDBC catalog. Spark cannot safely change+ // these settings on an already initialized JDBCTableCatalog.+ private Map<String, String> jdbcConnectionOptions = Collections.emptyMap();++ @Nullable private Instant catalogCreateTime;+@Overrideprotected TableCatalog createAndInitSparkCatalog(String name, CaseInsensitiveStringMap options, Map<String, String> properties) {- JDBCTableCatalog jdbcTableCatalog = new JDBCTableCatalog();- Map<String, String> all =- getPropertiesConverter().toSparkCatalogProperties(options, properties);- applyJdbcCredential(gravitinoCatalog(), all);+ Map<String, String> all = jdbcOptions(gravitinoCatalog(), options, properties);useTimestampNtz = false;if (supportsPreferTimestampNtz()) {String value = preferTimestampNtz(options, properties);@@ -93,8 +109,17 @@ public class GravitinoJdbcCatalog extends BaseCatalog {// for catalogs that do not support the option, including when Spark's session timestamp type// defaults to NTZ.setPreferTimestampNtz(all, useTimestampNtz);+ return initializeJdbcTableCatalog(name, options, all);+ }++ /** Initializes the physical catalog and records the exact connection settings it receives. */+ protected final TableCatalog initializeJdbcTableCatalog(+ String name, CaseInsensitiveStringMap options, Map<String, String> all) {+ JDBCTableCatalog jdbcTableCatalog = new JDBCTableCatalog();jdbcTableCatalog.initialize(name, new CaseInsensitiveStringMap(all));+ sparkCatalogOptions = new HashMap<>(options.asCaseSensitiveMap());jdbcOptions = new HashMap<>(all);+ jdbcConnectionOptions = jdbcConnectionOptions(all);return jdbcTableCatalog;}@@ -108,6 +133,14 @@ public class GravitinoJdbcCatalog extends BaseCatalog {*/@Overrideprotected Table loadSparkTable(Identifier ident) {+ verifyJdbcConnectionUnchanged();+ return loadJdbcTable(ident);+ }++ /**+ * Loads the physical table after connection validation, preserving provider-specific diagnostics.+ */+ protected Table loadJdbcTable(Identifier ident) {try {return sparkCatalog.loadTable(ident);} catch (NoSuchTableException e) {@@ -124,6 +157,62 @@ public class GravitinoJdbcCatalog extends BaseCatalog {}}+ @Override+ protected Catalog initialGravitinoCatalog(String name) {+ // A new session must not inherit the previous session's cached connection settings.+ return refreshGravitinoCatalog();+ }++ @Override+ protected Map<String, String> initializationProperties(Catalog catalog) {+ // Bind the creation time to the same metadata snapshot that supplied the JDBC URL.+ catalogCreateTime = catalogCreateTime(catalog);+ return propertiesWithSecrets(catalog);+ }++ @Override+ protected void validateBeforeTableMutation() {+ verifyJdbcConnectionUnchanged();+ }++ private void verifyJdbcConnectionUnchanged() {+ Catalog currentCatalog = refreshGravitinoCatalog();+ Map<String, String> currentOptions =+ jdbcOptions(+ currentCatalog,+ new CaseInsensitiveStringMap(sparkCatalogOptions),+ propertiesWithSecrets(currentCatalog));+ boolean connectionChanged =+ !jdbcConnectionOptions.equals(jdbcConnectionOptions(currentOptions));+ Instant currentCreateTime = catalogCreateTime(currentCatalog);+ boolean catalogRecreated =+ catalogCreateTime != null+ && currentCreateTime != null+ && !catalogCreateTime.equals(currentCreateTime);+ if (connectionChanged || catalogRecreated) {+ throw new IllegalStateException(+ String.format(+ "JDBC catalog %s changed after this Spark session initialized it. "+ + "Restart the Spark session before accessing the catalog.",+ name()));+ }+ }++ private static Map<String, String> jdbcConnectionOptions(Map<String, String> options) {+ Map<String, String> connectionOptions = new HashMap<>();+ for (String key : CONNECTION_KEYS) {+ if (options.containsKey(key)) {+ connectionOptions.put(key, options.get(key));+ }+ }+ return connectionOptions;+ }++ @Nullable+ private static Instant catalogCreateTime(Catalog catalog) {+ return catalog.auditInfo() == null ? null : catalog.auditInfo().createTime();+ }+/*** Reads a table's schema the way Spark's JDBC catalog does and returns the source's error.*@@ -178,22 +267,38 @@ public class GravitinoJdbcCatalog extends BaseCatalog {return result;}- /**- * Overwrites the Spark JDBC user and password in {@code sparkProperties} with credentials- * obtained from the server via credential vending, if available.- *- * @param catalog the Gravitino catalog client- * @param sparkProperties the mutable Spark properties map to update- */- @VisibleForTesting- static void applyJdbcCredential(Catalog catalog, Map<String, String> sparkProperties) {+ /** Resolves the effective Spark JDBC options for initialization and subsequent validation. */+ protected Map<String, String> jdbcOptions(+ Catalog catalog, CaseInsensitiveStringMap options, Map<String, String> properties) {Credential[] credentials;try {credentials = catalog.supportsCredentials().getCredentials();} catch (UnsupportedOperationException e) {- LOG.debug("Catalog {} does not support credential vending, skipping.", catalog.name(), e);- return;+ LOG.debug("Catalog {} does not support credential vending", catalog.name(), e);+ credentials = new Credential[0];+ }+ Map<String, String> enriched = new HashMap<>(properties);+ enriched.putAll(CredentialInfos.nonExpiringCredentialInfo(credentials));+ // Spark treats option names case-insensitively. Fold JDBC bypass aliases before the+ // converter applies catalog properties, session options, and finally vended credentials.+ for (String key : CONNECTION_KEYS) {+ String canonical = PropertiesConverter.SPARK_PROPERTY_PREFIX + key;+ for (String property : properties.keySet()) {+ if (property.startsWith(PropertiesConverter.SPARK_PROPERTY_PREFIX)+ && property.equalsIgnoreCase(canonical)+ && !property.equals(canonical)) {+ enriched.putIfAbsent(canonical, enriched.remove(property));+ }+ }}+ Map<String, String> result =+ getPropertiesConverter().toSparkCatalogProperties(options, enriched);+ applyJdbcCredential(credentials, result);+ return result;+ }++ @VisibleForTesting+ static void applyJdbcCredential(Credential[] credentials, Map<String, String> sparkProperties) {for (Credential credential : credentials) {if (credential instanceof JdbcCredential) {JdbcCredential jdbcCredential = (JdbcCredential) credential;@@ -218,10 +323,10 @@ public class GravitinoJdbcCatalog extends BaseCatalog {identifier,gravitinoTable,(JDBCTable) sparkTable,- (JDBCTableCatalog) sparkCatalog,propertiesConverter,sparkTransformConverter,- sparkTypeConverter);+ sparkTypeConverter,+ this::verifyJdbcConnectionUnchanged);}@Overridediff --git a/spark-connector/spark-common/src/main/java/org/apache/gravitino/spark/connector/jdbc/SparkJdbcTable.java b/spark-connector/spark-common/src/main/java/org/apache/gravitino/spark/connector/jdbc/SparkJdbcTable.javaindex baaeaa5378..f7e5726cef 100644--- a/spark-connector/spark-common/src/main/java/org/apache/gravitino/spark/connector/jdbc/SparkJdbcTable.java+++ b/spark-connector/spark-common/src/main/java/org/apache/gravitino/spark/connector/jdbc/SparkJdbcTable.java@@ -30,6 +30,8 @@ import org.apache.gravitino.spark.connector.SparkTransformConverter;import org.apache.gravitino.spark.connector.SparkTypeConverter;import org.apache.gravitino.spark.connector.utils.GravitinoTableInfoHelper;import org.apache.spark.sql.connector.catalog.Identifier;+import org.apache.spark.sql.connector.catalog.index.TableIndex;+import org.apache.spark.sql.connector.expressions.NamedReference;import org.apache.spark.sql.connector.write.LogicalWriteInfo;import org.apache.spark.sql.connector.write.WriteBuilder;import org.apache.spark.sql.execution.datasources.v2.jdbc.JDBCScanBuilder;@@ -50,6 +52,8 @@ public class SparkJdbcTable extends SparkJdbcTableBase {private final StructType sparkSchema;private final SparkJdbcPushDownPolicy pushDownPolicy;+ private final Runnable validateConnection;+public SparkJdbcTable(Identifier identifier,Table gravitinoTable,@@ -58,7 +62,26 @@ public class SparkJdbcTable extends SparkJdbcTableBase {PropertiesConverter propertiesConverter,SparkTransformConverter sparkTransformConverter,SparkTypeConverter sparkTypeConverter) {+ this(+ identifier,+ gravitinoTable,+ jdbcTable,+ propertiesConverter,+ sparkTransformConverter,+ sparkTypeConverter,+ () -> {});+ }++ SparkJdbcTable(+ Identifier identifier,+ Table gravitinoTable,+ JDBCTable jdbcTable,+ PropertiesConverter propertiesConverter,+ SparkTransformConverter sparkTransformConverter,+ SparkTypeConverter sparkTypeConverter,+ Runnable validateConnection) {super(identifier, jdbcTable);+ this.validateConnection = validateConnection;this.gravitinoTable = gravitinoTable;this.gravitinoTableInfoHelper =new GravitinoTableInfoHelper(@@ -86,6 +109,7 @@ public class SparkJdbcTable extends SparkJdbcTableBase {*/@Overridepublic JDBCScanBuilder newScanBuilder(CaseInsensitiveStringMap options) {+ validateConnection.run();// Schema and aggregate typing are fixed by the catalog options, not by individual reads.Map<String, String> scanOptions = new HashMap<>(options.asCaseSensitiveMap());scanOptions.keySet().removeIf("preferTimestampNTZ"::equalsIgnoreCase);@@ -101,6 +125,7 @@ public class SparkJdbcTable extends SparkJdbcTableBase {*/@Overridepublic WriteBuilder newWriteBuilder(LogicalWriteInfo info) {+ validateConnection.run();if (jdbcOptions().url().toLowerCase(Locale.ROOT).startsWith("jdbc:postgresql:")) {for (Column column : gravitinoTable.columns()) {if (column.dataType() instanceof Types.UUIDType@@ -117,6 +142,38 @@ public class SparkJdbcTable extends SparkJdbcTableBase {return super.newWriteBuilder(info);}+ /** {@inheritDoc} */+ @Override+ public void createIndex(+ String indexName,+ NamedReference[] columns,+ Map<NamedReference, Map<String, String>> columnProperties,+ Map<String, String> properties) {+ validateConnection.run();+ super.createIndex(indexName, columns, columnProperties, properties);+ }++ /** {@inheritDoc} */+ @Override+ public boolean indexExists(String indexName) {+ validateConnection.run();+ return super.indexExists(indexName);+ }++ /** {@inheritDoc} */+ @Override+ public void dropIndex(String indexName) {+ validateConnection.run();+ super.dropIndex(indexName);+ }++ /** {@inheritDoc} */+ @Override+ public TableIndex[] listIndexes() {+ validateConnection.run();+ return super.listIndexes();+ }+@Overridepublic String name() {return gravitinoTableInfoHelper.name();diff --git a/spark-connector/spark-common/src/test/java/org/apache/gravitino/spark/connector/catalog/TestGravitinoCatalogManager.java b/spark-connector/spark-common/src/test/java/org/apache/gravitino/spark/connector/catalog/TestGravitinoCatalogManager.javaindex e8207f338d..b097cd5469 100644--- a/spark-connector/spark-common/src/test/java/org/apache/gravitino/spark/connector/catalog/TestGravitinoCatalogManager.java+++ b/spark-connector/spark-common/src/test/java/org/apache/gravitino/spark/connector/catalog/TestGravitinoCatalogManager.java@@ -247,6 +247,19 @@ public class TestGravitinoCatalogManager {assertEquals(1, clientFactory.clientCount());}+ @Test+ void testRefreshCatalogBypassesCacheAndReplacesCachedValue() {+ GravitinoCatalogManager manager = createManager(new SparkConf(false));++ Catalog cached = manager.getGravitinoCatalogInfo(CATALOG_NAME);+ Catalog refreshed =+ manager.refreshGravitinoCatalogInfo(manager.currentIdentity(), CATALOG_NAME);++ assertNotSame(cached, refreshed);+ assertSame(refreshed, manager.getGravitinoCatalogInfo(CATALOG_NAME));+ assertEquals(2, clientFactory.loadCount());+ }+@Testvoid testIcebergRestUriIsCachedAfterSuccessfulDiscovery() {AtomicInteger discoveryCalls = new AtomicInteger();diff --git a/spark-connector/spark-common/src/test/java/org/apache/gravitino/spark/connector/jdbc/TestGravitinoJdbcCatalog.java b/spark-connector/spark-common/src/test/java/org/apache/gravitino/spark/connector/jdbc/TestGravitinoJdbcCatalog.javaindex 5c42577e83..969231bd7f 100644--- a/spark-connector/spark-common/src/test/java/org/apache/gravitino/spark/connector/jdbc/TestGravitinoJdbcCatalog.java+++ b/spark-connector/spark-common/src/test/java/org/apache/gravitino/spark/connector/jdbc/TestGravitinoJdbcCatalog.java@@ -24,6 +24,7 @@ import static org.mockito.Mockito.mockStatic;import static org.mockito.Mockito.verify;import static org.mockito.Mockito.when;+import java.time.Instant;import java.util.Collections;import java.util.HashMap;import java.util.Map;@@ -37,6 +38,7 @@ import org.apache.gravitino.credential.SupportsCredentials;import org.apache.gravitino.rel.types.Types;import org.apache.gravitino.spark.connector.SparkTypeConverter;import org.apache.gravitino.spark.connector.catalog.GravitinoCatalogManager;+import org.apache.spark.sql.connector.catalog.Identifier;import org.apache.spark.sql.connector.catalog.TableCatalog;import org.apache.spark.sql.execution.datasources.jdbc.JDBCOptions;import org.apache.spark.sql.internal.SQLConf;@@ -54,63 +56,6 @@ import org.mockito.MockedStatic;/** Unit tests for JDBC catalog credentials and timestamp option handling. */public class TestGravitinoJdbcCatalog {- /**- * Minimal Catalog stub — returns nothing, used to verify the instanceof check for- * SupportsCredentials.- */- private static class PlainCatalogStub implements Catalog {- @Override- public String name() {- return "stub";- }-- @Override- public Type type() {- return Type.RELATIONAL;- }-- @Override- public String provider() {- return "jdbc-mysql";- }-- @Override- public String comment() {- return null;- }-- @Override- public Map<String, String> properties() {- return Collections.emptyMap();- }-- @Override- public Audit auditInfo() {- return null;- }- }-- /** Catalog that also implements SupportsCredentials — simulates the upgraded server. */- private static class CredentialCatalogStub extends PlainCatalogStub- implements SupportsCredentials {-- private final Credential[] credentials;-- CredentialCatalogStub(Credential... credentials) {- this.credentials = credentials;- }-- @Override- public Credential[] getCredentials() {- return credentials;- }-- @Override- public SupportsCredentials supportsCredentials() {- return this;- }- }-@ParameterizedTest@ValueSource(strings = {@@ -199,6 +144,50 @@ public class TestGravitinoJdbcCatalog {}}+ @Test+ void testRejectsConnectionSettingChangeInOpenSession() {+ try (MockedStatic<GravitinoCatalogManager> global = mockStatic(GravitinoCatalogManager.class)) {+ global.when(GravitinoCatalogManager::get).thenReturn(mock(GravitinoCatalogManager.class));+ RefreshingCatalog catalog = new RefreshingCatalog();+ catalog.initialCatalog = jdbcCatalog("jdbc:mysql://localhost/first", null);+ catalog.refreshedCatalog = jdbcCatalog("jdbc:mysql://localhost/second", null);+ catalog.createAndInitSparkCatalog(+ "test",+ new CaseInsensitiveStringMap(Collections.emptyMap()),+ catalog.initializationProperties(catalog.initialCatalog));++ IllegalStateException exception =+ Assertions.assertThrows(+ IllegalStateException.class,+ () -> catalog.loadSparkTable(Identifier.of(new String[] {"db"}, "table")));++ Assertions.assertTrue(exception.getMessage().contains("Restart the Spark session"));+ }+ }++ @Test+ void testRejectsRecreatedCatalogInOpenSession() {+ try (MockedStatic<GravitinoCatalogManager> global = mockStatic(GravitinoCatalogManager.class)) {+ global.when(GravitinoCatalogManager::get).thenReturn(mock(GravitinoCatalogManager.class));+ RefreshingCatalog catalog = new RefreshingCatalog();+ catalog.initialCatalog =+ jdbcCatalog("jdbc:mysql://localhost/db", Instant.parse("2026-01-01T00:00:00Z"));+ catalog.refreshedCatalog =+ jdbcCatalog("jdbc:mysql://localhost/db", Instant.parse("2026-01-02T00:00:00Z"));+ catalog.createAndInitSparkCatalog(+ "test",+ new CaseInsensitiveStringMap(Collections.emptyMap()),+ catalog.initializationProperties(catalog.initialCatalog));++ IllegalStateException exception =+ Assertions.assertThrows(+ IllegalStateException.class,+ () -> catalog.loadSparkTable(Identifier.of(new String[] {"db"}, "table")));++ Assertions.assertTrue(exception.getMessage().contains("Restart the Spark session"));+ }+ }+@ParameterizedTest@CsvSource({"preferTimestampNTZ, true, '', true",@@ -350,9 +339,8 @@ public class TestGravitinoJdbcCatalog {props.put(JdbcPropertiesConstants.SPARK_JDBC_USER, "prop-user");props.put(JdbcPropertiesConstants.SPARK_JDBC_PASSWORD, "prop-password");- Catalog catalog =- new CredentialCatalogStub(new JdbcCredential("vended-user", "vended-password"));- GravitinoJdbcCatalog.applyJdbcCredential(catalog, props);+ GravitinoJdbcCatalog.applyJdbcCredential(+ new Credential[] {new JdbcCredential("vended-user", "vended-password")}, props);Assertions.assertEquals("vended-user", props.get(JdbcPropertiesConstants.SPARK_JDBC_USER));Assertions.assertEquals(@@ -365,20 +353,7 @@ public class TestGravitinoJdbcCatalog {props.put(JdbcPropertiesConstants.SPARK_JDBC_USER, "prop-user");props.put(JdbcPropertiesConstants.SPARK_JDBC_PASSWORD, "prop-password");- GravitinoJdbcCatalog.applyJdbcCredential(new CredentialCatalogStub(), props);-- Assertions.assertEquals("prop-user", props.get(JdbcPropertiesConstants.SPARK_JDBC_USER));- Assertions.assertEquals(- "prop-password", props.get(JdbcPropertiesConstants.SPARK_JDBC_PASSWORD));- }-- @Test- void testFallsBackToPropertiesWhenCatalogDoesNotSupportCredentials() {- Map<String, String> props = new HashMap<>();- props.put(JdbcPropertiesConstants.SPARK_JDBC_USER, "prop-user");- props.put(JdbcPropertiesConstants.SPARK_JDBC_PASSWORD, "prop-password");-- GravitinoJdbcCatalog.applyJdbcCredential(new PlainCatalogStub(), props);+ GravitinoJdbcCatalog.applyJdbcCredential(new Credential[0], props);Assertions.assertEquals("prop-user", props.get(JdbcPropertiesConstants.SPARK_JDBC_USER));Assertions.assertEquals(@@ -416,6 +391,42 @@ public class TestGravitinoJdbcCatalog {return catalog;}+ private static Catalog jdbcCatalog(String url, Instant createTime) {+ Catalog catalog = mock(Catalog.class);+ when(catalog.properties())+ .thenReturn(+ Map.of(+ "jdbc-url", url,+ "jdbc-user", "user",+ "jdbc-password", "password",+ "jdbc-driver", "com.mysql.cj.jdbc.Driver"));+ when(catalog.supportsSecrets()).thenThrow(new UnsupportedOperationException());+ SupportsCredentials credentials = mock(SupportsCredentials.class);+ when(credentials.getCredentials()).thenReturn(new Credential[0]);+ when(catalog.supportsCredentials()).thenReturn(credentials);+ if (createTime != null) {+ Audit audit = mock(Audit.class);+ when(audit.createTime()).thenReturn(createTime);+ when(catalog.auditInfo()).thenReturn(audit);+ }+ return catalog;+ }++ private static class RefreshingCatalog extends GravitinoJdbcCatalog {+ private Catalog initialCatalog;+ private Catalog refreshedCatalog;++ @Override+ protected Catalog gravitinoCatalog() {+ return initialCatalog;+ }++ @Override+ protected Catalog refreshGravitinoCatalog() {+ return refreshedCatalog;+ }+ }+private static JDBCOptions initialize(GravitinoJdbcCatalog catalog, Map<String, String> options, Map<String, String> extra)throws IllegalAccessException {diff --git a/spark-connector/spark-common/src/test/java/org/apache/gravitino/spark/connector/jdbc/TestGravitinoJdbcCatalogSourceError.java b/spark-connector/spark-common/src/test/java/org/apache/gravitino/spark/connector/jdbc/TestGravitinoJdbcCatalogSourceError.javaindex 6ca9b5272c..0af4433afd 100644--- a/spark-connector/spark-common/src/test/java/org/apache/gravitino/spark/connector/jdbc/TestGravitinoJdbcCatalogSourceError.java+++ b/spark-connector/spark-common/src/test/java/org/apache/gravitino/spark/connector/jdbc/TestGravitinoJdbcCatalogSourceError.java@@ -96,8 +96,13 @@ public class TestGravitinoJdbcCatalogSourceError {SupportsCredentials credentials = mock(SupportsCredentials.class);when(credentials.getCredentials()).thenReturn(new Credential[] {new JdbcCredential(NO_RIGHTS, PASSWORD)});+ Map<String, String> properties = new HashMap<>();+ properties.put("jdbc-url", URL);+ properties.put("jdbc-driver", "org.h2.Driver");Catalog source = mock(Catalog.class);when(source.provider()).thenReturn("jdbc-h2");+ when(source.properties()).thenReturn(properties);+ when(source.supportsSecrets()).thenThrow(new UnsupportedOperationException());when(source.supportsCredentials()).thenReturn(credentials);GravitinoJdbcCatalog catalog =new GravitinoJdbcCatalog() {@@ -105,11 +110,13 @@ public class TestGravitinoJdbcCatalogSourceError {protected Catalog gravitinoCatalog() {return source;}++ @Override+ protected Catalog refreshGravitinoCatalog() {+ return source;+ }};- Map<String, String> properties = new HashMap<>();- properties.put("jdbc-url", URL);- properties.put("jdbc-driver", "org.h2.Driver");TableCatalog physical =catalog.createAndInitSparkCatalog("test", new CaseInsensitiveStringMap(new HashMap<>()), properties);diff --git a/spark-connector/spark-common/src/test/java/org/apache/gravitino/spark/connector/jdbc/TestJdbcCatalogRefresh.java b/spark-connector/spark-common/src/test/java/org/apache/gravitino/spark/connector/jdbc/TestJdbcCatalogRefresh.javanew file mode 100644index 0000000000..1a8817cdac--- /dev/null+++ b/spark-connector/spark-common/src/test/java/org/apache/gravitino/spark/connector/jdbc/TestJdbcCatalogRefresh.java@@ -0,0 +1,251 @@+/*+ * 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.spark.connector.jdbc;++import static org.junit.jupiter.api.Assertions.assertEquals;+import static org.junit.jupiter.api.Assertions.assertThrows;+import static org.junit.jupiter.api.Assertions.assertTrue;+import static org.mockito.ArgumentMatchers.any;+import static org.mockito.ArgumentMatchers.anySet;+import static org.mockito.Mockito.clearInvocations;+import static org.mockito.Mockito.doReturn;+import static org.mockito.Mockito.mock;+import static org.mockito.Mockito.verify;+import static org.mockito.Mockito.verifyNoInteractions;+import static org.mockito.Mockito.when;++import java.sql.Connection;+import java.sql.DriverManager;+import java.sql.Statement;+import java.util.Collections;+import java.util.HashMap;+import java.util.Map;+import org.apache.gravitino.Catalog;+import org.apache.gravitino.NameIdentifier;+import org.apache.gravitino.client.GravitinoClient;+import org.apache.gravitino.credential.Credential;+import org.apache.gravitino.credential.SupportsCredentials;+import org.apache.gravitino.rel.Column;+import org.apache.gravitino.rel.Table;+import org.apache.gravitino.rel.TableCatalog;+import org.apache.gravitino.rel.types.Types;+import org.apache.gravitino.spark.connector.catalog.GravitinoCatalogManager;+import org.apache.spark.SparkConf;+import org.apache.spark.sql.Dataset;+import org.apache.spark.sql.Row;+import org.apache.spark.sql.SparkSession;+import org.apache.spark.sql.connector.catalog.Identifier;+import org.apache.spark.sql.connector.catalog.TableChange;+import org.apache.spark.sql.connector.expressions.Transform;+import org.apache.spark.sql.types.DataTypes;+import org.apache.spark.sql.types.StructType;+import org.apache.spark.sql.util.CaseInsensitiveStringMap;+import org.junit.jupiter.api.Test;++class TestJdbcCatalogRefresh {+ private static final String URL = "jdbc:h2:mem:jdbc_refresh;DB_CLOSE_DELAY=-1";++ private static Map<String, String> properties(String url) {+ return Map.of(+ "jdbc-url", url, "jdbc-user", "SA", "jdbc-password", "", "jdbc-driver", "org.h2.Driver");+ }++ private static Catalog source(TableCatalog tables) {+ Catalog source = mock(Catalog.class);+ when(source.type()).thenReturn(Catalog.Type.RELATIONAL);+ when(source.provider()).thenReturn("jdbc-h2");+ when(source.properties()).thenReturn(properties(URL));+ when(source.supportsSecrets()).thenThrow(new UnsupportedOperationException());+ when(source.supportsCredentials()).thenThrow(new UnsupportedOperationException());+ when(source.asTableCatalog()).thenReturn(tables);+ return source;+ }++ @Test+ void rejectsStaleCreateAndAlterBeforeMutation() throws Exception {+ TableCatalog tables = mock(TableCatalog.class);+ Catalog source = source(tables);+ GravitinoClient client = mock(GravitinoClient.class);+ when(client.loadCatalog("jdbc_refresh")).thenReturn(source);+ GravitinoCatalogManager manager =+ GravitinoCatalogManager.create(new SparkConf(false), "user", identity -> client);+ try {+ GravitinoJdbcCatalog catalog = new GravitinoJdbcCatalog();+ catalog.initialize("jdbc_refresh", new CaseInsensitiveStringMap(Collections.emptyMap()));+ when(source.properties()).thenReturn(properties("jdbc:h2:mem:changed"));+ assertThrows(+ IllegalStateException.class,+ () ->+ catalog.createTable(+ Identifier.of(new String[] {"PUBLIC"}, "T"),+ new StructType().add("ID", DataTypes.IntegerType),+ new Transform[0],+ Collections.emptyMap()));+ assertThrows(+ IllegalStateException.class,+ () ->+ catalog.alterTable(+ Identifier.of(new String[] {"PUBLIC"}, "T"),+ TableChange.setProperty("key", "value")));+ verifyNoInteractions(tables);+ } finally {+ manager.close();+ }+ }++ @Test+ void rejectsRetainedDatasetAndWriteBuilder() throws Exception {+ try (Connection connection = DriverManager.getConnection(URL, "SA", "");+ Statement statement = connection.createStatement()) {+ statement.execute("CREATE TABLE IF NOT EXISTS PUBLIC.T (ID INT)");+ statement.execute("DELETE FROM PUBLIC.T");+ statement.execute("INSERT INTO PUBLIC.T VALUES (42)");+ }+ TableCatalog tables = mock(TableCatalog.class);+ Table metadata = mock(Table.class);+ when(metadata.name()).thenReturn("T");+ when(metadata.columns()).thenReturn(new Column[] {Column.of("ID", Types.IntegerType.get())});+ when(tables.loadTable(any(NameIdentifier.class), anySet())).thenReturn(metadata);+ Catalog source = source(tables);+ GravitinoClient client = mock(GravitinoClient.class);+ when(client.loadCatalog("jdbc_refresh")).thenReturn(source);+ GravitinoCatalogManager manager =+ GravitinoCatalogManager.create(new SparkConf(false), "user", identity -> client);+ try (SparkSession spark =+ SparkSession.builder()+ .master("local[1]")+ .appName("jdbc_refresh")+ .config("spark.ui.enabled", "false")+ .config("spark.sql.catalog.jdbc_refresh", GravitinoJdbcCatalog.class.getName())+ .getOrCreate()) {+ Dataset<Row> old = spark.table("jdbc_refresh.PUBLIC.T");+ old.schema();+ assertEquals(42, spark.table("jdbc_refresh.PUBLIC.T").collectAsList().get(0).getInt(0));+ GravitinoJdbcCatalog catalog =+ (GravitinoJdbcCatalog) spark.sessionState().catalogManager().catalog("jdbc_refresh");+ SparkJdbcTable retained =+ (SparkJdbcTable) catalog.loadTable(Identifier.of(new String[] {"PUBLIC"}, "T"));+ when(source.properties()).thenReturn(properties("jdbc:h2:mem:changed"));+ assertThrows(IllegalStateException.class, () -> retained.indexExists("idx"));+ assertThrows(+ IllegalStateException.class, () -> retained.createIndex("idx", null, null, null));+ assertThrows(IllegalStateException.class, () -> retained.dropIndex("idx"));+ assertThrows(IllegalStateException.class, retained::listIndexes);+ assertThrows(IllegalStateException.class, () -> spark.table("jdbc_refresh.PUBLIC.T"));+ assertTrue(+ assertThrows(IllegalStateException.class, old::collectAsList)+ .getMessage()+ .contains("Restart the Spark session"));+ assertTrue(+ assertThrows(IllegalStateException.class, () -> retained.newWriteBuilder(null))+ .getMessage()+ .contains("Restart the Spark session"));+ } finally {+ manager.close();+ }+ }++ @Test+ void newSessionUsesCurrentSettingsEvenWhenTheManagerHasAnOlderCatalog() throws Exception {+ Catalog previous = source(mock(TableCatalog.class));+ when(previous.properties()).thenReturn(properties("jdbc:h2:mem:previous"));+ Catalog current = source(mock(TableCatalog.class));+ Map<String, String> currentProperties = new HashMap<>(properties(URL));+ currentProperties.put("spark.bypass.URL", "jdbc:h2:mem:shadow");+ when(current.properties()).thenReturn(currentProperties);+ GravitinoClient client = mock(GravitinoClient.class);+ when(client.loadCatalog("jdbc_refresh")).thenReturn(previous, current);+ GravitinoCatalogManager manager =+ GravitinoCatalogManager.create(new SparkConf(false), "user", identity -> client);+ try (SparkSession spark =+ SparkSession.builder()+ .master("local[1]")+ .appName("fresh-jdbc-catalog")+ .config("spark.ui.enabled", "false")+ .config("spark.sql.catalog.jdbc_refresh", GravitinoJdbcCatalog.class.getName())+ .getOrCreate();+ Connection connection = DriverManager.getConnection(URL, "SA", "");+ Statement statement = connection.createStatement()) {+ statement.execute("CREATE TABLE IF NOT EXISTS PUBLIC.FRESH (ID INT)");+ manager.getGravitinoCatalogInfo("jdbc_refresh");+ GravitinoJdbcCatalog catalog =+ (GravitinoJdbcCatalog) spark.sessionState().catalogManager().catalog("jdbc_refresh");+ assertEquals(+ "ID",+ catalog+ .loadSparkTable(Identifier.of(new String[] {"PUBLIC"}, "FRESH"))+ .columns()[0]+ .name());+ } finally {+ manager.close();+ }+ }++ @Test+ void rejectsRotationOfMixedCaseBypassPassword() {+ Catalog source = source(mock(TableCatalog.class));+ Map<String, String> properties = new HashMap<>(properties(URL));+ properties.remove("jdbc-password");+ properties.put("spark.bypass.PaSsWoRd", "first");+ when(source.properties()).thenReturn(properties);+ GravitinoClient client = mock(GravitinoClient.class);+ when(client.loadCatalog("jdbc_refresh")).thenReturn(source);+ GravitinoCatalogManager manager =+ GravitinoCatalogManager.create(new SparkConf(false), "user", identity -> client);+ try {+ GravitinoJdbcCatalog catalog = new GravitinoJdbcCatalog();+ catalog.initialize("jdbc_refresh", new CaseInsensitiveStringMap(Collections.emptyMap()));+ properties.put("spark.bypass.PaSsWoRd", "second");+ IllegalStateException error =+ assertThrows(+ IllegalStateException.class,+ () -> catalog.loadSparkTable(Identifier.of(new String[] {"PUBLIC"}, "T")));+ assertTrue(error.getMessage().contains("Restart the Spark session"));+ } finally {+ manager.close();+ }+ }++ @Test+ void fetchesCredentialsOncePerSnapshot() throws Exception {+ TableCatalog tables = mock(TableCatalog.class);+ Catalog source = source(tables);+ SupportsCredentials credentials = mock(SupportsCredentials.class);+ doReturn(credentials).when(source).supportsCredentials();+ when(credentials.getCredentials()).thenReturn(new Credential[0]);+ GravitinoClient client = mock(GravitinoClient.class);+ when(client.loadCatalog("jdbc_refresh")).thenReturn(source);+ GravitinoCatalogManager manager =+ GravitinoCatalogManager.create(new SparkConf(false), "user", identity -> client);+ try {+ GravitinoJdbcCatalog catalog = new GravitinoJdbcCatalog();+ catalog.initialize("jdbc_refresh", new CaseInsensitiveStringMap(Collections.emptyMap()));+ verify(credentials).getCredentials();+ clearInvocations(credentials);+ when(source.properties()).thenReturn(properties("jdbc:h2:mem:changed"));+ assertThrows(+ IllegalStateException.class,+ () -> catalog.loadSparkTable(Identifier.of(new String[] {"PUBLIC"}, "T")));+ verify(credentials).getCredentials();+ } finally {+ manager.close();+ }+ }+}diff --git a/spark-connector/v3.5/spark/src/main/java/org/apache/gravitino/spark/connector/jdbc/doris/GravitinoDorisCatalogSpark35.java b/spark-connector/v3.5/spark/src/main/java/org/apache/gravitino/spark/connector/jdbc/doris/GravitinoDorisCatalogSpark35.javaindex 3ccdc826ab..25f967baac 100644--- a/spark-connector/v3.5/spark/src/main/java/org/apache/gravitino/spark/connector/jdbc/doris/GravitinoDorisCatalogSpark35.java+++ b/spark-connector/v3.5/spark/src/main/java/org/apache/gravitino/spark/connector/jdbc/doris/GravitinoDorisCatalogSpark35.java@@ -38,7 +38,6 @@ import org.apache.spark.sql.connector.catalog.TableChange;import org.apache.spark.sql.connector.catalog.TableWritePrivilege;import org.apache.spark.sql.connector.expressions.Transform;import org.apache.spark.sql.execution.datasources.v2.jdbc.JDBCTable;-import org.apache.spark.sql.execution.datasources.v2.jdbc.JDBCTableCatalog;import org.apache.spark.sql.types.StructType;import org.apache.spark.sql.util.CaseInsensitiveStringMap;@@ -48,17 +47,22 @@ public class GravitinoDorisCatalogSpark35 extends GravitinoJdbcCatalogSpark35 {@Overrideprotected TableCatalog createAndInitSparkCatalog(String name, CaseInsensitiveStringMap options, Map<String, String> properties) {+ return initializeJdbcTableCatalog(+ name, options, jdbcOptions(gravitinoCatalog(), options, properties));+ }++ @Override+ protected Map<String, String> jdbcOptions(+ Catalog catalog, CaseInsensitiveStringMap options, Map<String, String> properties) {Map<String, String> all =DorisPropertiesConverter35.getInstance().toSparkCatalogProperties(options, properties);- JdbcCredential credential = requiredJdbcCredential(gravitinoCatalog());+ JdbcCredential credential = requiredJdbcCredential(catalog);requireProperty(all, "url");requireProperty(all, "driver");all.put("user", credential.jdbcUser());all.put("password", credential.jdbcPassword());- JDBCTableCatalog jdbcTableCatalog = new JDBCTableCatalog();- jdbcTableCatalog.initialize(name, new CaseInsensitiveStringMap(all));- return jdbcTableCatalog;+ return all;}@Override@@ -100,10 +104,10 @@ public class GravitinoDorisCatalogSpark35 extends GravitinoJdbcCatalogSpark35 {/** Loads the physical JDBC schema with redacted failure diagnostics. */@Override- protected org.apache.spark.sql.connector.catalog.Table loadSparkTable(Identifier ident) {+ protected org.apache.spark.sql.connector.catalog.Table loadJdbcTable(Identifier ident) {try {- return super.loadSparkTable(ident);- } catch (RuntimeException e) {+ return sparkCatalog.loadTable(ident);+ } catch (Exception e) {throw DorisPhysicalSchemaValidator35.physicalAccessFailure(ident, "Spark JDBC schema load", e);}diff --git a/spark-connector/v3.5/spark/src/test/java/org/apache/gravitino/spark/connector/jdbc/doris/TestGravitinoDorisCatalogSpark35.java b/spark-connector/v3.5/spark/src/test/java/org/apache/gravitino/spark/connector/jdbc/doris/TestGravitinoDorisCatalogSpark35.javaindex f5e8c4a05c..aecd2f955c 100644--- a/spark-connector/v3.5/spark/src/test/java/org/apache/gravitino/spark/connector/jdbc/doris/TestGravitinoDorisCatalogSpark35.java+++ b/spark-connector/v3.5/spark/src/test/java/org/apache/gravitino/spark/connector/jdbc/doris/TestGravitinoDorisCatalogSpark35.java@@ -161,6 +161,34 @@ public class TestGravitinoDorisCatalogSpark35 {}}+ @Test+ void testChangedCredentialsRejectLoadBeforeOpeningConnection() throws Exception {+ Driver driver = mock(Driver.class);+ DorisTestDriver.setDelegate(driver);+ TableCatalog tables = mock(TableCatalog.class);+ when(tables.loadTable(NameIdentifier.of("db", "table"), Set.of(Privilege.Name.SELECT_TABLE)))+ .thenReturn(mock(Table.class));+ GravitinoDorisCatalogSpark35 catalog =+ initializeCatalog(+ tables,+ Map.of(+ "jdbc-url",+ "jdbc:doris-validator-test://host/db",+ "jdbc-driver",+ DorisTestDriver.class.getName()),+ Map.of());+ SupportsCredentials credentials = client.loadCatalog("doris").supportsCredentials();+ when(credentials.getCredentials())+ .thenReturn(new Credential[] {new JdbcCredential("vended-user", "rotated")});++ IllegalStateException failure =+ assertThrows(+ IllegalStateException.class,+ () -> catalog.loadTable(Identifier.of(new String[] {"db"}, "table")));+ assertTrue(failure.getMessage().contains("Restart the Spark session"));+ verifyNoInteractions(driver);+ }+@Testvoid testPhysicalLoadOmitsDriverCauseAndSuppressedDetails() throws Exception {String jdbcUrl = "jdbc:doris-validator-test://host/db?password=test-url-secret";