This is an automated email from the ASF dual-hosted git repository.

fhueske pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/flink.git


The following commit(s) were added to refs/heads/master by this push:
     new 43a902ad128 [FLINK-40166][table] SQL query parsing fails if current 
catalog unreachable (#28775)
43a902ad128 is described below

commit 43a902ad128824d0e4f696ee96cd8c29e5416e2e
Author: Dale Lane <[email protected]>
AuthorDate: Thu Jul 23 10:31:03 2026 +0100

    [FLINK-40166][table] SQL query parsing fails if current catalog unreachable 
(#28775)
    
    If the current catalog is unreachable, any SQL query fails to
    parse - even queries that make fully-qualified accesses to
    catalogs that are reachable.
    
    This is because we make a call to databaseExists in the current
    catalog as part of parsing the statement.
    
    This commit wraps this in a try..catch so it doesn't block the
    remainder of the parsing.
    
    Signed-off-by: Dale Lane <[email protected]>
---
 .../apache/flink/table/catalog/CatalogManager.java | 16 ++++-
 .../flink/table/catalog/CatalogManagerTest.java    | 37 +++++++++++
 .../planner/catalog/BrokenCurrentCatalogTest.java  | 71 ++++++++++++++++++++++
 3 files changed, 123 insertions(+), 1 deletion(-)

diff --git 
a/flink-table/flink-table-api-java/src/main/java/org/apache/flink/table/catalog/CatalogManager.java
 
b/flink-table/flink-table-api-java/src/main/java/org/apache/flink/table/catalog/CatalogManager.java
index ca31e17ebf4..fa9db8cb50d 100644
--- 
a/flink-table/flink-table-api-java/src/main/java/org/apache/flink/table/catalog/CatalogManager.java
+++ 
b/flink-table/flink-table-api-java/src/main/java/org/apache/flink/table/catalog/CatalogManager.java
@@ -1114,7 +1114,21 @@ public final class CatalogManager implements 
CatalogRegistry, AutoCloseable {
     }
 
     private boolean permanentDatabaseExists(String catalogName, String 
databaseName) {
-        return getCatalog(catalogName).map(c -> 
c.databaseExists(databaseName)).orElse(false);
+        return getCatalog(catalogName)
+                .map(
+                        c -> {
+                            try {
+                                return c.databaseExists(databaseName);
+                            } catch (CatalogException e) {
+                                LOG.warn(
+                                        "Unable to check whether database '{}' 
exists in catalog '{}'.",
+                                        databaseName,
+                                        catalogName,
+                                        e);
+                                return false;
+                            }
+                        })
+                .orElse(false);
     }
 
     /**
diff --git 
a/flink-table/flink-table-api-java/src/test/java/org/apache/flink/table/catalog/CatalogManagerTest.java
 
b/flink-table/flink-table-api-java/src/test/java/org/apache/flink/table/catalog/CatalogManagerTest.java
index 907d03dfcf8..51774ffb6f6 100644
--- 
a/flink-table/flink-table-api-java/src/test/java/org/apache/flink/table/catalog/CatalogManagerTest.java
+++ 
b/flink-table/flink-table-api-java/src/test/java/org/apache/flink/table/catalog/CatalogManagerTest.java
@@ -245,6 +245,43 @@ class CatalogManagerTest {
         
assertThat(dropTemporaryEvent.identifier().getObjectName()).isEqualTo("table2");
     }
 
+    @Test
+    void testSchemaExistsSwallowsCatalogExceptionFromDatabaseExists() {
+        CatalogManager catalogManager =
+                CatalogManagerMocks.preparedCatalogManager()
+                        .defaultCatalog("broken", new 
UnreachableCatalog("broken"))
+                        .classLoader(CatalogManagerTest.class.getClassLoader())
+                        .config(new Configuration())
+                        .catalogStoreHolder(
+                                CatalogStoreHolder.newBuilder()
+                                        
.classloader(CatalogManagerTest.class.getClassLoader())
+                                        .catalogStore(new 
GenericInMemoryCatalogStore())
+                                        .config(new Configuration())
+                                        .build())
+                        .build();
+        assertThat(catalogManager.schemaExists("broken", "default")).isFalse();
+    }
+
+    /**
+     * A catalog whose {@link #databaseExists(String)} always fails, 
simulating a connectivity
+     * problem with an unreachable destination.
+     */
+    private static class UnreachableCatalog extends GenericInMemoryCatalog {
+        UnreachableCatalog(String name) {
+            super(name, "default");
+        }
+
+        @Override
+        public boolean databaseExists(String databaseName) {
+            throw new CatalogException(
+                    "Failed to connect to database '"
+                            + databaseName
+                            + "' of catalog '"
+                            + getName()
+                            + "'.");
+        }
+    }
+
     @Test
     public void testDropCurrentDatabase() throws Exception {
         CatalogManager catalogManager = createCatalogManager(null);
diff --git 
a/flink-table/flink-table-planner/src/test/java/org/apache/flink/table/planner/catalog/BrokenCurrentCatalogTest.java
 
b/flink-table/flink-table-planner/src/test/java/org/apache/flink/table/planner/catalog/BrokenCurrentCatalogTest.java
new file mode 100644
index 00000000000..8641f761b2d
--- /dev/null
+++ 
b/flink-table/flink-table-planner/src/test/java/org/apache/flink/table/planner/catalog/BrokenCurrentCatalogTest.java
@@ -0,0 +1,71 @@
+/*
+ * 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.flink.table.planner.catalog;
+
+import org.apache.flink.table.api.EnvironmentSettings;
+import org.apache.flink.table.api.Table;
+import org.apache.flink.table.api.TableEnvironment;
+import org.apache.flink.table.catalog.GenericInMemoryCatalog;
+import org.apache.flink.table.catalog.exceptions.CatalogException;
+
+import org.junit.jupiter.api.Test;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+/**
+ * Tests that a fully-qualified query against a healthy catalog can still be 
resolved even when the
+ * current catalog is unreachable.
+ */
+class BrokenCurrentCatalogTest {
+
+    @Test
+    void testFullyQualifiedQueryWhileCurrentCatalogIsBroken() throws Exception 
{
+        TableEnvironment tEnv =
+                TableEnvironment.create(
+                        
EnvironmentSettings.newInstance().inStreamingMode().build());
+
+        tEnv.registerCatalog("healthy", new GenericInMemoryCatalog("healthy", 
"default"));
+        tEnv.useCatalog("healthy");
+        tEnv.executeSql(
+                "CREATE VIEW `healthy`.`default`.`v` AS SELECT * FROM (VALUES 
(1), (2), (3)) AS t(id)");
+
+        tEnv.registerCatalog("broken", new UnreachableCatalog("broken"));
+        tEnv.useCatalog("broken");
+
+        Table table = tEnv.sqlQuery("SELECT * FROM `healthy`.`default`.`v`");
+
+        
assertThat(table.getResolvedSchema().getColumnNames()).containsExactly("id");
+    }
+
+    private static class UnreachableCatalog extends GenericInMemoryCatalog {
+        UnreachableCatalog(String name) {
+            super(name, "default");
+        }
+
+        @Override
+        public boolean databaseExists(String databaseName) {
+            throw new CatalogException(
+                    "Failed to connect to database '"
+                            + databaseName
+                            + "' of catalog '"
+                            + getName()
+                            + "'.");
+        }
+    }
+}

Reply via email to