Jibing-Li commented on code in PR #15201:
URL: https://github.com/apache/doris/pull/15201#discussion_r1058432368


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/BindRelation.java:
##########
@@ -82,48 +112,62 @@ private LogicalPlan bindWithCurrentDb(CascadesContext 
cascadesContext, UnboundRe
             }
             return new LogicalSubQueryAlias<>(tableName, ctePlan);
         }
-
+        String catalogName = 
cascadesContext.getConnectContext().getCurrentCatalog().getName();
         String dbName = cascadesContext.getConnectContext().getDatabase();
-        Table table = cascadesContext.getTable(dbName, tableName, 
cascadesContext.getConnectContext().getEnv());
+        TableIf table = getTable(catalogName, dbName, tableName, 
cascadesContext.getConnectContext().getEnv());
         // TODO: should generate different Scan sub class according to table's 
type
-        List<Long> partIds = getPartitionIds(table, unboundRelation);
-        if (table.getType() == TableType.OLAP) {
-            if (!CollectionUtils.isEmpty(partIds)) {
-                return new LogicalOlapScan(RelationUtil.newRelationId(),
-                        (OlapTable) table, ImmutableList.of(dbName), partIds);
-            } else {
-                return new LogicalOlapScan(RelationUtil.newRelationId(),
-                        (OlapTable) table, ImmutableList.of(dbName));
-            }
-        } else if (table.getType() == TableType.VIEW) {
-            Plan viewPlan = parseAndAnalyzeView(table.getDdlSql(), 
cascadesContext);
-            return new LogicalSubQueryAlias<>(table.getName(), viewPlan);
-        }
-        throw new AnalysisException("Unsupported tableType:" + 
table.getType());
+        return getLogicalPlan(table, unboundRelation, dbName, cascadesContext);
     }
 
     private LogicalPlan bindWithDbNameFromNamePart(CascadesContext 
cascadesContext, UnboundRelation unboundRelation) {
         List<String> nameParts = unboundRelation.getNameParts();
         ConnectContext connectContext = cascadesContext.getConnectContext();
+        String catalogName = 
cascadesContext.getConnectContext().getCurrentCatalog().getName();
         // if the relation is view, nameParts.get(0) is dbName.
         String dbName = nameParts.get(0);
         if (!dbName.equals(connectContext.getDatabase())) {
             dbName = connectContext.getClusterName() + ":" + dbName;
         }
-        Table table = cascadesContext.getTable(dbName, nameParts.get(1), 
connectContext.getEnv());
-        List<Long> partIds = getPartitionIds(table, unboundRelation);
-        if (table.getType() == TableType.OLAP) {
-            if (!CollectionUtils.isEmpty(partIds)) {
-                return new LogicalOlapScan(RelationUtil.newRelationId(), 
(OlapTable) table,
-                        ImmutableList.of(dbName), partIds);
-            } else {
-                return new LogicalOlapScan(RelationUtil.newRelationId(), 
(OlapTable) table, ImmutableList.of(dbName));
-            }
-        } else if (table.getType() == TableType.VIEW) {
-            Plan viewPlan = parseAndAnalyzeView(table.getDdlSql(), 
cascadesContext);
-            return new LogicalSubQueryAlias<>(table.getName(), viewPlan);
+        String tableName = nameParts.get(1);
+        TableIf table = getTable(catalogName, dbName, tableName, 
connectContext.getEnv());
+        return getLogicalPlan(table, unboundRelation, dbName, cascadesContext);
+    }
+
+    private LogicalPlan bindWithCatalogNameFromNamePart(CascadesContext 
cascadesContext,
+                                                        UnboundRelation 
unboundRelation) {
+        List<String> nameParts = unboundRelation.getNameParts();
+        ConnectContext connectContext = cascadesContext.getConnectContext();
+        String catalogName = nameParts.get(0);
+        String dbName = nameParts.get(1);
+        if (!dbName.equals(connectContext.getDatabase())) {
+            dbName = connectContext.getClusterName() + ":" + dbName;
+        }
+        String tableName = nameParts.get(2);
+        TableIf table = getTable(catalogName, dbName, tableName, 
connectContext.getEnv());
+        return getLogicalPlan(table, unboundRelation, dbName, cascadesContext);
+    }
+
+    private LogicalPlan getLogicalPlan(TableIf table, UnboundRelation 
unboundRelation, String dbName,
+                                       CascadesContext cascadesContext) {
+        switch (table.getType()) {
+            case OLAP:
+                List<Long> partIds = getPartitionIds(table, unboundRelation);
+                if (!CollectionUtils.isEmpty(partIds)) {
+                    return new LogicalOlapScan(RelationUtil.newRelationId(),
+                        (OlapTable) table, ImmutableList.of(dbName), partIds);
+                } else {
+                    return new LogicalOlapScan(RelationUtil.newRelationId(),
+                        (OlapTable) table, ImmutableList.of(dbName));
+                }
+            case VIEW:
+                Plan viewPlan = parseAndAnalyzeView(((View) 
table).getDdlSql(), cascadesContext);
+                return new LogicalSubQueryAlias<>(table.getName(), viewPlan);
+            case HMS_EXTERNAL_TABLE:
+                return new 
LogicalFileScan(cascadesContext.getStatementContext().getNextRelationId(),
+                    (HMSExternalTable) table, ImmutableList.of(dbName));

Review Comment:
   I'll take a look at this, probably fix it in next PR.



-- 
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: [email protected]

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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to