diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/BindRelation.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/BindRelation.java index 425641fda3a0ac..aff19c54411090 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/BindRelation.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/BindRelation.java @@ -200,7 +200,6 @@ private LogicalPlan makeOlapScan(TableIf table, UnboundRelation unboundRelation, private LogicalPlan getLogicalPlan(TableIf table, UnboundRelation unboundRelation, List tableQualifier, CascadesContext cascadesContext) { - String dbName = tableQualifier.get(1); //[catalogName, dbName, tableName] switch (table.getType()) { case OLAP: return makeOlapScan(table, unboundRelation, tableQualifier); @@ -223,14 +222,12 @@ private LogicalPlan getLogicalPlan(TableIf table, UnboundRelation unboundRelatio return new LogicalFileScan(StatementScopeIdGenerator.newRelationId(), (ExternalTable) table, tableQualifier); case SCHEMA: - return new LogicalSchemaScan(unboundRelation.getRelationId(), - table, ImmutableList.of(dbName)); + return new LogicalSchemaScan(unboundRelation.getRelationId(), table, tableQualifier); case JDBC_EXTERNAL_TABLE: case JDBC: - return new LogicalJdbcScan(unboundRelation.getRelationId(), table, ImmutableList.of(dbName)); + return new LogicalJdbcScan(unboundRelation.getRelationId(), table, tableQualifier); case ES_EXTERNAL_TABLE: - return new LogicalEsScan(unboundRelation.getRelationId(), - (EsExternalTable) table, ImmutableList.of(dbName)); + return new LogicalEsScan(unboundRelation.getRelationId(), (EsExternalTable) table, tableQualifier); default: throw new AnalysisException("Unsupported tableType:" + table.getType()); } diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/algebra/CatalogRelation.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/algebra/CatalogRelation.java index f009c413344c32..d713ba16a8ac34 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/algebra/CatalogRelation.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/algebra/CatalogRelation.java @@ -17,7 +17,7 @@ package org.apache.doris.nereids.trees.plans.algebra; -import org.apache.doris.catalog.Database; +import org.apache.doris.catalog.DatabaseIf; import org.apache.doris.catalog.TableIf; import org.apache.doris.nereids.exceptions.AnalysisException; @@ -26,5 +26,5 @@ public interface CatalogRelation extends Relation { TableIf getTable(); - Database getDatabase() throws AnalysisException; + DatabaseIf getDatabase() throws AnalysisException; } diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/logical/LogicalCatalogRelation.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/logical/LogicalCatalogRelation.java index 6150e9047aca60..246c875f91b4da 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/logical/LogicalCatalogRelation.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/logical/LogicalCatalogRelation.java @@ -17,9 +17,10 @@ package org.apache.doris.nereids.trees.plans.logical; -import org.apache.doris.catalog.Database; +import org.apache.doris.catalog.DatabaseIf; import org.apache.doris.catalog.Env; import org.apache.doris.catalog.TableIf; +import org.apache.doris.datasource.CatalogIf; import org.apache.doris.nereids.exceptions.AnalysisException; import org.apache.doris.nereids.memo.GroupExpression; import org.apache.doris.nereids.properties.LogicalProperties; @@ -43,6 +44,7 @@ public abstract class LogicalCatalogRelation extends LogicalRelation implements CatalogRelation { protected final TableIf table; + // [catalogName, databaseName, tableName] protected final ImmutableList qualifier; public LogicalCatalogRelation(RelationId relationId, PlanType type, TableIf table, List qualifier) { @@ -64,10 +66,19 @@ public TableIf getTable() { } @Override - public Database getDatabase() throws AnalysisException { - Preconditions.checkArgument(!qualifier.isEmpty()); - return Env.getCurrentInternalCatalog().getDbOrException(qualifier.get(0), - s -> new AnalysisException("Database [" + qualifier.get(0) + "] does not exist.")); + public DatabaseIf getDatabase() throws AnalysisException { + Preconditions.checkArgument(!qualifier.isEmpty(), "qualifier can not be empty"); + try { + CatalogIf catalog = qualifier.size() == 3 + ? Env.getCurrentEnv().getCatalogMgr().getCatalogOrException(qualifier.get(0), + s -> new Exception("Catalog [" + qualifier.get(0) + "] does not exist.")) + : Env.getCurrentEnv().getCurrentCatalog(); + return catalog.getDbOrException(qualifier.size() == 3 ? qualifier.get(1) : qualifier.get(0), + s -> new Exception("Database [" + qualifier.get(1) + "] does not exist in catalog [" + + qualifier.get(0) + "].")); + } catch (Exception e) { + throw new AnalysisException(e.getMessage(), e); + } } @Override diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/physical/PhysicalCatalogRelation.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/physical/PhysicalCatalogRelation.java index b25a7c530afb85..fc359fe3053de1 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/physical/PhysicalCatalogRelation.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/physical/PhysicalCatalogRelation.java @@ -17,9 +17,10 @@ package org.apache.doris.nereids.trees.plans.physical; -import org.apache.doris.catalog.Database; +import org.apache.doris.catalog.DatabaseIf; import org.apache.doris.catalog.Env; import org.apache.doris.catalog.TableIf; +import org.apache.doris.datasource.CatalogIf; import org.apache.doris.nereids.exceptions.AnalysisException; import org.apache.doris.nereids.memo.GroupExpression; import org.apache.doris.nereids.properties.LogicalProperties; @@ -81,10 +82,19 @@ public TableIf getTable() { } @Override - public Database getDatabase() throws AnalysisException { - Preconditions.checkArgument(!qualifier.isEmpty()); - return Env.getCurrentInternalCatalog().getDbOrException(qualifier.get(0), - s -> new AnalysisException("Database [" + qualifier.get(0) + "] does not exist.")); + public DatabaseIf getDatabase() throws AnalysisException { + Preconditions.checkArgument(!qualifier.isEmpty(), "qualifier can not be empty"); + try { + CatalogIf catalog = qualifier.size() == 3 + ? Env.getCurrentEnv().getCatalogMgr().getCatalogOrException(qualifier.get(0), + s -> new Exception("Catalog [" + qualifier.get(0) + "] does not exist.")) + : Env.getCurrentEnv().getCurrentCatalog(); + return catalog.getDbOrException(qualifier.size() == 3 ? qualifier.get(1) : qualifier.get(0), + s -> new Exception("Database [" + qualifier.get(1) + "] does not exist in catalog [" + + qualifier.get(0) + "].")); + } catch (Exception e) { + throw new AnalysisException(e.getMessage(), e); + } } @Override