godfreyhe commented on a change in pull request #11869:
URL: https://github.com/apache/flink/pull/11869#discussion_r414498307



##########
File path: flink-python/pyflink/table/table_environment.py
##########
@@ -345,14 +345,24 @@ def list_databases(self):
 
     def list_tables(self):
         """
-        Gets the names of all tables in the current database of the current 
catalog.
+        Gets the names of all tables and views in the current database of the 
current catalog.
 
-        :return: List of table names in the current database of the current 
catalog.
+        :return: List of table and view names in the current database of the 
current catalog.
         :rtype: list[str]
         """
         j_table_name_array = self._j_tenv.listTables()
         return [item for item in j_table_name_array]
 
+    def list_views(self):
+        """
+        Gets the names of all views in the current database of the current 
catalog.
+
+        :return: List of view names in the current database of the current 
catalog.

Review comment:
       add "It returns both temporary and permanent views."

##########
File path: 
flink-table/flink-table-api-java/src/main/java/org/apache/flink/table/catalog/CatalogManager.java
##########
@@ -415,6 +415,37 @@ public CatalogBaseTable getTable() {
                        });
        }
 
+       /**
+        * Returns an array of names of all views(both temporary and permanent) 
registered in
+        * the namespace of the current catalog and database.
+        *
+        * @return names of all registered views
+        */
+       public Set<String> listViews() {
+               return listViews(getCurrentCatalog(), getCurrentDatabase());
+       }
+
+       /**
+        * Returns an array of names of all views(both temporary and permanent) 
registered in
+        * the namespace of the current catalog and database.
+        *
+        * @return names of registered views
+        */
+       public Set<String> listViews(String catalogName, String databaseName) {
+               Catalog currentCatalog = catalogs.get(getCurrentCatalog());
+
+               try {
+                       return Stream.concat(
+                               
currentCatalog.listViews(getCurrentDatabase()).stream(),
+                               listTemporaryTablesInternal(catalogName, 
databaseName)
+                                       .filter(e -> e.getValue() instanceof 
CatalogView)
+                                       .map(e -> e.getKey().getObjectName())
+                       ).collect(Collectors.toSet());

Review comment:
       `listTemporaryTablesInternal` already exists




----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to