twalthr commented on code in PR #23427:
URL: https://github.com/apache/flink/pull/23427#discussion_r1327410411


##########
flink-table/flink-table-planner/src/test/java/org/apache/flink/table/planner/catalog/UnknownCatalogTest.java:
##########
@@ -90,6 +94,19 @@ public void testSetCatalogWithSelectCurrentTimestamp() 
throws Exception {
         
assertThat(table.getResolvedSchema()).isEqualTo(CURRENT_TIMESTAMP_EXPECTED_SCHEMA);
     }
 
+    @Test
+    public void testUnsetCatalogWithShowFunctions() throws Exception {
+        TableEnvironment tEnv = TableEnvironment.create(ENVIRONMENT_SETTINGS);
+
+        tEnv.useCatalog(null);
+
+        TableResult table = tEnv.executeSql("SHOW FUNCTIONS");
+        final List<Row> functions = 
CollectionUtil.iteratorToList(table.collect());
+
+        // check it has some built-in functions

Review Comment:
   `built-in` -> `system functions`



##########
flink-table/flink-table-api-java/src/main/java/org/apache/flink/table/catalog/FunctionCatalog.java:
##########
@@ -306,17 +306,19 @@ public Set<FunctionIdentifier> getUserDefinedFunctions(
                         .collect(Collectors.toSet()));
 
         // add catalog functions
-        Catalog catalog = catalogManager.getCatalog(catalogName).get();
+        Optional<Catalog> catalogOpt = catalogManager.getCatalog(catalogName);
         try {
-            catalog.listFunctions(databaseName)
-                    .forEach(
-                            name ->
-                                    result.add(
-                                            FunctionIdentifier.of(
-                                                    ObjectIdentifier.of(
-                                                            catalogName, 
databaseName, name))));
+            if (catalogOpt.isPresent()) {

Review Comment:
   couldn't we just use `.ifPresent()` here



##########
flink-table/flink-table-api-java/src/main/java/org/apache/flink/table/catalog/FunctionCatalog.java:
##########
@@ -306,17 +306,19 @@ public Set<FunctionIdentifier> getUserDefinedFunctions(
                         .collect(Collectors.toSet()));
 
         // add catalog functions
-        Catalog catalog = catalogManager.getCatalog(catalogName).get();
+        Optional<Catalog> catalogOpt = catalogManager.getCatalog(catalogName);
         try {
-            catalog.listFunctions(databaseName)
-                    .forEach(
-                            name ->
-                                    result.add(
-                                            FunctionIdentifier.of(
-                                                    ObjectIdentifier.of(
-                                                            catalogName, 
databaseName, name))));
+            if (catalogOpt.isPresent()) {
+                catalogOpt.get().listFunctions(databaseName)
+                        .forEach(
+                                name ->
+                                        result.add(
+                                                FunctionIdentifier.of(
+                                                        ObjectIdentifier.of(
+                                                                catalogName, 
databaseName, name))));
+            }
         } catch (DatabaseNotExistException e) {
-            // Ignore since there will always be a current database of the 
current catalog
+            // if catalog and or database do not exist, do not add usr defined 
functions

Review Comment:
   `usr defined` -> `catalog functions`



-- 
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: issues-unsubscr...@flink.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to