dawidwys commented on a change in pull request #9971: [FLINK-14490][table] Add 
methods for interacting with temporary objects
URL: https://github.com/apache/flink/pull/9971#discussion_r338619715
 
 

 ##########
 File path: 
flink-table/flink-table-api-java/src/main/java/org/apache/flink/table/catalog/CatalogManager.java
 ##########
 @@ -207,28 +214,138 @@ public String getBuiltInDatabaseName() {
                return 
catalogs.get(getBuiltInCatalogName()).getDefaultDatabase();
        }
 
+       /**
+        * Result of a lookup for a table through {@link 
#getTable(ObjectIdentifier)}. It combines the
+        * {@link CatalogBaseTable} with additional information such as if the 
table is a temporary table or comes
+        * from the catalog.
+        */
+       public static class TableLookupResult {
+               private final boolean isTemporary;
+               private final CatalogBaseTable table;
+
+               private static TableLookupResult temporary(CatalogBaseTable 
table) {
+                       return new TableLookupResult(true, table);
+               }
+
+               private static TableLookupResult permanent(CatalogBaseTable 
table) {
+                       return new TableLookupResult(false, table);
+               }
+
+               private TableLookupResult(boolean isTemporary, CatalogBaseTable 
table) {
+                       this.isTemporary = isTemporary;
+                       this.table = table;
+               }
+
+               public boolean isTemporary() {
+                       return isTemporary;
+               }
+
+               public CatalogBaseTable getTable() {
+                       return table;
+               }
+       }
+
        /**
         * Retrieves a fully qualified table. If the path is not yet fully 
qualified use
         * {@link #qualifyIdentifier(UnresolvedIdentifier)} first.
         *
         * @param objectIdentifier full path of the table to retrieve
         * @return table that the path points to.
         */
-       public Optional<CatalogBaseTable> getTable(ObjectIdentifier 
objectIdentifier) {
+       public Optional<TableLookupResult> getTable(ObjectIdentifier 
objectIdentifier) {
                try {
-                       Catalog currentCatalog = 
catalogs.get(objectIdentifier.getCatalogName());
-                       ObjectPath objectPath = new ObjectPath(
-                               objectIdentifier.getDatabaseName(),
-                               objectIdentifier.getObjectName());
-
-                       if (currentCatalog != null && 
currentCatalog.tableExists(objectPath)) {
-                               return 
Optional.of(currentCatalog.getTable(objectPath));
+                       CatalogBaseTable temporaryTable = 
temporaryTables.get(objectIdentifier);
+                       if (temporaryTable != null) {
+                               return 
Optional.of(TableLookupResult.temporary(temporaryTable));
+                       } else {
+                               return getPermanentTable(objectIdentifier);
                        }
                } catch (TableNotExistException ignored) {
                }
                return Optional.empty();
        }
 
+       private Optional<TableLookupResult> getPermanentTable(ObjectIdentifier 
objectIdentifier)
+                       throws TableNotExistException {
+               Catalog currentCatalog = 
catalogs.get(objectIdentifier.getCatalogName());
+               ObjectPath objectPath = new ObjectPath(
+                       objectIdentifier.getDatabaseName(),
+                       objectIdentifier.getObjectName());
+
+               if (currentCatalog != null && 
currentCatalog.tableExists(objectPath)) {
+                       return 
Optional.of(TableLookupResult.permanent(currentCatalog.getTable(objectPath)));
+               }
+               return Optional.empty();
+       }
+
+       /**
+        * Returns unmodifiable map of all registered temporary tables and 
views.
+        *
+        * @return map of registered temporary tables & views
+        */
+       public Map<ObjectIdentifier, CatalogBaseTable> getTemporaryTables() {
+               return Collections.unmodifiableMap(temporaryTables);
+       }
+
+       /**
+        * Returns an array of names of all tables (tables and views, both 
temporary and permanent)
+        * registered in the namespace of the current catalog and database.
+        *
+        * @return paths of all registered tables
+        */
+       public String[] listTables() {
 
 Review comment:
   Good point. I think we should use `Set` in the CatalogManager though. It is 
an internal API that might be used at different places e.g. in the 
`DatabaseCalciteSchema` and the `Set` is more general interface. I unified all 
methods.

----------------------------------------------------------------
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:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to