bowenli86 commented on a change in pull request #8404: [FLINK-11476][table] 
Create CatalogManager to manage multiple catalogs
URL: https://github.com/apache/flink/pull/8404#discussion_r284898257
 
 

 ##########
 File path: 
flink-table/flink-table-api-java/src/main/java/org/apache/flink/table/catalog/CatalogManager.java
 ##########
 @@ -250,56 +258,64 @@ public void setCurrentDatabase(String databaseName) 
throws DatabaseNotExistExcep
        public Optional<CatalogTableOperation> resolveTable(String... 
tablePath) {
                checkArgument(tablePath != null && tablePath.length != 0, 
"Table path must not be null or empty.");
 
-               List<String> defaultPath = new ArrayList<>();
-               defaultPath.add(currentCatalogName);
-               defaultPath.add(currentDatabaseName);
+               List<String> userPath = asList(tablePath);
 
-               List<String> userPath = Arrays.asList(tablePath);
-               defaultPath.addAll(userPath);
+               List<List<String>> prefixes = asList(
+                       asList(currentCatalogName, currentDatabaseName),
+                       singletonList(currentCatalogName),
+                       emptyList()
+               );
 
-               Optional<CatalogTableOperation> inDefaultPath = 
lookupPath(defaultPath);
-
-               if (inDefaultPath.isPresent()) {
-                       return inDefaultPath;
-               } else {
-                       return lookupPath(userPath);
+               for (List<String> prefix : prefixes) {
+                       Optional<CatalogTableOperation> potentialTable = 
lookupPath(prefix, userPath);
+                       if (potentialTable.isPresent()) {
+                               return potentialTable;
+                       }
                }
+
+               return Optional.empty();
        }
 
-       private Optional<CatalogTableOperation> lookupPath(List<String> path) {
+       private Optional<CatalogTableOperation> lookupPath(List<String> prefix, 
List<String> userPath) {
                try {
-                       Optional<TableSchema> potentialTable = 
lookupCatalogTable(path);
+                       List<String> path = new ArrayList<>(prefix);
+                       path.addAll(userPath);
+
+                       Optional<CatalogTableOperation> potentialTable = 
lookupCatalogTable(path);
 
 Review comment:
   the validation is fine. 
   
   > This is not a performance critical code.
   
   Just in general I think query planning is critical to any benchmarks we run. 
I just heard from my colleague who is doing Flink/Blink TPCH now that, even how 
the `CatalogReader` runs is hearting the benchmark quite a bit because it needs 
to [exam three schema 
paths](https://github.com/apache/flink/pull/8404/files#diff-0bb30406df09433cce9b3617f910db9bR47)
 to find the table. Hope the background helps explain the necessity. Though I 
think this probably won't hurt benchmarks run with catalog table and blink 
planner because a catalog table will be returned without going to look up 
external tables, any perf improvement in query planning phase would help us in 
the long run. 
   
   I will leave this issue up to you.

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