This is an automated email from the ASF dual-hosted git repository.
yiguolei pushed a commit to branch branch-2.1
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/branch-2.1 by this push:
new dc8da9ee890 [Fix](nereids) fix qualifier problem that affects delete
stmt in another catalog (#33528)
dc8da9ee890 is described below
commit dc8da9ee890a5ff2acddc9616a584253bb516901
Author: feiniaofeiafei <[email protected]>
AuthorDate: Thu Apr 11 21:43:01 2024 +0800
[Fix](nereids) fix qualifier problem that affects delete stmt in another
catalog (#33528)
* [Fix](nereids) fix qualifier problem that affects delete stmt in another
catalog
* [Fix](nereids) fix qualifier problem that affects delete stmt in another
catalog
* [Fix](nereids) fix qualifier problem that affects delete stmt in another
catalog
* [Fix](nereids) fix qualifier problem that affects delete stmt in another
catalog
---------
Co-authored-by: feiniaofeiafei <[email protected]>
---
.../doris/nereids/rules/analysis/BindRelation.java | 30 ++++++-----
.../plans/logical/LogicalCatalogRelation.java | 31 +++++------
.../plans/physical/PhysicalCatalogRelation.java | 22 +++++---
.../nereids/rules/analysis/BindRelationTest.java | 4 +-
.../nereids/rules/rewrite/ColumnPruningTest.java | 62 +++++++++++-----------
5 files changed, 81 insertions(+), 68 deletions(-)
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 bb768aba085..2a407a00b1b 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
@@ -66,6 +66,7 @@ import org.apache.doris.qe.ConnectContext;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
+import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import org.apache.commons.collections.CollectionUtils;
@@ -189,7 +190,7 @@ public class BindRelation extends OneAnalysisRuleFactory {
List<Long> tabletIds = unboundRelation.getTabletIds();
if (!CollectionUtils.isEmpty(partIds)) {
scan = new LogicalOlapScan(unboundRelation.getRelationId(),
- (OlapTable) table,
ImmutableList.of(tableQualifier.get(1)), partIds,
+ (OlapTable) table, tableQualifier, partIds,
tabletIds, unboundRelation.getHints(),
unboundRelation.getTableSample());
} else {
Optional<String> indexName = unboundRelation.getIndexName();
@@ -206,11 +207,11 @@ public class BindRelation extends OneAnalysisRuleFactory {
: PreAggStatus.off("For direct index scan.");
scan = new LogicalOlapScan(unboundRelation.getRelationId(),
- (OlapTable) table,
ImmutableList.of(tableQualifier.get(1)), tabletIds, indexId,
+ (OlapTable) table, tableQualifier, tabletIds, indexId,
preAggStatus, unboundRelation.getHints(),
unboundRelation.getTableSample());
} else {
scan = new LogicalOlapScan(unboundRelation.getRelationId(),
- (OlapTable) table,
ImmutableList.of(tableQualifier.get(1)), tabletIds, unboundRelation.getHints(),
+ (OlapTable) table, tableQualifier, tabletIds,
unboundRelation.getHints(),
unboundRelation.getTableSample());
}
}
@@ -238,10 +239,12 @@ public class BindRelation extends OneAnalysisRuleFactory {
private LogicalPlan getLogicalPlan(TableIf table, UnboundRelation
unboundRelation,
List<String> tableQualifier,
CascadesContext cascadesContext) {
+ List<String> qualifierWithoutTableName = Lists.newArrayList();
+ qualifierWithoutTableName.addAll(tableQualifier.subList(0,
tableQualifier.size() - 1));
switch (table.getType()) {
case OLAP:
case MATERIALIZED_VIEW:
- return makeOlapScan(table, unboundRelation, tableQualifier);
+ return makeOlapScan(table, unboundRelation,
qualifierWithoutTableName);
case VIEW:
View view = (View) table;
String inlineViewDef = view.getInlineViewDef();
@@ -257,24 +260,25 @@ public class BindRelation extends OneAnalysisRuleFactory {
return new LogicalSubQueryAlias<>(tableQualifier,
hiveViewPlan);
}
hmsTable.setScanParams(unboundRelation.getScanParams());
- return new LogicalFileScan(unboundRelation.getRelationId(),
(HMSExternalTable) table, tableQualifier,
- unboundRelation.getTableSample());
+ return new LogicalFileScan(unboundRelation.getRelationId(),
(HMSExternalTable) table,
+ qualifierWithoutTableName,
unboundRelation.getTableSample());
case ICEBERG_EXTERNAL_TABLE:
case PAIMON_EXTERNAL_TABLE:
case MAX_COMPUTE_EXTERNAL_TABLE:
- return new LogicalFileScan(unboundRelation.getRelationId(),
(ExternalTable) table, tableQualifier,
- unboundRelation.getTableSample());
+ return new LogicalFileScan(unboundRelation.getRelationId(),
(ExternalTable) table,
+ qualifierWithoutTableName,
unboundRelation.getTableSample());
case SCHEMA:
- return new LogicalSchemaScan(unboundRelation.getRelationId(),
table, tableQualifier);
+ return new LogicalSchemaScan(unboundRelation.getRelationId(),
table, qualifierWithoutTableName);
case JDBC_EXTERNAL_TABLE:
case JDBC:
- return new LogicalJdbcScan(unboundRelation.getRelationId(),
table, tableQualifier);
+ return new LogicalJdbcScan(unboundRelation.getRelationId(),
table, qualifierWithoutTableName);
case ODBC:
- return new LogicalOdbcScan(unboundRelation.getRelationId(),
table, tableQualifier);
+ return new LogicalOdbcScan(unboundRelation.getRelationId(),
table, qualifierWithoutTableName);
case ES_EXTERNAL_TABLE:
- return new LogicalEsScan(unboundRelation.getRelationId(),
(EsExternalTable) table, tableQualifier);
+ return new LogicalEsScan(unboundRelation.getRelationId(),
(EsExternalTable) table,
+ qualifierWithoutTableName);
case TEST_EXTERNAL_TABLE:
- return new LogicalTestScan(unboundRelation.getRelationId(),
table, tableQualifier);
+ return new LogicalTestScan(unboundRelation.getRelationId(),
table, qualifierWithoutTableName);
default:
try {
// TODO: support other type table, such as ELASTICSEARCH
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 b4dbc944460..5f7982aae46 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
@@ -39,11 +39,11 @@ import org.apache.doris.nereids.trees.plans.PlanType;
import org.apache.doris.nereids.trees.plans.RelationId;
import org.apache.doris.nereids.trees.plans.algebra.CatalogRelation;
import org.apache.doris.nereids.util.Utils;
+import org.apache.doris.qe.ConnectContext;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
-import org.apache.commons.lang3.StringUtils;
import java.util.List;
import java.util.Objects;
@@ -57,7 +57,7 @@ import java.util.function.Supplier;
public abstract class LogicalCatalogRelation extends LogicalRelation
implements CatalogRelation {
protected final TableIf table;
- // [catalogName, databaseName, tableName]
+ // [catalogName, databaseName]
protected final ImmutableList<String> qualifier;
public LogicalCatalogRelation(RelationId relationId, PlanType type,
TableIf table, List<String> qualifier) {
@@ -82,13 +82,20 @@ public abstract class LogicalCatalogRelation extends
LogicalRelation implements
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) + "]."));
+ int len = qualifier.size();
+ if (2 == len) {
+ CatalogIf<DatabaseIf> catalog =
Env.getCurrentEnv().getCatalogMgr()
+ .getCatalogOrAnalysisException(qualifier.get(0));
+ return catalog.getDbOrAnalysisException(qualifier.get(1));
+ } else if (1 == len) {
+ CatalogIf<DatabaseIf> catalog =
Env.getCurrentEnv().getCurrentCatalog();
+ return catalog.getDbOrAnalysisException(qualifier.get(0));
+ } else if (0 == len) {
+ CatalogIf<DatabaseIf> catalog =
Env.getCurrentEnv().getCurrentCatalog();
+ ConnectContext ctx = ConnectContext.get();
+ return catalog.getDb(ctx.getDatabase()).get();
+ }
+ return null;
} catch (Exception e) {
throw new AnalysisException(e.getMessage(), e);
}
@@ -110,9 +117,6 @@ public abstract class LogicalCatalogRelation extends
LogicalRelation implements
* Full qualified name parts, i.e., concat qualifier and name into a list.
*/
public List<String> qualified() {
- if (qualifier.size() == 3) {
- return qualifier;
- }
return Utils.qualifiedNameParts(qualifier, table.getName());
}
@@ -120,9 +124,6 @@ public abstract class LogicalCatalogRelation extends
LogicalRelation implements
* Full qualified table name, concat qualifier and name with `.` as
separator.
*/
public String qualifiedName() {
- if (qualifier.size() == 3) {
- return StringUtils.join(qualifier, ".");
- }
return Utils.qualifiedName(qualifier, table.getName());
}
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 70ac9aaa645..ddc26f1041c 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
@@ -31,6 +31,7 @@ import org.apache.doris.nereids.trees.plans.PlanType;
import org.apache.doris.nereids.trees.plans.RelationId;
import org.apache.doris.nereids.trees.plans.algebra.CatalogRelation;
import org.apache.doris.nereids.util.Utils;
+import org.apache.doris.qe.ConnectContext;
import org.apache.doris.statistics.Statistics;
import com.google.common.base.Preconditions;
@@ -85,13 +86,20 @@ public abstract class PhysicalCatalogRelation extends
PhysicalRelation implement
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) + "]."));
+ int len = qualifier.size();
+ if (2 == len) {
+ CatalogIf<DatabaseIf> catalog =
Env.getCurrentEnv().getCatalogMgr()
+ .getCatalogOrAnalysisException(qualifier.get(0));
+ return catalog.getDbOrAnalysisException(qualifier.get(1));
+ } else if (1 == len) {
+ CatalogIf<DatabaseIf> catalog =
Env.getCurrentEnv().getCurrentCatalog();
+ return catalog.getDbOrAnalysisException(qualifier.get(0));
+ } else if (0 == len) {
+ CatalogIf<DatabaseIf> catalog =
Env.getCurrentEnv().getCurrentCatalog();
+ ConnectContext ctx = ConnectContext.get();
+ return catalog.getDb(ctx.getDatabase()).get();
+ }
+ return null;
} catch (Exception e) {
throw new AnalysisException(e.getMessage(), e);
}
diff --git
a/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/analysis/BindRelationTest.java
b/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/analysis/BindRelationTest.java
index d719f3a8f89..25d0bb706be 100644
---
a/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/analysis/BindRelationTest.java
+++
b/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/analysis/BindRelationTest.java
@@ -64,7 +64,7 @@ class BindRelationTest extends TestWithFeService implements
GeneratedPlanPattern
Assertions.assertTrue(plan instanceof LogicalOlapScan);
Assertions.assertEquals(
- ImmutableList.of(DEFAULT_CLUSTER_PREFIX + DB1, "t"),
+ ImmutableList.of("internal", DEFAULT_CLUSTER_PREFIX + DB1,
"t"),
((LogicalOlapScan) plan).qualified());
}
@@ -76,7 +76,7 @@ class BindRelationTest extends TestWithFeService implements
GeneratedPlanPattern
Assertions.assertTrue(plan instanceof LogicalOlapScan);
Assertions.assertEquals(
- ImmutableList.of(DEFAULT_CLUSTER_PREFIX + DB1, "t"),
+ ImmutableList.of("internal", DEFAULT_CLUSTER_PREFIX + DB1,
"t"),
((LogicalOlapScan) plan).qualified());
}
diff --git
a/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/rewrite/ColumnPruningTest.java
b/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/rewrite/ColumnPruningTest.java
index c19fd68a72b..e6f2bb6838d 100644
---
a/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/rewrite/ColumnPruningTest.java
+++
b/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/rewrite/ColumnPruningTest.java
@@ -70,18 +70,18 @@ public class ColumnPruningTest extends TestWithFeService
implements MemoPatternM
logicalProject()
.when(p ->
getOutputQualifiedNames(p).containsAll(
ImmutableList.of(
-
"test.student.id",
-
"test.student.name"))),
+
"internal.test.student.id",
+
"internal.test.student.name"))),
logicalProject().when(
p ->
getOutputQualifiedNames(p).containsAll(
ImmutableList.of(
-
"test.score.sid",
-
"test.score.grade")))
+
"internal.test.score.sid",
+
"internal.test.score.grade")))
))
.when(p ->
getOutputQualifiedNames(p)
.containsAll(
-
ImmutableList.of("test.student.name",
-
"test.student.id")))
+
ImmutableList.of("internal.test.student.name",
+
"internal.test.student.id")))
)
)
);
@@ -102,18 +102,18 @@ public class ColumnPruningTest extends TestWithFeService
implements MemoPatternM
logicalProject()
.when(p ->
getOutputQualifiedNames(p).containsAll(
ImmutableList.of(
-
"test.student.id",
-
"test.student.name",
-
"test.student.sex"))),
+
"internal.test.student.id",
+
"internal.test.student.name",
+
"internal.test.student.sex"))),
logicalRelation()
))
.when(p ->
getOutputQualifiedNames(p)
.containsAll(
-
ImmutableList.of("test.student.name",
-
"test.score.cid",
-
"test.score.grade",
-
"test.student.sex")))
+
ImmutableList.of("internal.test.student.name",
+
"internal.test.score.cid",
+
"internal.test.score.grade",
+
"internal.test.student.sex")))
)
)
);
@@ -129,9 +129,9 @@ public class ColumnPruningTest extends TestWithFeService
implements MemoPatternM
logicalFilter(
logicalProject().when(p ->
getOutputQualifiedNames(p)
.containsAll(ImmutableList.of(
- "test.student.name",
- "test.student.id",
- "test.student.age")))
+
"internal.test.student.name",
+
"internal.test.student.id",
+
"internal.test.student.age")))
)
)
);
@@ -155,25 +155,25 @@ public class ColumnPruningTest extends TestWithFeService
implements MemoPatternM
logicalProject(logicalRelation())
.when(p -> getOutputQualifiedNames(
p).containsAll(ImmutableList.of(
-
"test.student.id",
-
"test.student.name"))),
+
"internal.test.student.id",
+
"internal.test.student.name"))),
logicalRelation()
)).when(p ->
getOutputQualifiedNames(p)
.containsAll(ImmutableList.of(
-
"test.student.name",
-
"test.score.cid",
-
"test.score.grade"))),
+
"internal.test.student.name",
+
"internal.test.score.cid",
+
"internal.test.score.grade"))),
logicalProject(logicalRelation())
.when(p ->
getOutputQualifiedNames(p)
.containsAll(ImmutableList.of(
-
"test.course.cid",
-
"test.course.cname")))
+
"internal.test.course.cid",
+
"internal.test.course.cname")))
)
).when(p ->
getOutputQualifiedNames(p).containsAll(ImmutableList.of(
- "test.student.name",
- "test.course.cname",
- "test.score.grade")))
+ "internal.test.student.name",
+ "internal.test.course.cname",
+ "internal.test.score.grade")))
)
)
);
@@ -280,12 +280,12 @@ public class ColumnPruningTest extends TestWithFeService
implements MemoPatternM
logicalProject(logicalRelation())
.when(p ->
getOutputQualifiedNames(p)
.containsAll(ImmutableList.of(
-
"test.student.id",
-
"test.student.name"))),
+
"internal.test.student.id",
+
"internal.test.student.name"))),
logicalProject(logicalRelation())
.when(p ->
getOutputQualifiedNames(p)
.containsAll(ImmutableList.of(
-
"test.score.sid")))
+
"internal.test.score.sid")))
)
)
);
@@ -304,10 +304,10 @@ public class ColumnPruningTest extends TestWithFeService
implements MemoPatternM
logicalProject(
logicalOlapScan()
).when(p ->
getOutputQualifiedNames(p).equals(
-
ImmutableList.of("test.student.id")
+
ImmutableList.of("internal.test.student.id")
))
).when(agg ->
getOutputQualifiedNames(agg.getOutputs()).equals(
-
ImmutableList.of("test.student.id")
+
ImmutableList.of("internal.test.student.id")
)))
)
)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]