bowenli86 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_r339228905
 
 

 ##########
 File path: 
flink-table/flink-table-api-java/src/main/java/org/apache/flink/table/catalog/CatalogManager.java
 ##########
 @@ -207,28 +207,226 @@ 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(
 
 Review comment:
   this call can be saved by calling `objectIdentifier.toObjectPath()`

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