Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@
import org.apache.doris.nereids.trees.plans.logical.LogicalRelation;
import org.apache.doris.nereids.trees.plans.logical.LogicalResultSink;
import org.apache.doris.nereids.trees.plans.logical.LogicalSink;
import org.apache.doris.nereids.trees.plans.logical.LogicalSort;
import org.apache.doris.nereids.trees.plans.logical.LogicalTopN;
import org.apache.doris.nereids.trees.plans.logical.LogicalUnion;
import org.apache.doris.nereids.trees.plans.logical.LogicalWindow;
import org.apache.doris.nereids.trees.plans.visitor.DefaultPlanRewriter;
Expand Down Expand Up @@ -457,11 +459,15 @@ public Void visit(Plan plan, PartitionIncrementCheckContext context) {
&& ((LogicalUnion) plan).getQualifier() == SetOperation.Qualifier.ALL)
|| plan instanceof LogicalCTEAnchor
|| plan instanceof LogicalCTEConsumer
|| plan instanceof LogicalCTEProducer) {
|| plan instanceof LogicalCTEProducer
|| plan instanceof LogicalSort
|| plan instanceof LogicalTopN
) {
return super.visit(plan, context);
}
context.addFailReason(String.format("Unsupported plan operate in track partition, "
+ "the invalid plan node is %s", plan.getClass().getSimpleName()));
context.setFailFast(true);
context.collectFailedTableSet(plan);
return super.visit(plan, context);
}
Expand Down Expand Up @@ -529,8 +535,10 @@ private static boolean checkPartition(Collection<? extends Expression> expressio
NamedExpression partitionNamedExpression = partitionExpressionEntry.getKey();
RelatedTableColumnInfo partitionTableColumnInfo = partitionExpressionEntry.getValue();
Optional<Expression> partitionExpressionOpt = partitionTableColumnInfo.getPartitionExpression();
Expression partitionExpressionActual = partitionExpressionOpt.orElseGet(
() -> ExpressionUtils.shuttleExpressionWithLineage(partitionNamedExpression,
Expression partitionExpressionActual = partitionExpressionOpt
.map(expr -> ExpressionUtils.shuttleExpressionWithLineage(expr,
context.getOriginalPlan(), new BitSet()))
.orElseGet(() -> ExpressionUtils.shuttleExpressionWithLineage(partitionNamedExpression,
context.getOriginalPlan(), new BitSet()));
// merge date_trunc
partitionExpressionActual = new ExpressionNormalization().rewrite(partitionExpressionActual,
Expand Down Expand Up @@ -694,6 +702,9 @@ public Set<String> getFailReasons() {
}

public void addFailReason(String failReason) {
if (failFast) {
return;
}
this.failReasons.add(failReason);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,26 @@ public void test1() {
});
}

// with sort
@Test
public void test101() {
PlanChecker.from(connectContext)
.checkExplain(" select l1.l_shipdate, l2.L_ORDERKEY\n"
+ " from lineitem l1\n"
+ " inner join lineitem l2\n"
+ " on l1.l_shipdate = l2.l_shipdate\n"
+ " order by l1.l_shipdate, l2.L_ORDERKEY",
nereidsPlanner -> {
Plan rewrittenPlan = nereidsPlanner.getRewrittenPlan();
RelatedTableInfo relatedTableInfo =
MaterializedViewUtils.getRelatedTableInfos("l_shipdate", null,
rewrittenPlan, nereidsPlanner.getCascadesContext());
successWith(relatedTableInfo, ImmutableSet.of(
ImmutableList.of("lineitem", "l_shipdate", "true", "true")),
"");
});
}

@Test
public void test100() {
PlanChecker.from(connectContext)
Expand Down Expand Up @@ -330,7 +350,8 @@ public void test500() {
MaterializedViewUtils.getRelatedTableInfos("l_shipdate", null,
rewrittenPlan, nereidsPlanner.getCascadesContext());
successWith(relatedTableInfo,
ImmutableSet.of(ImmutableList.of("lineitem", "l_shipdate", "true", "true")), "");
ImmutableSet.of(ImmutableList.of("lineitem", "l_shipdate", "true", "true"),
ImmutableList.of("orders", "o_orderdate", "true", "true")), "");
});
}

Expand All @@ -353,6 +374,26 @@ public void test5000() {
});
}

// test with date_trunc with alias
@Test
public void test5001() {
PlanChecker.from(connectContext)
.checkExplain(" select l_shipdate, date_trunc(o_orderdate, 'day') o_orderdate_alias, count(l_shipdate) \n"
+ " from lineitem\n"
+ " inner join orders o\n"
+ " on l_shipdate = o.o_orderdate\n"
+ " group by l_shipdate, o.o_orderdate",
nereidsPlanner -> {
Plan rewrittenPlan = nereidsPlanner.getRewrittenPlan();
RelatedTableInfo relatedTableInfo =
MaterializedViewUtils.getRelatedTableInfos("o_orderdate_alias", null,
rewrittenPlan, nereidsPlanner.getCascadesContext());
successWith(relatedTableInfo,
ImmutableSet.of(ImmutableList.of("orders", "o_orderdate", "true", "true"),
ImmutableList.of("lineitem", "l_shipdate", "true", "true")), "day");
});
}

@Test
public void test501() {
PlanChecker.from(connectContext)
Expand Down
Loading