fhueske commented on code in PR #28775:
URL: https://github.com/apache/flink/pull/28775#discussion_r3630749078
##########
flink-table/flink-table-api-java/src/main/java/org/apache/flink/table/catalog/CatalogManager.java:
##########
@@ -1114,7 +1114,21 @@ private boolean temporaryDatabaseExists(String
catalogName, String databaseName)
}
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.debug(
Review Comment:
```suggestion
LOG.warn(
```
I would raise the log level of this error.
The log is the only way to figure out what's wrong when a query would try to
access the failing database (besides debugging).
##########
flink-table/flink-table-planner/src/test/java/org/apache/flink/table/planner/catalog/BrokenCurrentCatalogTest.java:
##########
@@ -0,0 +1,62 @@
+/*
+ * 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.configuration.Configuration;
+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.CatalogDescriptor;
+import org.apache.flink.table.planner.factories.UnreachableTestCatalogFactory;
+
+import org.junit.jupiter.api.Test;
+
+import static
org.apache.flink.table.catalog.GenericInMemoryCatalogFactoryOptions.IDENTIFIER;
+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());
+
+ Configuration healthyOptions = new Configuration();
+ healthyOptions.setString("type", IDENTIFIER);
+ healthyOptions.setString("default-database", "default");
+ tEnv.createCatalog("healthy", CatalogDescriptor.of("healthy",
healthyOptions));
+ tEnv.useCatalog("healthy");
+ tEnv.executeSql(
+ "CREATE VIEW `healthy`.`default`.`v` AS SELECT * FROM (VALUES
(1), (2), (3)) AS t(id)");
+
+ Configuration brokenOptions = new Configuration();
+ brokenOptions.setString("type",
UnreachableTestCatalogFactory.IDENTIFIER);
+ tEnv.createCatalog("broken", CatalogDescriptor.of("broken",
brokenOptions));
Review Comment:
you can use `tEnv.registerCatalog(catalogName, catalog);`
then we don't need a factory class and the `META-INF/services` change.
the catalog class can be defined inside of the test class.
##########
flink-table/flink-table-planner/src/test/java/org/apache/flink/table/planner/factories/UnreachableTestCatalogFactory.java:
##########
@@ -0,0 +1,76 @@
+/*
+ * 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.factories;
+
+import org.apache.flink.configuration.ConfigOption;
+import org.apache.flink.table.catalog.Catalog;
+import org.apache.flink.table.catalog.GenericInMemoryCatalog;
+import org.apache.flink.table.catalog.exceptions.CatalogException;
+import org.apache.flink.table.factories.CatalogFactory;
+import org.apache.flink.table.factories.FactoryUtil;
+
+import java.util.Collections;
+import java.util.Set;
+
+/**
+ * Test catalog factory that creates a catalog whose {@link
Catalog#databaseExists(String)} always
+ * fails, simulating a catalog that cannot be reached (e.g. a connectivity
failure).
+ */
+public class UnreachableTestCatalogFactory implements CatalogFactory {
+
+ public static final String IDENTIFIER = "test-unreachable-catalog";
+
+ @Override
+ public String factoryIdentifier() {
+ return IDENTIFIER;
+ }
+
+ @Override
+ public Set<ConfigOption<?>> requiredOptions() {
+ return Collections.emptySet();
+ }
+
+ @Override
+ public Set<ConfigOption<?>> optionalOptions() {
+ return Collections.emptySet();
+ }
+
+ @Override
+ public Catalog createCatalog(Context context) {
+ FactoryUtil.createCatalogFactoryHelper(this, context).validate();
+ return new UnreachableCatalog(context.getName());
+ }
+
+ /** A catalog whose {@link #databaseExists(String)} always fails. */
+ public static class UnreachableCatalog extends GenericInMemoryCatalog {
+ public UnreachableCatalog(String name) {
+ super(name, "default");
+ }
+
+ @Override
+ public boolean databaseExists(String databaseName) {
+ throw new CatalogException(
+ "Failed to connect to Kafka cluster for database '"
Review Comment:
```suggestion
"Failed to connect to database '"
```
Keep the exception generic.
##########
flink-table/flink-table-planner/src/test/java/org/apache/flink/table/planner/catalog/BrokenCurrentCatalogTest.java:
##########
@@ -0,0 +1,62 @@
+/*
+ * 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.configuration.Configuration;
+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.CatalogDescriptor;
+import org.apache.flink.table.planner.factories.UnreachableTestCatalogFactory;
+
+import org.junit.jupiter.api.Test;
+
+import static
org.apache.flink.table.catalog.GenericInMemoryCatalogFactoryOptions.IDENTIFIER;
+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());
+
+ Configuration healthyOptions = new Configuration();
+ healthyOptions.setString("type", IDENTIFIER);
+ healthyOptions.setString("default-database", "default");
+ tEnv.createCatalog("healthy", CatalogDescriptor.of("healthy",
healthyOptions));
+ tEnv.useCatalog("healthy");
+ tEnv.executeSql(
+ "CREATE VIEW `healthy`.`default`.`v` AS SELECT * FROM (VALUES
(1), (2), (3)) AS t(id)");
+
+ Configuration brokenOptions = new Configuration();
+ brokenOptions.setString("type",
UnreachableTestCatalogFactory.IDENTIFIER);
+ tEnv.createCatalog("broken", CatalogDescriptor.of("broken",
brokenOptions));
Review Comment:
Instead of moving the catalog inside of this class, you could also make it a
public class in the `flink-table-api-java` module and reuse it here.
`flink-table-planner` depends on the test artifact of the other module.
Up to you if you prefer two small inline classes or one public test class.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]