This is an automated email from the ASF dual-hosted git repository.
morrysnow pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/master by this push:
new 0a16f11435 [enhancement](Nereids) add RelationId to unboundRelation
(#14693)
0a16f11435 is described below
commit 0a16f11435e745917da84f737849058a4764f382
Author: mch_ucchi <[email protected]>
AuthorDate: Mon Dec 12 16:24:08 2022 +0800
[enhancement](Nereids) add RelationId to unboundRelation (#14693)
add RelationId to unboundRelation and refactor some ut used RelationUtil to
allocate next RelationId.
---
.../doris/nereids/analyzer/UnboundRelation.java | 40 ++--
.../apache/doris/nereids/memo/GroupExpression.java | 5 -
.../doris/nereids/parser/LogicalPlanBuilder.java | 3 +-
.../doris/nereids/rules/analysis/BindRelation.java | 9 +-
.../doris/nereids/trees/plans/AbstractPlan.java | 5 +
.../trees/plans/logical/LogicalRelation.java | 7 +
.../nereids/trees/plans/logical/RelationUtil.java | 51 +++++
.../translator/PhysicalPlanTranslatorTest.java | 4 +-
.../doris/nereids/jobs/RewriteTopDownJobTest.java | 8 +-
.../nereids/jobs/cascades/DeriveStatsJobTest.java | 8 +-
.../org/apache/doris/nereids/memo/MemoTest.java | 217 ++++++++-------------
.../pattern/GroupExpressionMatchingTest.java | 35 ++--
.../nereids/rules/analysis/BindRelationTest.java | 5 +-
.../rules/analysis/BindSlotReferenceTest.java | 8 +-
.../nereids/rules/analysis/CheckRowPolicyTest.java | 8 +-
.../nereids/rules/analysis/RegisterCTETest.java | 8 +-
.../rewrite/logical/AggregateDisassembleTest.java | 4 +-
.../rules/rewrite/logical/LimitPushDownTest.java | 6 +-
.../rules/rewrite/logical/MergeFiltersTest.java | 3 +-
.../rules/rewrite/logical/MergeLimitsTest.java | 4 +-
.../rules/rewrite/logical/MergeProjectsTest.java | 5 +-
.../rewrite/logical/NormalizeAggregateTest.java | 4 +-
.../PushdownFilterThroughAggregationTest.java | 6 +-
.../doris/nereids/stats/StatsCalculatorTest.java | 4 +-
.../doris/nereids/trees/plans/PlanEqualsTest.java | 3 +-
.../doris/nereids/trees/plans/PlanOutputTest.java | 5 +-
26 files changed, 252 insertions(+), 213 deletions(-)
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/nereids/analyzer/UnboundRelation.java
b/fe/fe-core/src/main/java/org/apache/doris/nereids/analyzer/UnboundRelation.java
index a1eda47a00..b8491ad019 100644
---
a/fe/fe-core/src/main/java/org/apache/doris/nereids/analyzer/UnboundRelation.java
+++
b/fe/fe-core/src/main/java/org/apache/doris/nereids/analyzer/UnboundRelation.java
@@ -17,6 +17,7 @@
package org.apache.doris.nereids.analyzer;
+import org.apache.doris.catalog.Table;
import org.apache.doris.nereids.analyzer.identifier.TableIdentifier;
import org.apache.doris.nereids.exceptions.UnboundException;
import org.apache.doris.nereids.memo.GroupExpression;
@@ -26,7 +27,8 @@ import org.apache.doris.nereids.trees.expressions.Expression;
import org.apache.doris.nereids.trees.expressions.Slot;
import org.apache.doris.nereids.trees.plans.Plan;
import org.apache.doris.nereids.trees.plans.PlanType;
-import org.apache.doris.nereids.trees.plans.logical.LogicalLeaf;
+import org.apache.doris.nereids.trees.plans.RelationId;
+import org.apache.doris.nereids.trees.plans.logical.LogicalRelation;
import org.apache.doris.nereids.trees.plans.visitor.PlanVisitor;
import org.apache.doris.nereids.util.Utils;
@@ -40,21 +42,21 @@ import java.util.Optional;
/**
* Represent a relation plan node that has not been bound.
*/
-public class UnboundRelation extends LogicalLeaf implements Relation, Unbound {
+public class UnboundRelation extends LogicalRelation implements Unbound {
private final List<String> nameParts;
- public UnboundRelation(List<String> nameParts) {
- this(nameParts, Optional.empty(), Optional.empty());
+ public UnboundRelation(RelationId id, List<String> nameParts) {
+ this(id, nameParts, Optional.empty(), Optional.empty());
}
- public UnboundRelation(List<String> nameParts, Optional<GroupExpression>
groupExpression,
+ public UnboundRelation(RelationId id, List<String> nameParts,
Optional<GroupExpression> groupExpression,
Optional<LogicalProperties> logicalProperties) {
- super(PlanType.LOGICAL_UNBOUND_RELATION, groupExpression,
logicalProperties);
+ super(id, PlanType.LOGICAL_UNBOUND_RELATION, groupExpression,
logicalProperties);
this.nameParts = nameParts;
}
- public UnboundRelation(TableIdentifier identifier) {
- this(identifier, Optional.empty(), Optional.empty());
+ public UnboundRelation(RelationId id, TableIdentifier identifier) {
+ this(id, identifier, Optional.empty(), Optional.empty());
}
/**
@@ -62,9 +64,9 @@ public class UnboundRelation extends LogicalLeaf implements
Relation, Unbound {
*
* @param identifier relation identifier
*/
- public UnboundRelation(TableIdentifier identifier,
Optional<GroupExpression> groupExpression,
+ public UnboundRelation(RelationId id, TableIdentifier identifier,
Optional<GroupExpression> groupExpression,
Optional<LogicalProperties> logicalProperties) {
- super(PlanType.LOGICAL_UNBOUND_RELATION, groupExpression,
logicalProperties);
+ super(id, PlanType.LOGICAL_UNBOUND_RELATION, groupExpression,
logicalProperties);
this.nameParts = Lists.newArrayList();
if (identifier.getDatabaseName().isPresent()) {
nameParts.add(identifier.getDatabaseName().get());
@@ -72,6 +74,11 @@ public class UnboundRelation extends LogicalLeaf implements
Relation, Unbound {
nameParts.add(identifier.getTableName());
}
+ @Override
+ public Table getTable() {
+ throw new UnsupportedOperationException("unbound relation cannot get
table");
+ }
+
public List<String> getNameParts() {
return nameParts;
}
@@ -88,12 +95,12 @@ public class UnboundRelation extends LogicalLeaf implements
Relation, Unbound {
@Override
public Plan withGroupExpression(Optional<GroupExpression> groupExpression)
{
- return new UnboundRelation(nameParts, groupExpression,
Optional.of(getLogicalProperties()));
+ return new UnboundRelation(id, nameParts, groupExpression,
Optional.of(getLogicalProperties()));
}
@Override
public Plan withLogicalProperties(Optional<LogicalProperties>
logicalProperties) {
- return new UnboundRelation(nameParts, Optional.empty(),
logicalProperties);
+ return new UnboundRelation(id, nameParts, Optional.empty(),
logicalProperties);
}
@Override
@@ -104,6 +111,7 @@ public class UnboundRelation extends LogicalLeaf implements
Relation, Unbound {
@Override
public String toString() {
return Utils.toSqlString("UnboundRelation",
+ "id", id,
"nameParts", StringUtils.join(nameParts, ".")
);
}
@@ -118,6 +126,10 @@ public class UnboundRelation extends LogicalLeaf
implements Relation, Unbound {
throw new
UnsupportedOperationException(this.getClass().getSimpleName() + " don't support
getExpression()");
}
+ public RelationId getId() {
+ return id;
+ }
+
@Override
public boolean equals(Object o) {
if (this == o) {
@@ -130,11 +142,11 @@ public class UnboundRelation extends LogicalLeaf
implements Relation, Unbound {
return false;
}
UnboundRelation that = (UnboundRelation) o;
- return Objects.equals(nameParts, that.nameParts);
+ return id.equals(that.id);
}
@Override
public int hashCode() {
- return Objects.hash(nameParts);
+ return Objects.hash(id);
}
}
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/nereids/memo/GroupExpression.java
b/fe/fe-core/src/main/java/org/apache/doris/nereids/memo/GroupExpression.java
index d7c3631ed8..d3b03db2ce 100644
---
a/fe/fe-core/src/main/java/org/apache/doris/nereids/memo/GroupExpression.java
+++
b/fe/fe-core/src/main/java/org/apache/doris/nereids/memo/GroupExpression.java
@@ -18,7 +18,6 @@
package org.apache.doris.nereids.memo;
import org.apache.doris.common.Pair;
-import org.apache.doris.nereids.analyzer.UnboundRelation;
import org.apache.doris.nereids.cost.CostEstimate;
import org.apache.doris.nereids.metrics.EventChannel;
import org.apache.doris.nereids.metrics.EventProducer;
@@ -233,10 +232,6 @@ public class GroupExpression {
return false;
}
GroupExpression that = (GroupExpression) o;
- // TODO: add relation id to UnboundRelation
- if (plan instanceof UnboundRelation) {
- return false;
- }
return children.equals(that.children) && plan.equals(that.plan)
&&
plan.getLogicalProperties().equals(that.plan.getLogicalProperties());
}
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java
b/fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java
index f37ceccdb2..ce63061a53 100644
---
a/fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java
+++
b/fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java
@@ -165,6 +165,7 @@ import
org.apache.doris.nereids.trees.plans.logical.LogicalRepeat;
import org.apache.doris.nereids.trees.plans.logical.LogicalSelectHint;
import org.apache.doris.nereids.trees.plans.logical.LogicalSort;
import org.apache.doris.nereids.trees.plans.logical.LogicalSubQueryAlias;
+import org.apache.doris.nereids.trees.plans.logical.RelationUtil;
import org.apache.doris.nereids.types.DataType;
import org.apache.doris.nereids.util.ExpressionUtils;
import org.apache.doris.policy.PolicyTypeEnum;
@@ -345,7 +346,7 @@ public class LogicalPlanBuilder extends
DorisParserBaseVisitor<Object> {
@Override
public LogicalPlan visitTableName(TableNameContext ctx) {
List<String> tableId =
visitMultipartIdentifier(ctx.multipartIdentifier());
- LogicalPlan checkedRelation = withCheckPolicy(new
UnboundRelation(tableId));
+ LogicalPlan checkedRelation = withCheckPolicy(new
UnboundRelation(RelationUtil.newRelationId(), tableId));
return withTableAlias(checkedRelation, ctx.tableAlias());
}
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 d5e331947c..11372d7ac8 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
@@ -30,6 +30,7 @@ import org.apache.doris.nereids.trees.plans.Plan;
import org.apache.doris.nereids.trees.plans.logical.LogicalOlapScan;
import org.apache.doris.nereids.trees.plans.logical.LogicalPlan;
import org.apache.doris.nereids.trees.plans.logical.LogicalSubQueryAlias;
+import org.apache.doris.nereids.trees.plans.logical.RelationUtil;
import org.apache.doris.qe.ConnectContext;
import com.google.common.collect.ImmutableList;
@@ -42,6 +43,8 @@ import java.util.Optional;
*/
public class BindRelation extends OneAnalysisRuleFactory {
+ // TODO: cte will be copied to a sub-query with different names but the id
of the unbound relation in them
+ // are the same, so we use new relation id when binding relation, and
will fix this bug later.
@Override
public Rule build() {
return unboundRelation().thenApply(ctx -> {
@@ -78,8 +81,7 @@ public class BindRelation extends OneAnalysisRuleFactory {
Table table = cascadesContext.getTable(dbName, tableName,
cascadesContext.getConnectContext().getEnv());
// TODO: should generate different Scan sub class according to table's
type
if (table.getType() == TableType.OLAP) {
- return new
LogicalOlapScan(cascadesContext.getStatementContext().getNextRelationId(),
- (OlapTable) table, ImmutableList.of(dbName));
+ 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);
@@ -96,8 +98,7 @@ public class BindRelation extends OneAnalysisRuleFactory {
}
Table table = cascadesContext.getTable(dbName, nameParts.get(1),
connectContext.getEnv());
if (table.getType() == TableType.OLAP) {
- return new
LogicalOlapScan(cascadesContext.getStatementContext().getNextRelationId(),
- (OlapTable) table, ImmutableList.of(dbName));
+ 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);
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/AbstractPlan.java
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/AbstractPlan.java
index 17b840dfb6..6235f2b7a5 100644
---
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/AbstractPlan.java
+++
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/AbstractPlan.java
@@ -18,6 +18,7 @@
package org.apache.doris.nereids.trees.plans;
import org.apache.doris.nereids.analyzer.Unbound;
+import org.apache.doris.nereids.analyzer.UnboundRelation;
import org.apache.doris.nereids.memo.GroupExpression;
import org.apache.doris.nereids.memo.Memo;
import org.apache.doris.nereids.metrics.CounterType;
@@ -27,6 +28,7 @@ import org.apache.doris.nereids.metrics.consumer.LogConsumer;
import org.apache.doris.nereids.metrics.enhancer.AddCounterEventEnhancer;
import org.apache.doris.nereids.metrics.event.CounterEvent;
import org.apache.doris.nereids.properties.LogicalProperties;
+import org.apache.doris.nereids.properties.UnboundLogicalProperties;
import org.apache.doris.nereids.trees.AbstractTreeNode;
import org.apache.doris.nereids.trees.expressions.ExprId;
import org.apache.doris.nereids.trees.expressions.Slot;
@@ -154,6 +156,9 @@ public abstract class AbstractPlan extends
AbstractTreeNode<Plan> implements Pla
@Override
public LogicalProperties getLogicalProperties() {
+ if (this instanceof UnboundRelation) {
+ return UnboundLogicalProperties.INSTANCE;
+ }
return logicalPropertiesSupplier.get();
}
}
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/logical/LogicalRelation.java
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/logical/LogicalRelation.java
index f3fab310c4..ce57dd0aa9 100644
---
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/logical/LogicalRelation.java
+++
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/logical/LogicalRelation.java
@@ -17,6 +17,7 @@
package org.apache.doris.nereids.trees.plans.logical;
+import org.apache.doris.catalog.OlapTable;
import org.apache.doris.catalog.Table;
import org.apache.doris.nereids.memo.GroupExpression;
import org.apache.doris.nereids.properties.LogicalProperties;
@@ -51,6 +52,12 @@ public abstract class LogicalRelation extends LogicalLeaf
implements Scan {
this(id, type, table, qualifier, Optional.empty(), Optional.empty(),
Collections.emptyList());
}
+ public LogicalRelation(RelationId id, PlanType type,
Optional<GroupExpression> groupExpression,
+ Optional<LogicalProperties> logicalProperties) {
+ this(id, type, new OlapTable(), Collections.emptyList(),
groupExpression,
+ logicalProperties, Collections.emptyList());
+ }
+
/**
* Constructor for LogicalRelationPlan.
*
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/logical/RelationUtil.java
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/logical/RelationUtil.java
new file mode 100644
index 0000000000..6e23637659
--- /dev/null
+++
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/logical/RelationUtil.java
@@ -0,0 +1,51 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package org.apache.doris.nereids.trees.plans.logical;
+
+import org.apache.doris.nereids.StatementContext;
+import org.apache.doris.nereids.trees.plans.RelationId;
+import org.apache.doris.qe.ConnectContext;
+
+import com.google.common.annotations.VisibleForTesting;
+
+/**
+ * relation util
+ */
+public class RelationUtil {
+ // for test only
+ private static StatementContext statementContext = new StatementContext();
+
+ public static RelationId newRelationId() {
+ // this branch is for test only
+ if (ConnectContext.get() == null ||
ConnectContext.get().getStatementContext() == null) {
+ return statementContext.getNextRelationId();
+ }
+ return ConnectContext.get().getStatementContext().getNextRelationId();
+ }
+
+ /**
+ * Reset Id Generator
+ */
+ @VisibleForTesting
+ public static void clear() throws Exception {
+ if (ConnectContext.get() != null) {
+ ConnectContext.get().setStatementContext(new StatementContext());
+ }
+ statementContext = new StatementContext();
+ }
+}
diff --git
a/fe/fe-core/src/test/java/org/apache/doris/nereids/glue/translator/PhysicalPlanTranslatorTest.java
b/fe/fe-core/src/test/java/org/apache/doris/nereids/glue/translator/PhysicalPlanTranslatorTest.java
index ab1f8250a3..2ce0f10c7a 100644
---
a/fe/fe-core/src/test/java/org/apache/doris/nereids/glue/translator/PhysicalPlanTranslatorTest.java
+++
b/fe/fe-core/src/test/java/org/apache/doris/nereids/glue/translator/PhysicalPlanTranslatorTest.java
@@ -29,7 +29,7 @@ import
org.apache.doris.nereids.trees.expressions.literal.IntegerLiteral;
import org.apache.doris.nereids.trees.expressions.literal.Literal;
import org.apache.doris.nereids.trees.plans.PreAggStatus;
import org.apache.doris.nereids.trees.plans.PushDownAggOperator;
-import org.apache.doris.nereids.trees.plans.RelationId;
+import org.apache.doris.nereids.trees.plans.logical.RelationUtil;
import org.apache.doris.nereids.trees.plans.physical.PhysicalFilter;
import org.apache.doris.nereids.trees.plans.physical.PhysicalOlapScan;
import org.apache.doris.nereids.trees.plans.physical.PhysicalProject;
@@ -63,7 +63,7 @@ public class PhysicalPlanTranslatorTest {
t1Output.add(col2);
t1Output.add(col3);
LogicalProperties t1Properties = new LogicalProperties(() -> t1Output);
- PhysicalOlapScan scan = new
PhysicalOlapScan(RelationId.createGenerator().getNextId(), t1, qualifier, 0L,
+ PhysicalOlapScan scan = new
PhysicalOlapScan(RelationUtil.newRelationId(), t1, qualifier, 0L,
Collections.emptyList(), Collections.emptyList(), null,
PreAggStatus.on(), PushDownAggOperator.NONE,
Optional.empty(),
t1Properties);
diff --git
a/fe/fe-core/src/test/java/org/apache/doris/nereids/jobs/RewriteTopDownJobTest.java
b/fe/fe-core/src/test/java/org/apache/doris/nereids/jobs/RewriteTopDownJobTest.java
index 5d2301a0a5..92894b39ad 100644
---
a/fe/fe-core/src/test/java/org/apache/doris/nereids/jobs/RewriteTopDownJobTest.java
+++
b/fe/fe-core/src/test/java/org/apache/doris/nereids/jobs/RewriteTopDownJobTest.java
@@ -29,10 +29,10 @@ import org.apache.doris.nereids.trees.expressions.Slot;
import org.apache.doris.nereids.trees.expressions.SlotReference;
import org.apache.doris.nereids.trees.plans.Plan;
import org.apache.doris.nereids.trees.plans.PlanType;
-import org.apache.doris.nereids.trees.plans.RelationId;
import org.apache.doris.nereids.trees.plans.logical.LogicalPlan;
import org.apache.doris.nereids.trees.plans.logical.LogicalProject;
import org.apache.doris.nereids.trees.plans.logical.LogicalRelation;
+import org.apache.doris.nereids.trees.plans.logical.RelationUtil;
import org.apache.doris.nereids.types.IntegerType;
import org.apache.doris.nereids.types.StringType;
import org.apache.doris.nereids.util.MemoTestUtils;
@@ -71,7 +71,7 @@ public class RewriteTopDownJobTest {
@Test
public void testSimplestScene() {
- Plan leaf = new UnboundRelation(Lists.newArrayList("test"));
+ Plan leaf = new UnboundRelation(RelationUtil.newRelationId(),
Lists.newArrayList("test"));
LogicalProject<Plan> project = new LogicalProject<>(ImmutableList.of(
new SlotReference("name", StringType.INSTANCE, true,
ImmutableList.of("test"))),
leaf
@@ -105,12 +105,12 @@ public class RewriteTopDownJobTest {
private static class LogicalBoundRelation extends LogicalRelation {
public LogicalBoundRelation(Table table, List<String> qualifier) {
- super(RelationId.createGenerator().getNextId(),
PlanType.LOGICAL_BOUND_RELATION, table, qualifier);
+ super(RelationUtil.newRelationId(),
PlanType.LOGICAL_BOUND_RELATION, table, qualifier);
}
public LogicalBoundRelation(Table table, List<String> qualifier,
Optional<GroupExpression> groupExpression,
Optional<LogicalProperties> logicalProperties) {
- super(RelationId.createGenerator().getNextId(),
PlanType.LOGICAL_BOUND_RELATION, table, qualifier,
+ super(RelationUtil.newRelationId(),
PlanType.LOGICAL_BOUND_RELATION, table, qualifier,
groupExpression, logicalProperties,
Collections.emptyList());
}
diff --git
a/fe/fe-core/src/test/java/org/apache/doris/nereids/jobs/cascades/DeriveStatsJobTest.java
b/fe/fe-core/src/test/java/org/apache/doris/nereids/jobs/cascades/DeriveStatsJobTest.java
index 97782f402a..4c93b6ba33 100644
---
a/fe/fe-core/src/test/java/org/apache/doris/nereids/jobs/cascades/DeriveStatsJobTest.java
+++
b/fe/fe-core/src/test/java/org/apache/doris/nereids/jobs/cascades/DeriveStatsJobTest.java
@@ -19,7 +19,6 @@ package org.apache.doris.nereids.jobs.cascades;
import org.apache.doris.catalog.Env;
import org.apache.doris.catalog.OlapTable;
-import org.apache.doris.common.AnalysisException;
import org.apache.doris.nereids.CascadesContext;
import org.apache.doris.nereids.jobs.JobContext;
import org.apache.doris.nereids.properties.LogicalProperties;
@@ -29,9 +28,9 @@ import
org.apache.doris.nereids.trees.expressions.SlotReference;
import
org.apache.doris.nereids.trees.expressions.functions.agg.AggregateFunction;
import org.apache.doris.nereids.trees.expressions.functions.agg.Sum;
import org.apache.doris.nereids.trees.plans.Plan;
-import org.apache.doris.nereids.trees.plans.RelationId;
import org.apache.doris.nereids.trees.plans.logical.LogicalAggregate;
import org.apache.doris.nereids.trees.plans.logical.LogicalOlapScan;
+import org.apache.doris.nereids.trees.plans.logical.RelationUtil;
import org.apache.doris.nereids.types.IntegerType;
import org.apache.doris.nereids.util.MemoTestUtils;
import org.apache.doris.nereids.util.PlanConstructor;
@@ -73,8 +72,7 @@ public class DeriveStatsJobTest {
Assertions.assertEquals(1, statistics.getRowCount());
}
- private LogicalOlapScan constructOlapSCan() throws AnalysisException {
-
+ private LogicalOlapScan constructOlapSCan() {
long tableId1 = 0;
List<String> qualifier = ImmutableList.of("test", "t");
@@ -85,7 +83,7 @@ public class DeriveStatsJobTest {
}};
OlapTable table1 = PlanConstructor.newOlapTable(tableId1, "t1", 0);
- return new LogicalOlapScan(RelationId.createGenerator().getNextId(),
table1, Collections.emptyList()).withLogicalProperties(
+ return new LogicalOlapScan(RelationUtil.newRelationId(), table1,
Collections.emptyList()).withLogicalProperties(
Optional.of(new LogicalProperties(() ->
ImmutableList.of(slot1))));
}
diff --git
a/fe/fe-core/src/test/java/org/apache/doris/nereids/memo/MemoTest.java
b/fe/fe-core/src/test/java/org/apache/doris/nereids/memo/MemoTest.java
index ef385bd37b..7ea4497961 100644
--- a/fe/fe-core/src/test/java/org/apache/doris/nereids/memo/MemoTest.java
+++ b/fe/fe-core/src/test/java/org/apache/doris/nereids/memo/MemoTest.java
@@ -18,7 +18,6 @@
package org.apache.doris.nereids.memo;
import org.apache.doris.catalog.OlapTable;
-import org.apache.doris.common.IdGenerator;
import org.apache.doris.common.jmockit.Deencapsulation;
import org.apache.doris.nereids.analyzer.UnboundRelation;
import org.apache.doris.nereids.analyzer.UnboundSlot;
@@ -33,13 +32,13 @@ import org.apache.doris.nereids.trees.plans.GroupPlan;
import org.apache.doris.nereids.trees.plans.JoinType;
import org.apache.doris.nereids.trees.plans.LeafPlan;
import org.apache.doris.nereids.trees.plans.Plan;
-import org.apache.doris.nereids.trees.plans.RelationId;
import org.apache.doris.nereids.trees.plans.logical.LogicalFilter;
import org.apache.doris.nereids.trees.plans.logical.LogicalJoin;
import org.apache.doris.nereids.trees.plans.logical.LogicalLimit;
import org.apache.doris.nereids.trees.plans.logical.LogicalOlapScan;
import org.apache.doris.nereids.trees.plans.logical.LogicalPlan;
import org.apache.doris.nereids.trees.plans.logical.LogicalProject;
+import org.apache.doris.nereids.trees.plans.logical.RelationUtil;
import org.apache.doris.nereids.types.StringType;
import org.apache.doris.nereids.util.MemoTestUtils;
import org.apache.doris.nereids.util.PatternMatchSupported;
@@ -54,10 +53,8 @@ import org.junit.jupiter.api.Test;
import java.util.ArrayList;
import java.util.Arrays;
-import java.util.List;
import java.util.Map;
import java.util.Objects;
-import java.util.Optional;
class MemoTest implements PatternMatchSupported {
@@ -146,7 +143,7 @@ class MemoTest implements PatternMatchSupported {
@Test
public void initByOneLevelPlan() {
OlapTable table = PlanConstructor.newOlapTable(0, "a", 1);
- LogicalOlapScan scan = new
LogicalOlapScan(RelationId.createGenerator().getNextId(), table);
+ LogicalOlapScan scan = new
LogicalOlapScan(RelationUtil.newRelationId(), table);
PlanChecker.from(connectContext, scan)
.checkGroupNum(1)
@@ -158,7 +155,7 @@ class MemoTest implements PatternMatchSupported {
@Test
public void initByTwoLevelChainPlan() {
OlapTable table = PlanConstructor.newOlapTable(0, "a", 1);
- LogicalOlapScan scan = new
LogicalOlapScan(RelationId.createGenerator().getNextId(), table);
+ LogicalOlapScan scan = new
LogicalOlapScan(RelationUtil.newRelationId(), table);
LogicalProject<LogicalOlapScan> topProject = new LogicalProject<>(
ImmutableList.of(scan.computeOutput().get(0)), scan);
@@ -174,26 +171,19 @@ class MemoTest implements PatternMatchSupported {
@Test
public void initByJoinSameUnboundTable() {
- UnboundRelation scanA = new UnboundRelation(ImmutableList.of("a"));
+ UnboundRelation scanA = new
UnboundRelation(RelationUtil.newRelationId(), ImmutableList.of("a"));
+ // when unboundRelation contains id, the case is illegal.
LogicalJoin<UnboundRelation, UnboundRelation> topJoin = new
LogicalJoin<>(JoinType.INNER_JOIN, scanA, scanA);
- PlanChecker.from(connectContext, topJoin)
- .checkGroupNum(3)
- .matches(
- logicalJoin(
- any().when(left -> Objects.equals(left,
scanA)),
- any().when(right -> Objects.equals(right,
scanA))
- ).when(root -> Objects.equals(root, topJoin))
- );
+ Assertions.assertThrows(IllegalStateException.class, () ->
PlanChecker.from(connectContext, topJoin));
}
@Test
public void initByJoinSameLogicalTable() {
- IdGenerator<RelationId> generator = RelationId.createGenerator();
OlapTable tableA = PlanConstructor.newOlapTable(0, "a", 1);
- LogicalOlapScan scanA = new LogicalOlapScan(generator.getNextId(),
tableA);
- LogicalOlapScan scanA1 = new LogicalOlapScan(generator.getNextId(),
tableA);
+ LogicalOlapScan scanA = new
LogicalOlapScan(RelationUtil.newRelationId(), tableA);
+ LogicalOlapScan scanA1 = new
LogicalOlapScan(RelationUtil.newRelationId(), tableA);
LogicalJoin<LogicalOlapScan, LogicalOlapScan> topJoin = new
LogicalJoin<>(JoinType.INNER_JOIN, scanA, scanA1);
@@ -209,11 +199,10 @@ class MemoTest implements PatternMatchSupported {
@Test
public void initByTwoLevelJoinPlan() {
- IdGenerator<RelationId> generator = RelationId.createGenerator();
OlapTable tableA = PlanConstructor.newOlapTable(0, "a", 1);
OlapTable tableB = PlanConstructor.newOlapTable(0, "b", 1);
- LogicalOlapScan scanA = new LogicalOlapScan(generator.getNextId(),
tableA);
- LogicalOlapScan scanB = new LogicalOlapScan(generator.getNextId(),
tableB);
+ LogicalOlapScan scanA = new
LogicalOlapScan(RelationUtil.newRelationId(), tableA);
+ LogicalOlapScan scanB = new
LogicalOlapScan(RelationUtil.newRelationId(), tableB);
LogicalJoin<LogicalOlapScan, LogicalOlapScan> topJoin = new
LogicalJoin<>(JoinType.INNER_JOIN, scanA, scanB);
@@ -230,7 +219,7 @@ class MemoTest implements PatternMatchSupported {
@Test
public void initByThreeLevelChainPlan() {
OlapTable table = PlanConstructor.newOlapTable(0, "a", 1);
- LogicalOlapScan scan = new
LogicalOlapScan(RelationId.createGenerator().getNextId(), table);
+ LogicalOlapScan scan = new
LogicalOlapScan(RelationUtil.newRelationId(), table);
LogicalProject<LogicalOlapScan> project = new LogicalProject<>(
ImmutableList.of(scan.computeOutput().get(0)), scan);
@@ -250,15 +239,14 @@ class MemoTest implements PatternMatchSupported {
@Test
public void initByThreeLevelBushyPlan() {
- IdGenerator<RelationId> generator = RelationId.createGenerator();
OlapTable tableA = PlanConstructor.newOlapTable(0, "a", 1);
OlapTable tableB = PlanConstructor.newOlapTable(0, "b", 1);
OlapTable tableC = PlanConstructor.newOlapTable(0, "c", 1);
OlapTable tableD = PlanConstructor.newOlapTable(0, "d", 1);
- LogicalOlapScan scanA = new LogicalOlapScan(generator.getNextId(),
tableA);
- LogicalOlapScan scanB = new LogicalOlapScan(generator.getNextId(),
tableB);
- LogicalOlapScan scanC = new LogicalOlapScan(generator.getNextId(),
tableC);
- LogicalOlapScan scanD = new LogicalOlapScan(generator.getNextId(),
tableD);
+ LogicalOlapScan scanA = new
LogicalOlapScan(RelationUtil.newRelationId(), tableA);
+ LogicalOlapScan scanB = new
LogicalOlapScan(RelationUtil.newRelationId(), tableB);
+ LogicalOlapScan scanC = new
LogicalOlapScan(RelationUtil.newRelationId(), tableC);
+ LogicalOlapScan scanD = new
LogicalOlapScan(RelationUtil.newRelationId(), tableD);
LogicalJoin<LogicalOlapScan, LogicalOlapScan> leftJoin = new
LogicalJoin<>(JoinType.CROSS_JOIN, scanA, scanB);
LogicalJoin<LogicalOlapScan, LogicalOlapScan> rightJoin = new
LogicalJoin<>(JoinType.CROSS_JOIN, scanC, scanD);
@@ -284,11 +272,11 @@ class MemoTest implements PatternMatchSupported {
/*
* A -> A:
*
- * unboundRelation(student) -> unboundRelation(student)
+ * UnboundRelation(student) -> UnboundRelation(student)
*/
@Test
public void a2a() {
- UnboundRelation student = new
UnboundRelation(ImmutableList.of("student"));
+ UnboundRelation student = new
UnboundRelation(RelationUtil.newRelationId(), ImmutableList.of("student"));
PlanChecker.from(connectContext, student)
.applyBottomUp(
unboundRelation().then(scan -> scan)
@@ -300,13 +288,13 @@ class MemoTest implements PatternMatchSupported {
/*
* A -> B:
*
- * unboundRelation(student) -> logicalOlapScan(student)
+ * UnboundRelation(student) -> logicalOlapScan(student)
*/
@Test
public void a2b() {
- LogicalOlapScan student = new
LogicalOlapScan(RelationId.createGenerator().getNextId(),
PlanConstructor.student);
+ LogicalOlapScan student = new
LogicalOlapScan(RelationUtil.newRelationId(), PlanConstructor.student);
- PlanChecker.from(connectContext, new
UnboundRelation(ImmutableList.of("student")))
+ PlanChecker.from(connectContext, new
UnboundRelation(RelationUtil.newRelationId(), ImmutableList.of("student")))
.applyBottomUp(
unboundRelation().then(scan -> student)
)
@@ -321,13 +309,13 @@ class MemoTest implements PatternMatchSupported {
*/
@Test
public void a2newA() {
- LogicalOlapScan student = new
LogicalOlapScan(RelationId.createGenerator().getNextId(),
PlanConstructor.student);
+ LogicalOlapScan student = new
LogicalOlapScan(RelationUtil.newRelationId(), PlanConstructor.student);
PlanChecker.from(connectContext, student)
.applyBottomUp(
logicalOlapScan()
.when(scan -> student == scan)
- .then(scan -> new
LogicalOlapScan(RelationId.createGenerator().getNextId(),
PlanConstructor.student))
+ .then(scan -> new
LogicalOlapScan(RelationUtil.newRelationId(), PlanConstructor.student))
)
.checkGroupNum(1)
.matchesFromRoot(logicalOlapScan().when(student::equals));
@@ -336,16 +324,16 @@ class MemoTest implements PatternMatchSupported {
/*
* A -> B(C):
*
- * unboundRelation(student) limit(1)
+ * UnboundRelation(student) limit(1)
* -> |
* logicalOlapScan(student)
*/
@Test
public void a2bc() {
- LogicalOlapScan student = new
LogicalOlapScan(RelationId.createGenerator().getNextId(),
PlanConstructor.student);
+ LogicalOlapScan student = new
LogicalOlapScan(RelationUtil.newRelationId(), PlanConstructor.student);
LogicalLimit<LogicalOlapScan> limit = new LogicalLimit<>(1, 0,
student);
- PlanChecker.from(connectContext, new
UnboundRelation(ImmutableList.of("student")))
+ PlanChecker.from(connectContext, new
UnboundRelation(RelationUtil.newRelationId(), ImmutableList.of("student")))
.applyBottomUp(
unboundRelation().then(unboundRelation ->
limit.withChildren(student))
)
@@ -360,9 +348,9 @@ class MemoTest implements PatternMatchSupported {
/*
* A -> B(A): will run into dead loop, so we detect it and throw exception.
*
- * unboundRelation(student) limit(1)
limit(1)
+ * UnboundRelation(student) limit(1)
limit(1)
* -> | ->
| -> ...
- * unboundRelation(student)
unboundRelation(student)
+ * UnboundRelation(student)
UnboundRelation(student)
*
* you should split A into some states:
* 1. A(not rewrite)
@@ -377,12 +365,12 @@ class MemoTest implements PatternMatchSupported {
public void a2ba() {
// invalid case
Assertions.assertThrows(IllegalStateException.class, () -> {
- UnboundRelation student = new
UnboundRelation(ImmutableList.of("student"));
+ UnboundRelation student = new
UnboundRelation(RelationUtil.newRelationId(), ImmutableList.of("student"));
LogicalLimit<UnboundRelation> limit = new LogicalLimit<>(1, 0,
student);
PlanChecker.from(connectContext, student)
.applyBottomUp(
- unboundRelation().then(unboundRelation ->
limit.withChildren(unboundRelation))
+ unboundRelation().then(limit::withChildren)
)
.checkGroupNum(2)
.matchesFromRoot(
@@ -392,56 +380,23 @@ class MemoTest implements PatternMatchSupported {
);
});
- // valid case: 5 steps
- class A extends UnboundRelation {
- // 1: declare the Plan has some states
- final State state;
-
- public A(List<String> nameParts, State state) {
- this(nameParts, state, Optional.empty());
- }
-
- public A(List<String> nameParts, State state,
Optional<GroupExpression> groupExpression) {
- super(nameParts, groupExpression, Optional.empty());
- this.state = state;
- }
-
- // 2: overwrite the 'equals' method that compare state
- @Override
- public boolean equals(Object o) {
- return super.equals(o) && state == ((A) o).state;
- }
-
- // 3: declare 'withState' method, and clear groupExpression(means
create new group when rewrite)
- public A withState(State state) {
- return new A(getNameParts(), state, Optional.empty());
- }
-
- @Override
- public Plan withGroupExpression(Optional<GroupExpression>
groupExpression) {
- return new A(getNameParts(), state, groupExpression);
- }
-
- @Override
- public String toString() {
- return "A{namePart=" + getNameParts() + ", state=" + state +
'}';
- }
- }
-
- A a = new A(ImmutableList.of("student"), State.NOT_REWRITE);
-
- A a2 = new A(ImmutableList.of("student"), State.ALREADY_REWRITE);
- LogicalLimit<UnboundRelation> limit = new LogicalLimit<>(1, 0, a2);
+ // use relation id to divide different unbound relation.
+ UnboundRelation a = new UnboundRelation(RelationUtil.newRelationId(),
ImmutableList.of("student"));
- PlanChecker.from(connectContext, a).applyBottomUp(unboundRelation()
- // 4: add state condition to the pattern's predicates
- .when(r -> (r instanceof A) && ((A) r).state ==
State.NOT_REWRITE).then(unboundRelation -> {
- // 5: new plan and change state, so this case
equal to 'A -> B(C)', which C has
- // different state with A
- A notRewritePlan = (A) unboundRelation;
- return
limit.withChildren(notRewritePlan.withState(State.ALREADY_REWRITE));
- })).checkGroupNum(2)
-
.matchesFromRoot(logicalLimit(unboundRelation().when(a2::equals)).when(limit::equals));
+ UnboundRelation a2 = new UnboundRelation(RelationUtil.newRelationId(),
ImmutableList.of("student"));
+ LogicalLimit<UnboundRelation> limit = new LogicalLimit<>(1, 0, a2);
+ PlanChecker.from(connectContext, a)
+ .setMaxInvokeTimesPerRule(1000)
+ .applyBottomUp(
+ unboundRelation()
+ .when(unboundRelation ->
unboundRelation.getId().equals(a.getId()))
+ .then(unboundRelation -> limit.withChildren(
+ new UnboundRelation(a2.getId(),
unboundRelation.getNameParts()))))
+ .checkGroupNum(2)
+ .matchesFromRoot(
+ logicalLimit(
+ unboundRelation().when(a2::equals)
+ ).when(limit::equals));
}
/*
@@ -468,9 +423,9 @@ class MemoTest implements PatternMatchSupported {
/*@Test()
public void a2ab() {
Assertions.assertThrows(IllegalStateException.class, () -> {
- UnboundRelation student = new
UnboundRelation(ImmutableList.of("student"));
+ UnboundRelation student = new
UnboundRelation(RelationUtil.newRelationId(), ImmutableList.of("student"));
LogicalLimit<UnboundRelation> limit = new LogicalLimit<>(1, 0,
student);
- LogicalOlapScan boundStudent = new
LogicalOlapScan(RelationId.createGenerator().getNextId(),
PlanConstructor.student);
+ LogicalOlapScan boundStudent = new
LogicalOlapScan(RelationUtil.newRelationId(), PlanConstructor.student);
CascadesContext cascadesContext =
MemoTestUtils.createCascadesContext(connectContext, limit);
PlanChecker.from(cascadesContext)
@@ -485,7 +440,7 @@ class MemoTest implements PatternMatchSupported {
/*
* A -> B(C(D)):
*
- * unboundRelation(student) -> logicalLimit(10)
+ * UnboundRelation(student) -> logicalLimit(10)
* |
* logicalLimit(5)
* |
@@ -493,7 +448,7 @@ class MemoTest implements PatternMatchSupported {
*/
@Test
public void a2bcd() {
- LogicalOlapScan scan = new
LogicalOlapScan(RelationId.createGenerator().getNextId(),
PlanConstructor.student);
+ LogicalOlapScan scan = new
LogicalOlapScan(RelationUtil.newRelationId(), PlanConstructor.student);
LogicalLimit<LogicalOlapScan> limit5 = new LogicalLimit<>(5, 0, scan);
LogicalLimit<LogicalLimit<LogicalOlapScan>> limit10 = new
LogicalLimit<>(10, 0, limit5);
@@ -521,7 +476,7 @@ class MemoTest implements PatternMatchSupported {
*/
@Test
public void ab2a() {
- LogicalOlapScan student = new
LogicalOlapScan(RelationId.createGenerator().getNextId(),
PlanConstructor.student);
+ LogicalOlapScan student = new
LogicalOlapScan(RelationUtil.newRelationId(), PlanConstructor.student);
LogicalLimit<LogicalOlapScan> limit10 = new LogicalLimit<>(10, 0,
student);
PlanChecker.from(connectContext, limit10)
@@ -545,7 +500,7 @@ class MemoTest implements PatternMatchSupported {
*/
@Test
public void ab2NewA() {
- LogicalOlapScan student = new
LogicalOlapScan(RelationId.createGenerator().getNextId(),
PlanConstructor.student);
+ LogicalOlapScan student = new
LogicalOlapScan(RelationUtil.newRelationId(), PlanConstructor.student);
LogicalLimit<LogicalOlapScan> limit10 = new LogicalLimit<>(10, 0,
student);
PlanChecker.from(connectContext, limit10)
@@ -569,7 +524,7 @@ class MemoTest implements PatternMatchSupported {
*/
@Test
public void ab2GroupB() {
- LogicalOlapScan student = new
LogicalOlapScan(RelationId.createGenerator().getNextId(),
PlanConstructor.student);
+ LogicalOlapScan student = new
LogicalOlapScan(RelationUtil.newRelationId(), PlanConstructor.student);
LogicalLimit<LogicalOlapScan> limit10 = new LogicalLimit<>(10, 0,
student);
PlanChecker.from(connectContext, limit10)
@@ -591,7 +546,7 @@ class MemoTest implements PatternMatchSupported {
*/
@Test
public void ab2PlanB() {
- LogicalOlapScan student = new
LogicalOlapScan(RelationId.createGenerator().getNextId(),
PlanConstructor.student);
+ LogicalOlapScan student = new
LogicalOlapScan(RelationUtil.newRelationId(), PlanConstructor.student);
LogicalLimit<LogicalOlapScan> limit10 = new LogicalLimit<>(10, 0,
student);
PlanChecker.from(connectContext, limit10)
@@ -609,14 +564,14 @@ class MemoTest implements PatternMatchSupported {
*
* limit(10)
* | -> logicalOlapScan(student)
- * unboundRelation(student)
+ * UnboundRelation(RelationUtil.newRelationId(), student)
*/
@Test
public void ab2c() {
- UnboundRelation relation = new
UnboundRelation(ImmutableList.of("student"));
+ UnboundRelation relation = new
UnboundRelation(RelationUtil.newRelationId(), ImmutableList.of("student"));
LogicalLimit<UnboundRelation> limit10 = new LogicalLimit<>(10, 0,
relation);
- LogicalOlapScan student = new
LogicalOlapScan(RelationId.createGenerator().getNextId(),
PlanConstructor.student);
+ LogicalOlapScan student = new
LogicalOlapScan(RelationUtil.newRelationId(), PlanConstructor.student);
PlanChecker.from(connectContext, limit10)
.applyBottomUp(
logicalLimit(unboundRelation()).then(limit -> student)
@@ -632,14 +587,14 @@ class MemoTest implements PatternMatchSupported {
*
* limit(10) limit(5)
* | -> |
- * unboundRelation(student) logicalOlapScan(student)
+ * UnboundRelation(student) logicalOlapScan(student)
*/
@Test
public void ab2cd() {
- UnboundRelation relation = new
UnboundRelation(ImmutableList.of("student"));
+ UnboundRelation relation = new
UnboundRelation(RelationUtil.newRelationId(), ImmutableList.of("student"));
LogicalLimit<UnboundRelation> limit10 = new LogicalLimit<>(10, 0,
relation);
- LogicalOlapScan student = new
LogicalOlapScan(RelationId.createGenerator().getNextId(),
PlanConstructor.student);
+ LogicalOlapScan student = new
LogicalOlapScan(RelationUtil.newRelationId(), PlanConstructor.student);
LogicalLimit<LogicalOlapScan> limit5 = new LogicalLimit<>(5, 0,
student);
PlanChecker.from(connectContext, limit10)
@@ -664,7 +619,7 @@ class MemoTest implements PatternMatchSupported {
*/
@Test
public void ab2cb() {
- LogicalOlapScan student = new
LogicalOlapScan(RelationId.createGenerator().getNextId(),
PlanConstructor.student);
+ LogicalOlapScan student = new
LogicalOlapScan(RelationUtil.newRelationId(), PlanConstructor.student);
LogicalLimit<LogicalOlapScan> limit10 = new LogicalLimit<>(10, 0,
student);
LogicalLimit<LogicalOlapScan> limit5 = new LogicalLimit<>(5, 0,
student);
@@ -695,14 +650,14 @@ class MemoTest implements PatternMatchSupported {
public void ab2NewANewB() {
Assertions.assertThrowsExactly(IllegalStateException.class, () -> {
- LogicalOlapScan student = new
LogicalOlapScan(RelationId.createGenerator().getNextId(),
PlanConstructor.student);
+ LogicalOlapScan student = new
LogicalOlapScan(RelationUtil.newRelationId(), PlanConstructor.student);
LogicalLimit<LogicalOlapScan> limit10 = new LogicalLimit<>(10, 0,
student);
PlanChecker.from(connectContext, limit10)
.setMaxInvokeTimesPerRule(1000)
.applyBottomUp(
logicalLimit().when(limit10::equals).then(limit ->
limit.withChildren(
- new
LogicalOlapScan(RelationId.createGenerator().getNextId(),
PlanConstructor.student)
+ new
LogicalOlapScan(RelationUtil.newRelationId(), PlanConstructor.student)
))
);
});
@@ -720,7 +675,7 @@ class MemoTest implements PatternMatchSupported {
@Test
public void ab2ba() {
Assertions.assertThrowsExactly(IllegalStateException.class, () -> {
- UnboundRelation student = new
UnboundRelation(ImmutableList.of("student"));
+ UnboundRelation student = new
UnboundRelation(RelationUtil.newRelationId(), ImmutableList.of("student"));
LogicalLimit<UnboundRelation> limit5 = new LogicalLimit<>(5, 0,
student);
LogicalLimit<LogicalLimit<UnboundRelation>> limit10 = new
LogicalLimit<>(10, 0, limit5);
@@ -741,16 +696,16 @@ class MemoTest implements PatternMatchSupported {
*
* logicalLimit(3) -> logicalLimit(10)
* | |
- * unboundRelation(student) logicalLimit(5)
+ * UnboundRelation(student) logicalLimit(5)
* |
* logicalOlapScan(student)))
*/
@Test
public void ab2cde() {
- UnboundRelation student = new
UnboundRelation(ImmutableList.of("student"));
+ UnboundRelation student = new
UnboundRelation(RelationUtil.newRelationId(), ImmutableList.of("student"));
LogicalLimit<UnboundRelation> limit3 = new LogicalLimit<>(3, 0,
student);
- LogicalOlapScan scan = new
LogicalOlapScan(RelationId.createGenerator().getNextId(),
PlanConstructor.student);
+ LogicalOlapScan scan = new
LogicalOlapScan(RelationUtil.newRelationId(), PlanConstructor.student);
LogicalLimit<LogicalOlapScan> limit5 = new LogicalLimit<>(5, 0, scan);
LogicalLimit<LogicalLimit<LogicalOlapScan>> limit10 = new
LogicalLimit<>(10, 0, limit5);
@@ -779,7 +734,7 @@ class MemoTest implements PatternMatchSupported {
*/
@Test
public void abc2bac() {
- UnboundRelation student = new
UnboundRelation(ImmutableList.of("student"));
+ UnboundRelation student = new
UnboundRelation(RelationUtil.newRelationId(), ImmutableList.of("student"));
LogicalLimit<UnboundRelation> limit5 = new LogicalLimit<>(5, 0,
student);
LogicalLimit<LogicalLimit<UnboundRelation>> limit10 = new
LogicalLimit<>(10, 0, limit5);
@@ -818,7 +773,7 @@ class MemoTest implements PatternMatchSupported {
*/
@Test
public void abc2bc() {
- UnboundRelation student = new
UnboundRelation(ImmutableList.of("student"));
+ UnboundRelation student = new
UnboundRelation(RelationUtil.newRelationId(), ImmutableList.of("student"));
LogicalLimit<UnboundRelation> limit5 = new LogicalLimit<>(5, 0,
student);
LogicalLimit<LogicalLimit<UnboundRelation>> limit10 = new
LogicalLimit<>(10, 0, limit5);
@@ -843,10 +798,10 @@ class MemoTest implements PatternMatchSupported {
@Test
public void testRewriteBottomPlanToOnePlan() {
- LogicalOlapScan student = new
LogicalOlapScan(RelationId.createGenerator().getNextId(),
PlanConstructor.student);
+ LogicalOlapScan student = new
LogicalOlapScan(RelationUtil.newRelationId(), PlanConstructor.student);
LogicalLimit<LogicalOlapScan> limit = new LogicalLimit<>(1, 0,
student);
- LogicalOlapScan score = new
LogicalOlapScan(RelationId.createGenerator().getNextId(),
PlanConstructor.score);
+ LogicalOlapScan score = new
LogicalOlapScan(RelationUtil.newRelationId(), PlanConstructor.score);
PlanChecker.from(connectContext, limit)
.applyBottomUp(
@@ -862,10 +817,10 @@ class MemoTest implements PatternMatchSupported {
@Test
public void testRewriteBottomPlanToMultiPlan() {
- LogicalOlapScan student = new
LogicalOlapScan(RelationId.createGenerator().getNextId(),
PlanConstructor.student);
+ LogicalOlapScan student = new
LogicalOlapScan(RelationUtil.newRelationId(), PlanConstructor.student);
LogicalLimit<LogicalOlapScan> limit10 = new LogicalLimit<>(10, 0,
student);
- LogicalOlapScan score = new
LogicalOlapScan(RelationId.createGenerator().getNextId(),
PlanConstructor.score);
+ LogicalOlapScan score = new
LogicalOlapScan(RelationUtil.newRelationId(), PlanConstructor.score);
LogicalLimit<LogicalOlapScan> limit1 = new LogicalLimit<>(1, 0, score);
PlanChecker.from(connectContext, limit10)
@@ -884,8 +839,8 @@ class MemoTest implements PatternMatchSupported {
@Test
public void testRewriteUnboundPlanToBound() {
- UnboundRelation unboundTable = new
UnboundRelation(ImmutableList.of("score"));
- LogicalOlapScan boundTable = new
LogicalOlapScan(RelationId.createGenerator().getNextId(),
PlanConstructor.score);
+ UnboundRelation unboundTable = new
UnboundRelation(RelationUtil.newRelationId(), ImmutableList.of("score"));
+ LogicalOlapScan boundTable = new
LogicalOlapScan(RelationUtil.newRelationId(), PlanConstructor.score);
PlanChecker.from(connectContext, unboundTable)
.checkMemo(memo -> {
@@ -906,10 +861,10 @@ class MemoTest implements PatternMatchSupported {
@Test
public void testRecomputeLogicalProperties() {
- UnboundRelation unboundTable = new
UnboundRelation(ImmutableList.of("score"));
+ UnboundRelation unboundTable = new
UnboundRelation(RelationUtil.newRelationId(), ImmutableList.of("score"));
LogicalLimit<UnboundRelation> unboundLimit = new LogicalLimit<>(1, 0,
unboundTable);
- LogicalOlapScan boundTable = new
LogicalOlapScan(RelationId.createGenerator().getNextId(),
PlanConstructor.score);
+ LogicalOlapScan boundTable = new
LogicalOlapScan(RelationUtil.newRelationId(), PlanConstructor.score);
LogicalLimit<Plan> boundLimit =
unboundLimit.withChildren(ImmutableList.of(boundTable));
PlanChecker.from(connectContext, unboundLimit)
@@ -938,7 +893,7 @@ class MemoTest implements PatternMatchSupported {
@Test
public void testEliminateRootWithChildGroupInTwoLevels() {
- LogicalOlapScan scan = new
LogicalOlapScan(RelationId.createGenerator().getNextId(),
PlanConstructor.score);
+ LogicalOlapScan scan = new
LogicalOlapScan(RelationUtil.newRelationId(), PlanConstructor.score);
LogicalLimit<Plan> limit = new LogicalLimit<>(1, 0, scan);
PlanChecker.from(connectContext, limit)
@@ -950,7 +905,7 @@ class MemoTest implements PatternMatchSupported {
@Test
public void testEliminateRootWithChildPlanInTwoLevels() {
- LogicalOlapScan scan = new
LogicalOlapScan(RelationId.createGenerator().getNextId(),
PlanConstructor.score);
+ LogicalOlapScan scan = new
LogicalOlapScan(RelationUtil.newRelationId(), PlanConstructor.score);
LogicalLimit<Plan> limit = new LogicalLimit<>(1, 0, scan);
PlanChecker.from(connectContext, limit)
@@ -962,10 +917,10 @@ class MemoTest implements PatternMatchSupported {
@Test
public void testEliminateTwoLevelsToOnePlan() {
- LogicalOlapScan score = new
LogicalOlapScan(RelationId.createGenerator().getNextId(),
PlanConstructor.score);
+ LogicalOlapScan score = new
LogicalOlapScan(RelationUtil.newRelationId(), PlanConstructor.score);
LogicalLimit<Plan> limit = new LogicalLimit<>(1, 0, score);
- LogicalOlapScan student = new
LogicalOlapScan(RelationId.createGenerator().getNextId(),
PlanConstructor.student);
+ LogicalOlapScan student = new
LogicalOlapScan(RelationUtil.newRelationId(), PlanConstructor.student);
PlanChecker.from(connectContext, limit)
.applyBottomUp(logicalLimit(any()).then(l -> student))
@@ -982,10 +937,10 @@ class MemoTest implements PatternMatchSupported {
@Test
public void testEliminateTwoLevelsToTwoPlans() {
- LogicalOlapScan score = new
LogicalOlapScan(RelationId.createGenerator().getNextId(),
PlanConstructor.score);
+ LogicalOlapScan score = new
LogicalOlapScan(RelationUtil.newRelationId(), PlanConstructor.score);
LogicalLimit<Plan> limit1 = new LogicalLimit<>(1, 0, score);
- LogicalOlapScan student = new
LogicalOlapScan(RelationId.createGenerator().getNextId(),
PlanConstructor.student);
+ LogicalOlapScan student = new
LogicalOlapScan(RelationUtil.newRelationId(), PlanConstructor.student);
LogicalLimit<Plan> limit10 = new LogicalLimit<>(10, 0, student);
PlanChecker.from(connectContext, limit1)
@@ -1015,8 +970,8 @@ class MemoTest implements PatternMatchSupported {
.analyze(new LogicalLimit<>(10, 0,
new LogicalJoin<>(JoinType.LEFT_OUTER_JOIN,
ImmutableList.of(new EqualTo(new
UnboundSlot("sid"), new UnboundSlot("id"))),
- new
LogicalOlapScan(RelationId.createGenerator().getNextId(),
PlanConstructor.score),
- new
LogicalOlapScan(RelationId.createGenerator().getNextId(),
PlanConstructor.student)
+ new
LogicalOlapScan(RelationUtil.newRelationId(), PlanConstructor.score),
+ new
LogicalOlapScan(RelationUtil.newRelationId(), PlanConstructor.student)
)
))
.applyTopDown(
@@ -1070,7 +1025,7 @@ class MemoTest implements PatternMatchSupported {
*/
@Test
public void testRewriteMiddlePlans() {
- UnboundRelation unboundRelation = new
UnboundRelation(Lists.newArrayList("test"));
+ UnboundRelation unboundRelation = new
UnboundRelation(RelationUtil.newRelationId(), Lists.newArrayList("test"));
LogicalProject insideProject = new LogicalProject<>(
ImmutableList.of(new SlotReference("name",
StringType.INSTANCE, true, ImmutableList.of("test"))),
unboundRelation
@@ -1127,7 +1082,7 @@ class MemoTest implements PatternMatchSupported {
*/
@Test
public void testEliminateRootWithChildPlanThreeLevels() {
- UnboundRelation unboundRelation = new
UnboundRelation(Lists.newArrayList("test"));
+ UnboundRelation unboundRelation = new
UnboundRelation(RelationUtil.newRelationId(), Lists.newArrayList("test"));
LogicalProject<UnboundRelation> insideProject = new LogicalProject<>(
ImmutableList.of(new SlotReference("inside",
StringType.INSTANCE, true, ImmutableList.of("test"))),
unboundRelation
diff --git
a/fe/fe-core/src/test/java/org/apache/doris/nereids/pattern/GroupExpressionMatchingTest.java
b/fe/fe-core/src/test/java/org/apache/doris/nereids/pattern/GroupExpressionMatchingTest.java
index 2ac4ec596f..bb6b1d4948 100644
---
a/fe/fe-core/src/test/java/org/apache/doris/nereids/pattern/GroupExpressionMatchingTest.java
+++
b/fe/fe-core/src/test/java/org/apache/doris/nereids/pattern/GroupExpressionMatchingTest.java
@@ -29,6 +29,7 @@ import org.apache.doris.nereids.trees.plans.PlanType;
import org.apache.doris.nereids.trees.plans.logical.LogicalFilter;
import org.apache.doris.nereids.trees.plans.logical.LogicalJoin;
import org.apache.doris.nereids.trees.plans.logical.LogicalProject;
+import org.apache.doris.nereids.trees.plans.logical.RelationUtil;
import org.apache.doris.nereids.trees.plans.visitor.PlanVisitor;
import com.google.common.collect.ImmutableList;
@@ -44,7 +45,7 @@ public class GroupExpressionMatchingTest {
public void testLeafNode() {
Pattern pattern = new Pattern<>(PlanType.LOGICAL_UNBOUND_RELATION);
- Memo memo = new Memo(new UnboundRelation(Lists.newArrayList("test")));
+ Memo memo = new Memo(new UnboundRelation(RelationUtil.newRelationId(),
Lists.newArrayList("test")));
GroupExpressionMatching groupExpressionMatching
= new GroupExpressionMatching(pattern,
memo.getRoot().getLogicalExpression());
@@ -61,11 +62,11 @@ public class GroupExpressionMatchingTest {
Pattern pattern = new Pattern<>(PlanType.LOGICAL_PROJECT,
new Pattern<>(PlanType.LOGICAL_UNBOUND_RELATION));
- Plan leaf = new UnboundRelation(Lists.newArrayList("test"));
+ Plan leaf = new UnboundRelation(RelationUtil.newRelationId(),
Lists.newArrayList("test"));
LogicalProject root = new LogicalProject(Lists.newArrayList(), leaf);
Memo memo = new Memo(root);
- Plan anotherLeaf = new UnboundRelation(Lists.newArrayList("test2"));
+ Plan anotherLeaf = new UnboundRelation(RelationUtil.newRelationId(),
Lists.newArrayList("test2"));
memo.copyIn(anotherLeaf,
memo.getRoot().getLogicalExpression().child(0), false);
GroupExpressionMatching groupExpressionMatching
@@ -90,11 +91,11 @@ public class GroupExpressionMatchingTest {
public void testDepth2WithGroup() {
Pattern pattern = new Pattern<>(PlanType.LOGICAL_PROJECT,
Pattern.GROUP);
- Plan leaf = new UnboundRelation(Lists.newArrayList("test"));
+ Plan leaf = new UnboundRelation(RelationUtil.newRelationId(),
Lists.newArrayList("test"));
LogicalProject root = new LogicalProject(Lists.newArrayList(), leaf);
Memo memo = new Memo(root);
- Plan anotherLeaf = new UnboundRelation(Lists.newArrayList("test2"));
+ Plan anotherLeaf = new UnboundRelation(RelationUtil.newRelationId(),
Lists.newArrayList("test2"));
memo.copyIn(anotherLeaf,
memo.getRoot().getLogicalExpression().child(0), false);
GroupExpressionMatching groupExpressionMatching
@@ -114,7 +115,7 @@ public class GroupExpressionMatchingTest {
public void testLeafAny() {
Pattern pattern = Pattern.ANY;
- Memo memo = new Memo(new UnboundRelation(Lists.newArrayList("test")));
+ Memo memo = new Memo(new UnboundRelation(RelationUtil.newRelationId(),
Lists.newArrayList("test")));
GroupExpressionMatching groupExpressionMatching
= new GroupExpressionMatching(pattern,
memo.getRoot().getLogicalExpression());
@@ -129,10 +130,10 @@ public class GroupExpressionMatchingTest {
@Test
public void testAnyWithChild() {
Plan root = new LogicalProject(Lists.newArrayList(),
- new UnboundRelation(Lists.newArrayList("test")));
+ new UnboundRelation(RelationUtil.newRelationId(),
Lists.newArrayList("test")));
Memo memo = new Memo(root);
- Plan anotherLeaf = new UnboundRelation(ImmutableList.of("test2"));
+ Plan anotherLeaf = new UnboundRelation(RelationUtil.newRelationId(),
ImmutableList.of("test2"));
memo.copyIn(anotherLeaf,
memo.getRoot().getLogicalExpression().child(0), false);
GroupExpressionMatching groupExpressionMatching
@@ -151,8 +152,8 @@ public class GroupExpressionMatchingTest {
@Test
public void testInnerLogicalJoinMatch() {
Plan root = new LogicalJoin(JoinType.INNER_JOIN,
- new UnboundRelation(ImmutableList.of("a")),
- new UnboundRelation(ImmutableList.of("b"))
+ new UnboundRelation(RelationUtil.newRelationId(),
ImmutableList.of("a")),
+ new UnboundRelation(RelationUtil.newRelationId(),
ImmutableList.of("b"))
);
Memo memo = new Memo(root);
@@ -173,8 +174,8 @@ public class GroupExpressionMatchingTest {
@Test
public void testInnerLogicalJoinMismatch() {
Plan root = new LogicalJoin(JoinType.LEFT_OUTER_JOIN,
- new UnboundRelation(ImmutableList.of("a")),
- new UnboundRelation(ImmutableList.of("b"))
+ new UnboundRelation(RelationUtil.newRelationId(),
ImmutableList.of("a")),
+ new UnboundRelation(RelationUtil.newRelationId(),
ImmutableList.of("b"))
);
Memo memo = new Memo(root);
@@ -190,8 +191,8 @@ public class GroupExpressionMatchingTest {
@Test
public void testTopMatchButChildrenNotMatch() {
Plan root = new LogicalJoin(JoinType.LEFT_OUTER_JOIN,
- new UnboundRelation(ImmutableList.of("a")),
- new UnboundRelation(ImmutableList.of("b"))
+ new UnboundRelation(RelationUtil.newRelationId(),
ImmutableList.of("a")),
+ new UnboundRelation(RelationUtil.newRelationId(),
ImmutableList.of("b"))
);
Memo memo = new Memo(root);
@@ -212,9 +213,9 @@ public class GroupExpressionMatchingTest {
new UnboundSlot(Lists.newArrayList("b", "id"))),
new LogicalJoin(JoinType.INNER_JOIN,
new LogicalJoin(JoinType.LEFT_OUTER_JOIN,
- new
UnboundRelation(ImmutableList.of("a")),
- new
UnboundRelation(ImmutableList.of("b"))),
- new UnboundRelation(ImmutableList.of("c")))
+ new
UnboundRelation(RelationUtil.newRelationId(), ImmutableList.of("a")),
+ new
UnboundRelation(RelationUtil.newRelationId(), ImmutableList.of("b"))),
+ new
UnboundRelation(RelationUtil.newRelationId(), ImmutableList.of("c")))
);
Pattern p1 =
patterns().logicalFilter(patterns().subTree(LogicalFilter.class,
LogicalJoin.class)).pattern;
Iterator<Plan> matchResult1 = match(root, p1);
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 c3c817f7ba..8414ed5187 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
@@ -20,6 +20,7 @@ package org.apache.doris.nereids.rules.analysis;
import org.apache.doris.nereids.analyzer.UnboundRelation;
import org.apache.doris.nereids.trees.plans.Plan;
import org.apache.doris.nereids.trees.plans.logical.LogicalOlapScan;
+import org.apache.doris.nereids.trees.plans.logical.RelationUtil;
import org.apache.doris.nereids.util.PlanRewriter;
import org.apache.doris.utframe.TestWithFeService;
@@ -45,7 +46,7 @@ class BindRelationTest extends TestWithFeService {
@Test
void bindInCurrentDb() {
connectContext.setDatabase(DEFAULT_CLUSTER_PREFIX + DB1);
- Plan plan = PlanRewriter.bottomUpRewrite(new
UnboundRelation(ImmutableList.of("t")),
+ Plan plan = PlanRewriter.bottomUpRewrite(new
UnboundRelation(RelationUtil.newRelationId(), ImmutableList.of("t")),
connectContext, new BindRelation());
Assertions.assertTrue(plan instanceof LogicalOlapScan);
@@ -57,7 +58,7 @@ class BindRelationTest extends TestWithFeService {
@Test
void bindByDbQualifier() {
connectContext.setDatabase(DEFAULT_CLUSTER_PREFIX + DB2);
- Plan plan = PlanRewriter.bottomUpRewrite(new
UnboundRelation(ImmutableList.of("db1", "t")),
+ Plan plan = PlanRewriter.bottomUpRewrite(new
UnboundRelation(RelationUtil.newRelationId(), ImmutableList.of("db1", "t")),
connectContext, new BindRelation());
Assertions.assertTrue(plan instanceof LogicalOlapScan);
diff --git
a/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/analysis/BindSlotReferenceTest.java
b/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/analysis/BindSlotReferenceTest.java
index cfd1433af7..6537b96e60 100644
---
a/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/analysis/BindSlotReferenceTest.java
+++
b/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/analysis/BindSlotReferenceTest.java
@@ -21,10 +21,10 @@ import org.apache.doris.nereids.analyzer.UnboundSlot;
import org.apache.doris.nereids.exceptions.AnalysisException;
import org.apache.doris.nereids.trees.expressions.NamedExpressionUtil;
import org.apache.doris.nereids.trees.plans.JoinType;
-import org.apache.doris.nereids.trees.plans.RelationId;
import org.apache.doris.nereids.trees.plans.logical.LogicalJoin;
import org.apache.doris.nereids.trees.plans.logical.LogicalOlapScan;
import org.apache.doris.nereids.trees.plans.logical.LogicalProject;
+import org.apache.doris.nereids.trees.plans.logical.RelationUtil;
import org.apache.doris.nereids.util.MemoTestUtils;
import org.apache.doris.nereids.util.PlanChecker;
import org.apache.doris.nereids.util.PlanConstructor;
@@ -44,7 +44,7 @@ class BindSlotReferenceTest {
@Test
public void testCannotFindSlot() {
LogicalProject project = new LogicalProject<>(ImmutableList.of(new
UnboundSlot("foo")),
- new LogicalOlapScan(new RelationId(0),
PlanConstructor.student));
+ new LogicalOlapScan(RelationUtil.newRelationId(),
PlanConstructor.student));
AnalysisException exception =
Assertions.assertThrows(AnalysisException.class,
() ->
PlanChecker.from(MemoTestUtils.createConnectContext()).analyze(project));
Assertions.assertEquals("Cannot find column foo.",
exception.getMessage());
@@ -52,8 +52,8 @@ class BindSlotReferenceTest {
@Test
public void testAmbiguousSlot() {
- LogicalOlapScan scan1 = new
LogicalOlapScan(RelationId.createGenerator().getNextId(),
PlanConstructor.student);
- LogicalOlapScan scan2 = new
LogicalOlapScan(RelationId.createGenerator().getNextId(),
PlanConstructor.student);
+ LogicalOlapScan scan1 = new
LogicalOlapScan(RelationUtil.newRelationId(), PlanConstructor.student);
+ LogicalOlapScan scan2 = new
LogicalOlapScan(RelationUtil.newRelationId(), PlanConstructor.student);
LogicalJoin<LogicalOlapScan, LogicalOlapScan> join = new LogicalJoin<>(
JoinType.CROSS_JOIN, scan1, scan2);
LogicalProject<LogicalJoin<LogicalOlapScan, LogicalOlapScan>> project
= new LogicalProject<>(
diff --git
a/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/analysis/CheckRowPolicyTest.java
b/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/analysis/CheckRowPolicyTest.java
index 529f8a60ee..9e44686208 100644
---
a/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/analysis/CheckRowPolicyTest.java
+++
b/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/analysis/CheckRowPolicyTest.java
@@ -35,11 +35,11 @@ import org.apache.doris.common.FeConstants;
import org.apache.doris.nereids.exceptions.AnalysisException;
import org.apache.doris.nereids.trees.expressions.EqualTo;
import org.apache.doris.nereids.trees.plans.Plan;
-import org.apache.doris.nereids.trees.plans.RelationId;
import org.apache.doris.nereids.trees.plans.logical.LogicalCheckPolicy;
import org.apache.doris.nereids.trees.plans.logical.LogicalFilter;
import org.apache.doris.nereids.trees.plans.logical.LogicalOlapScan;
import org.apache.doris.nereids.trees.plans.logical.LogicalRelation;
+import org.apache.doris.nereids.trees.plans.logical.RelationUtil;
import org.apache.doris.nereids.util.PlanRewriter;
import org.apache.doris.system.SystemInfoService;
import org.apache.doris.thrift.TStorageType;
@@ -98,7 +98,7 @@ public class CheckRowPolicyTest extends TestWithFeService {
@Test
public void checkUser() throws AnalysisException,
org.apache.doris.common.AnalysisException {
- LogicalRelation relation = new LogicalOlapScan(new RelationId(0),
olapTable, Arrays.asList(fullDbName));
+ LogicalRelation relation = new
LogicalOlapScan(RelationUtil.newRelationId(), olapTable,
Arrays.asList(fullDbName));
LogicalCheckPolicy<LogicalRelation> checkPolicy = new
LogicalCheckPolicy<>(relation);
useUser("root");
@@ -113,7 +113,7 @@ public class CheckRowPolicyTest extends TestWithFeService {
@Test
public void checkNoPolicy() throws
org.apache.doris.common.AnalysisException {
useUser(userName);
- LogicalRelation relation = new LogicalOlapScan(new RelationId(0),
olapTable, Arrays.asList(fullDbName));
+ LogicalRelation relation = new
LogicalOlapScan(RelationUtil.newRelationId(), olapTable,
Arrays.asList(fullDbName));
LogicalCheckPolicy<LogicalRelation> checkPolicy = new
LogicalCheckPolicy<>(relation);
Plan plan = PlanRewriter.bottomUpRewrite(checkPolicy, connectContext,
new CheckPolicy());
Assertions.assertEquals(plan, relation);
@@ -122,7 +122,7 @@ public class CheckRowPolicyTest extends TestWithFeService {
@Test
public void checkOnePolicy() throws Exception {
useUser(userName);
- LogicalRelation relation = new LogicalOlapScan(new RelationId(0),
olapTable, Arrays.asList(fullDbName));
+ LogicalRelation relation = new
LogicalOlapScan(RelationUtil.newRelationId(), olapTable,
Arrays.asList(fullDbName));
LogicalCheckPolicy<LogicalRelation> checkPolicy = new
LogicalCheckPolicy<>(relation);
connectContext.getSessionVariable().setEnableNereidsPlanner(true);
createPolicy("CREATE ROW POLICY "
diff --git
a/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/analysis/RegisterCTETest.java
b/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/analysis/RegisterCTETest.java
index 560dfcec7f..6a0321be35 100644
---
a/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/analysis/RegisterCTETest.java
+++
b/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/analysis/RegisterCTETest.java
@@ -340,6 +340,7 @@ public class RegisterCTETest extends TestWithFeService
implements PatternMatchSu
@Test
public void testDifferenceRelationId() {
+ final Integer[] integer = {0};
PlanChecker.from(connectContext)
.analyze("with s as (select * from supplier) select * from s
as s1, s as s2")
.matchesFromRoot(
@@ -348,14 +349,17 @@ public class RegisterCTETest extends TestWithFeService
implements PatternMatchSu
logicalSubQueryAlias(// as s1
logicalSubQueryAlias(// as s
logicalProject(// select * from supplier
- logicalOlapScan().when(scan ->
scan.getId().asInt() == 0)
+ logicalOlapScan().when(scan -> {
+ integer[0] = scan.getId().asInt();
+ return true;
+ })
)
).when(a -> a.getAlias().equals("s"))
).when(a -> a.getAlias().equals("s1")),
logicalSubQueryAlias(
logicalSubQueryAlias(
logicalProject(
- logicalOlapScan().when(scan ->
scan.getId().asInt() == 1)
+ logicalOlapScan().when(scan ->
scan.getId().asInt() != integer[0])
)
).when(a -> a.getAlias().equals("s"))
).when(a -> a.getAlias().equals("s2"))
diff --git
a/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/rewrite/logical/AggregateDisassembleTest.java
b/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/rewrite/logical/AggregateDisassembleTest.java
index 9d4d5711e2..4292c52541 100644
---
a/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/rewrite/logical/AggregateDisassembleTest.java
+++
b/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/rewrite/logical/AggregateDisassembleTest.java
@@ -30,9 +30,9 @@ import
org.apache.doris.nereids.trees.expressions.functions.agg.Sum;
import org.apache.doris.nereids.trees.expressions.literal.IntegerLiteral;
import org.apache.doris.nereids.trees.plans.AggPhase;
import org.apache.doris.nereids.trees.plans.Plan;
-import org.apache.doris.nereids.trees.plans.RelationId;
import org.apache.doris.nereids.trees.plans.logical.LogicalAggregate;
import org.apache.doris.nereids.trees.plans.logical.LogicalOlapScan;
+import org.apache.doris.nereids.trees.plans.logical.RelationUtil;
import org.apache.doris.nereids.util.MemoTestUtils;
import org.apache.doris.nereids.util.PatternMatchSupported;
import org.apache.doris.nereids.util.PlanChecker;
@@ -54,7 +54,7 @@ public class AggregateDisassembleTest implements
PatternMatchSupported {
@BeforeAll
public final void beforeAll() {
- rStudent = new
LogicalOlapScan(RelationId.createGenerator().getNextId(),
PlanConstructor.student,
+ rStudent = new LogicalOlapScan(RelationUtil.newRelationId(),
PlanConstructor.student,
ImmutableList.of(""));
}
diff --git
a/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/rewrite/logical/LimitPushDownTest.java
b/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/rewrite/logical/LimitPushDownTest.java
index 1d953700a1..26ea802e01 100644
---
a/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/rewrite/logical/LimitPushDownTest.java
+++
b/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/rewrite/logical/LimitPushDownTest.java
@@ -28,6 +28,7 @@ import
org.apache.doris.nereids.trees.plans.logical.LogicalJoin;
import org.apache.doris.nereids.trees.plans.logical.LogicalLimit;
import org.apache.doris.nereids.trees.plans.logical.LogicalOlapScan;
import org.apache.doris.nereids.trees.plans.logical.LogicalProject;
+import org.apache.doris.nereids.trees.plans.logical.RelationUtil;
import org.apache.doris.nereids.util.MemoTestUtils;
import org.apache.doris.nereids.util.PatternMatchSupported;
import org.apache.doris.nereids.util.PlanChecker;
@@ -48,8 +49,8 @@ import java.util.function.Function;
import java.util.stream.Collectors;
class LimitPushDownTest extends TestWithFeService implements
PatternMatchSupported {
- private Plan scanScore = new LogicalOlapScan(new RelationId(0),
PlanConstructor.score);
- private Plan scanStudent = new LogicalOlapScan(new RelationId(1),
PlanConstructor.student);
+ private Plan scanScore = new LogicalOlapScan(RelationUtil.newRelationId(),
PlanConstructor.score);
+ private Plan scanStudent = new
LogicalOlapScan(RelationUtil.newRelationId(), PlanConstructor.student);
@Override
protected void runBeforeAll() throws Exception {
@@ -106,6 +107,7 @@ class LimitPushDownTest extends TestWithFeService
implements PatternMatchSupport
@Test
public void testPushLimitThroughRightJoin() {
+ // after use RelationUtil to allocate relation id, the id will
increase when getNextId() called.
test(JoinType.RIGHT_OUTER_JOIN, true,
logicalLimit(
logicalProject(
diff --git
a/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/rewrite/logical/MergeFiltersTest.java
b/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/rewrite/logical/MergeFiltersTest.java
index 15db4cdef4..fad00b825e 100644
---
a/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/rewrite/logical/MergeFiltersTest.java
+++
b/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/rewrite/logical/MergeFiltersTest.java
@@ -24,6 +24,7 @@ import org.apache.doris.nereids.trees.expressions.Expression;
import org.apache.doris.nereids.trees.expressions.literal.IntegerLiteral;
import org.apache.doris.nereids.trees.plans.Plan;
import org.apache.doris.nereids.trees.plans.logical.LogicalFilter;
+import org.apache.doris.nereids.trees.plans.logical.RelationUtil;
import org.apache.doris.nereids.util.ExpressionUtils;
import org.apache.doris.nereids.util.MemoTestUtils;
@@ -39,7 +40,7 @@ import java.util.List;
public class MergeFiltersTest {
@Test
public void testMergeConsecutiveFilters() {
- UnboundRelation relation = new
UnboundRelation(Lists.newArrayList("db", "table"));
+ UnboundRelation relation = new
UnboundRelation(RelationUtil.newRelationId(), Lists.newArrayList("db",
"table"));
Expression expression1 = new IntegerLiteral(1);
LogicalFilter filter1 = new LogicalFilter<>(expression1, relation);
Expression expression2 = new IntegerLiteral(2);
diff --git
a/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/rewrite/logical/MergeLimitsTest.java
b/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/rewrite/logical/MergeLimitsTest.java
index 3056f1ac34..fa7270def9 100644
---
a/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/rewrite/logical/MergeLimitsTest.java
+++
b/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/rewrite/logical/MergeLimitsTest.java
@@ -21,6 +21,7 @@ import org.apache.doris.nereids.CascadesContext;
import org.apache.doris.nereids.analyzer.UnboundRelation;
import org.apache.doris.nereids.rules.Rule;
import org.apache.doris.nereids.trees.plans.logical.LogicalLimit;
+import org.apache.doris.nereids.trees.plans.logical.RelationUtil;
import org.apache.doris.nereids.util.MemoTestUtils;
import com.google.common.collect.Lists;
@@ -32,7 +33,8 @@ import java.util.List;
public class MergeLimitsTest {
@Test
public void testMergeConsecutiveLimits() {
- LogicalLimit limit3 = new LogicalLimit<>(3, 5, new
UnboundRelation(Lists.newArrayList("db", "t")));
+ LogicalLimit limit3 = new LogicalLimit<>(3, 5, new UnboundRelation(
+ RelationUtil.newRelationId(), Lists.newArrayList("db", "t")));
LogicalLimit limit2 = new LogicalLimit<>(2, 0, limit3);
LogicalLimit limit1 = new LogicalLimit<>(10, 0, limit2);
diff --git
a/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/rewrite/logical/MergeProjectsTest.java
b/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/rewrite/logical/MergeProjectsTest.java
index d15c87660d..b515beb0a6 100644
---
a/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/rewrite/logical/MergeProjectsTest.java
+++
b/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/rewrite/logical/MergeProjectsTest.java
@@ -28,6 +28,7 @@ import
org.apache.doris.nereids.trees.expressions.SlotReference;
import org.apache.doris.nereids.trees.expressions.literal.IntegerLiteral;
import org.apache.doris.nereids.trees.plans.Plan;
import org.apache.doris.nereids.trees.plans.logical.LogicalProject;
+import org.apache.doris.nereids.trees.plans.logical.RelationUtil;
import org.apache.doris.nereids.types.IntegerType;
import org.apache.doris.nereids.util.MemoTestUtils;
@@ -43,7 +44,7 @@ import java.util.List;
public class MergeProjectsTest {
@Test
public void testMergeConsecutiveProjects() {
- UnboundRelation relation = new
UnboundRelation(Lists.newArrayList("db", "table"));
+ UnboundRelation relation = new
UnboundRelation(RelationUtil.newRelationId(), Lists.newArrayList("db",
"table"));
NamedExpression colA = new SlotReference("a", IntegerType.INSTANCE,
true, Lists.newArrayList("a"));
NamedExpression colB = new SlotReference("b", IntegerType.INSTANCE,
true, Lists.newArrayList("b"));
NamedExpression colC = new SlotReference("c", IntegerType.INSTANCE,
true, Lists.newArrayList("c"));
@@ -74,7 +75,7 @@ public class MergeProjectsTest {
*/
@Test
public void testMergeConsecutiveProjectsWithAlias() {
- UnboundRelation relation = new
UnboundRelation(Lists.newArrayList("db", "table"));
+ UnboundRelation relation = new
UnboundRelation(RelationUtil.newRelationId(), Lists.newArrayList("db",
"table"));
NamedExpression colA = new SlotReference("a", IntegerType.INSTANCE,
true, Lists.newArrayList("a"));
NamedExpression colB = new SlotReference("b", IntegerType.INSTANCE,
true, Lists.newArrayList("b"));
NamedExpression colC = new SlotReference("c", IntegerType.INSTANCE,
true, Lists.newArrayList("c"));
diff --git
a/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/rewrite/logical/NormalizeAggregateTest.java
b/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/rewrite/logical/NormalizeAggregateTest.java
index 8b6e49a44a..2ef52a42cf 100644
---
a/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/rewrite/logical/NormalizeAggregateTest.java
+++
b/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/rewrite/logical/NormalizeAggregateTest.java
@@ -27,10 +27,10 @@ import
org.apache.doris.nereids.trees.expressions.functions.agg.AggregateFunctio
import org.apache.doris.nereids.trees.expressions.functions.agg.Sum;
import org.apache.doris.nereids.trees.expressions.literal.IntegerLiteral;
import org.apache.doris.nereids.trees.plans.Plan;
-import org.apache.doris.nereids.trees.plans.RelationId;
import org.apache.doris.nereids.trees.plans.logical.LogicalAggregate;
import org.apache.doris.nereids.trees.plans.logical.LogicalOlapScan;
import org.apache.doris.nereids.trees.plans.logical.LogicalPlan;
+import org.apache.doris.nereids.trees.plans.logical.RelationUtil;
import org.apache.doris.nereids.util.FieldChecker;
import org.apache.doris.nereids.util.LogicalPlanBuilder;
import org.apache.doris.nereids.util.MemoTestUtils;
@@ -52,7 +52,7 @@ public class NormalizeAggregateTest implements
PatternMatchSupported {
@BeforeAll
public final void beforeAll() {
- rStudent = new
LogicalOlapScan(RelationId.createGenerator().getNextId(),
PlanConstructor.student,
+ rStudent = new LogicalOlapScan(RelationUtil.newRelationId(),
PlanConstructor.student,
ImmutableList.of(""));
}
diff --git
a/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/rewrite/logical/PushdownFilterThroughAggregationTest.java
b/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/rewrite/logical/PushdownFilterThroughAggregationTest.java
index 851f10e5e9..33daf8c60a 100644
---
a/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/rewrite/logical/PushdownFilterThroughAggregationTest.java
+++
b/fe/fe-core/src/test/java/org/apache/doris/nereids/rules/rewrite/logical/PushdownFilterThroughAggregationTest.java
@@ -24,9 +24,9 @@ import org.apache.doris.nereids.trees.expressions.GreaterThan;
import org.apache.doris.nereids.trees.expressions.LessThanEqual;
import org.apache.doris.nereids.trees.expressions.Slot;
import org.apache.doris.nereids.trees.expressions.literal.Literal;
-import org.apache.doris.nereids.trees.plans.RelationId;
import org.apache.doris.nereids.trees.plans.logical.LogicalOlapScan;
import org.apache.doris.nereids.trees.plans.logical.LogicalPlan;
+import org.apache.doris.nereids.trees.plans.logical.RelationUtil;
import org.apache.doris.nereids.util.ExpressionUtils;
import org.apache.doris.nereids.util.LogicalPlanBuilder;
import org.apache.doris.nereids.util.MemoTestUtils;
@@ -60,7 +60,7 @@ public class PushdownFilterThroughAggregationTest implements
PatternMatchSupport
*/
@Test
public void pushDownPredicateOneFilterTest() {
- LogicalPlan scan = new
LogicalOlapScan(RelationId.createGenerator().getNextId(),
PlanConstructor.student,
+ LogicalPlan scan = new LogicalOlapScan(RelationUtil.newRelationId(),
PlanConstructor.student,
ImmutableList.of(""));
Slot gender = scan.getOutput().get(1);
@@ -107,7 +107,7 @@ public class PushdownFilterThroughAggregationTest
implements PatternMatchSupport
*/
@Test
public void pushDownPredicateTwoFilterTest() {
- LogicalPlan scan = new
LogicalOlapScan(RelationId.createGenerator().getNextId(),
PlanConstructor.student,
+ LogicalPlan scan = new LogicalOlapScan(RelationUtil.newRelationId(),
PlanConstructor.student,
ImmutableList.of(""));
Slot gender = scan.getOutput().get(1);
Slot name = scan.getOutput().get(2);
diff --git
a/fe/fe-core/src/test/java/org/apache/doris/nereids/stats/StatsCalculatorTest.java
b/fe/fe-core/src/test/java/org/apache/doris/nereids/stats/StatsCalculatorTest.java
index 69d50d5db8..c47763b2ce 100644
---
a/fe/fe-core/src/test/java/org/apache/doris/nereids/stats/StatsCalculatorTest.java
+++
b/fe/fe-core/src/test/java/org/apache/doris/nereids/stats/StatsCalculatorTest.java
@@ -28,11 +28,11 @@ import org.apache.doris.nereids.trees.expressions.Or;
import org.apache.doris.nereids.trees.expressions.SlotReference;
import org.apache.doris.nereids.trees.expressions.literal.IntegerLiteral;
import org.apache.doris.nereids.trees.plans.GroupPlan;
-import org.apache.doris.nereids.trees.plans.RelationId;
import org.apache.doris.nereids.trees.plans.logical.LogicalFilter;
import org.apache.doris.nereids.trees.plans.logical.LogicalLimit;
import org.apache.doris.nereids.trees.plans.logical.LogicalOlapScan;
import org.apache.doris.nereids.trees.plans.logical.LogicalTopN;
+import org.apache.doris.nereids.trees.plans.logical.RelationUtil;
import org.apache.doris.nereids.types.IntegerType;
import org.apache.doris.nereids.util.PlanConstructor;
import org.apache.doris.qe.ConnectContext;
@@ -241,7 +241,7 @@ public class StatsCalculatorTest {
SlotReference slot1 = new SlotReference("c1", IntegerType.INSTANCE,
true, qualifier);
OlapTable table1 = PlanConstructor.newOlapTable(tableId1, "t1", 0);
- LogicalOlapScan logicalOlapScan1 = new
LogicalOlapScan(RelationId.createGenerator().getNextId(), table1,
Collections.emptyList())
+ LogicalOlapScan logicalOlapScan1 = new
LogicalOlapScan(RelationUtil.newRelationId(), table1, Collections.emptyList())
.withLogicalProperties(Optional.of(new LogicalProperties(() ->
ImmutableList.of(slot1))));
Group childGroup = new Group();
GroupExpression groupExpression = new
GroupExpression(logicalOlapScan1, ImmutableList.of(childGroup));
diff --git
a/fe/fe-core/src/test/java/org/apache/doris/nereids/trees/plans/PlanEqualsTest.java
b/fe/fe-core/src/test/java/org/apache/doris/nereids/trees/plans/PlanEqualsTest.java
index cb4b0acde3..bf5a57ec77 100644
---
a/fe/fe-core/src/test/java/org/apache/doris/nereids/trees/plans/PlanEqualsTest.java
+++
b/fe/fe-core/src/test/java/org/apache/doris/nereids/trees/plans/PlanEqualsTest.java
@@ -33,6 +33,7 @@ import
org.apache.doris.nereids.trees.plans.logical.LogicalJoin;
import org.apache.doris.nereids.trees.plans.logical.LogicalOlapScan;
import org.apache.doris.nereids.trees.plans.logical.LogicalProject;
import org.apache.doris.nereids.trees.plans.logical.LogicalSort;
+import org.apache.doris.nereids.trees.plans.logical.RelationUtil;
import org.apache.doris.nereids.trees.plans.physical.PhysicalAggregate;
import org.apache.doris.nereids.trees.plans.physical.PhysicalFilter;
import org.apache.doris.nereids.trees.plans.physical.PhysicalHashJoin;
@@ -247,7 +248,7 @@ public class PlanEqualsTest {
selectedTabletId.addAll(partition.getBaseIndex().getTabletIdsInOrder());
}
- RelationId id = RelationId.createGenerator().getNextId();
+ RelationId id = RelationUtil.newRelationId();
PhysicalOlapScan actual = new PhysicalOlapScan(id, olapTable,
Lists.newArrayList("a"),
olapTable.getBaseIndexId(), selectedTabletId,
olapTable.getPartitionIds(), distributionSpecHash,
diff --git
a/fe/fe-core/src/test/java/org/apache/doris/nereids/trees/plans/PlanOutputTest.java
b/fe/fe-core/src/test/java/org/apache/doris/nereids/trees/plans/PlanOutputTest.java
index ea085d9462..7267ada07d 100644
---
a/fe/fe-core/src/test/java/org/apache/doris/nereids/trees/plans/PlanOutputTest.java
+++
b/fe/fe-core/src/test/java/org/apache/doris/nereids/trees/plans/PlanOutputTest.java
@@ -25,6 +25,7 @@ import org.apache.doris.nereids.properties.LogicalProperties;
import org.apache.doris.nereids.properties.PhysicalProperties;
import org.apache.doris.nereids.trees.expressions.Slot;
import org.apache.doris.nereids.trees.plans.logical.LogicalOlapScan;
+import org.apache.doris.nereids.trees.plans.logical.RelationUtil;
import org.apache.doris.nereids.trees.plans.physical.PhysicalPlan;
import org.apache.doris.nereids.trees.plans.physical.PhysicalRelation;
import org.apache.doris.nereids.types.IntegerType;
@@ -57,7 +58,7 @@ public class PlanOutputTest {
@Test
public void testLazyComputeOutput() {
// not throw exception when create new UnboundRelation
- UnboundRelation relationPlan = new
UnboundRelation(ImmutableList.of("a"));
+ UnboundRelation relationPlan = new
UnboundRelation(RelationUtil.newRelationId(), ImmutableList.of("a"));
try {
// throw exception when getOutput
@@ -85,7 +86,7 @@ public class PlanOutputTest {
@Test
public void testPhysicalPlanMustHaveLogicalProperties() {
Assertions.assertThrows(NullPointerException.class, () ->
- new PhysicalRelation(RelationId.createGenerator().getNextId(),
+ new PhysicalRelation(RelationUtil.newRelationId(),
PlanType.PHYSICAL_OLAP_SCAN, ImmutableList.of("db"),
Optional.empty(), null) {
@Override
public Plan withGroupExpression(Optional<GroupExpression>
groupExpression) {
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]