diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/AdjustPreAggStatus.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/AdjustPreAggStatus.java index a0c0b56dd71c99..8b90e4cdedc8a2 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/AdjustPreAggStatus.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/AdjustPreAggStatus.java @@ -78,7 +78,7 @@ public List buildRules() { return ImmutableList.of( // Aggregate(Scan) logicalAggregate(logicalOlapScan().when(LogicalOlapScan::isPreAggStatusUnSet)) - .thenApplyNoThrow(ctx -> { + .thenApply(ctx -> { LogicalAggregate agg = ctx.root; LogicalOlapScan scan = agg.child(); PreAggStatus preAggStatus = checkKeysType(scan); @@ -96,7 +96,7 @@ public List buildRules() { // Aggregate(Filter(Scan)) logicalAggregate( logicalFilter(logicalOlapScan().when(LogicalOlapScan::isPreAggStatusUnSet))) - .thenApplyNoThrow(ctx -> { + .thenApply(ctx -> { LogicalAggregate> agg = ctx.root; LogicalFilter filter = agg.child(); LogicalOlapScan scan = filter.child(); @@ -117,7 +117,7 @@ public List buildRules() { // Aggregate(Project(Scan)) logicalAggregate(logicalProject( logicalOlapScan().when(LogicalOlapScan::isPreAggStatusUnSet))) - .thenApplyNoThrow(ctx -> { + .thenApply(ctx -> { LogicalAggregate> agg = ctx.root; LogicalProject project = agg.child(); @@ -141,7 +141,7 @@ public List buildRules() { // Aggregate(Project(Filter(Scan))) logicalAggregate(logicalProject(logicalFilter( logicalOlapScan().when(LogicalOlapScan::isPreAggStatusUnSet)))) - .thenApplyNoThrow(ctx -> { + .thenApply(ctx -> { LogicalAggregate>> agg = ctx.root; LogicalProject> project = agg.child(); LogicalFilter filter = project.child(); @@ -164,7 +164,7 @@ public List buildRules() { // Aggregate(Filter(Project(Scan))) logicalAggregate(logicalFilter(logicalProject( logicalOlapScan().when(LogicalOlapScan::isPreAggStatusUnSet)))) - .thenApplyNoThrow(ctx -> { + .thenApply(ctx -> { LogicalAggregate>> agg = ctx.root; LogicalFilter> filter = agg.child(); @@ -189,7 +189,7 @@ public List buildRules() { // Aggregate(Repeat(Scan)) logicalAggregate( logicalRepeat(logicalOlapScan().when(LogicalOlapScan::isPreAggStatusUnSet))) - .thenApplyNoThrow(ctx -> { + .thenApply(ctx -> { LogicalAggregate> agg = ctx.root; LogicalRepeat repeat = agg.child(); LogicalOlapScan scan = repeat.child(); @@ -209,7 +209,7 @@ public List buildRules() { // Aggregate(Repeat(Filter(Scan))) logicalAggregate(logicalRepeat(logicalFilter( logicalOlapScan().when(LogicalOlapScan::isPreAggStatusUnSet)))) - .thenApplyNoThrow(ctx -> { + .thenApply(ctx -> { LogicalAggregate>> agg = ctx.root; LogicalRepeat> repeat = agg.child(); LogicalFilter filter = repeat.child(); @@ -231,7 +231,7 @@ public List buildRules() { // Aggregate(Repeat(Project(Scan))) logicalAggregate(logicalRepeat(logicalProject( logicalOlapScan().when(LogicalOlapScan::isPreAggStatusUnSet)))) - .thenApplyNoThrow(ctx -> { + .thenApply(ctx -> { LogicalAggregate>> agg = ctx.root; LogicalRepeat> repeat = agg.child(); LogicalProject project = repeat.child(); @@ -254,7 +254,7 @@ public List buildRules() { // Aggregate(Repeat(Project(Filter(Scan)))) logicalAggregate(logicalRepeat(logicalProject(logicalFilter( logicalOlapScan().when(LogicalOlapScan::isPreAggStatusUnSet))))) - .thenApplyNoThrow(ctx -> { + .thenApply(ctx -> { LogicalAggregate>>> agg = ctx.root; LogicalRepeat>> repeat = agg.child(); @@ -280,7 +280,7 @@ public List buildRules() { // Aggregate(Repeat(Filter(Project(Scan)))) logicalAggregate(logicalRepeat(logicalFilter(logicalProject( logicalOlapScan().when(LogicalOlapScan::isPreAggStatusUnSet))))) - .thenApplyNoThrow(ctx -> { + .thenApply(ctx -> { LogicalAggregate>>> agg = ctx.root; LogicalRepeat>> repeat = agg.child(); @@ -307,7 +307,7 @@ public List buildRules() { // Filter(Project(Scan)) logicalFilter(logicalProject( logicalOlapScan().when(LogicalOlapScan::isPreAggStatusUnSet))) - .thenApplyNoThrow(ctx -> { + .thenApply(ctx -> { LogicalFilter> filter = ctx.root; LogicalProject project = filter.child(); LogicalOlapScan scan = project.child(); @@ -326,7 +326,7 @@ public List buildRules() { // Filter(Scan) logicalFilter(logicalOlapScan().when(LogicalOlapScan::isPreAggStatusUnSet)) - .thenApplyNoThrow(ctx -> { + .thenApply(ctx -> { LogicalFilter filter = ctx.root; LogicalOlapScan scan = filter.child(); PreAggStatus preAggStatus = checkKeysType(scan); @@ -342,7 +342,7 @@ public List buildRules() { // only scan. logicalOlapScan().when(LogicalOlapScan::isPreAggStatusUnSet) - .thenApplyNoThrow(ctx -> { + .thenApply(ctx -> { LogicalOlapScan scan = ctx.root; PreAggStatus preAggStatus = checkKeysType(scan); if (preAggStatus == PreAggStatus.unset()) { @@ -500,7 +500,10 @@ private PreAggStatus checkAggregateFunctions(List aggregateFu ? PreAggStatus.off("No aggregate on scan.") : PreAggStatus.on(); for (AggregateFunction aggFunc : aggregateFuncs) { - if (aggFunc.children().size() == 1 && aggFunc.child(0) instanceof Slot) { + if (aggFunc.children().isEmpty()) { + preAggStatus = PreAggStatus.off( + String.format("can't turn preAgg on for aggregate function %s", aggFunc)); + } else if (aggFunc.children().size() == 1 && aggFunc.child(0) instanceof Slot) { Slot aggSlot = (Slot) aggFunc.child(0); if (aggSlot instanceof SlotReference && ((SlotReference) aggSlot).getColumn().isPresent()) { 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 81183a157486c1..b14834fd32192b 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 @@ -115,11 +115,12 @@ public boolean hasDeleteSign() { PlanChecker.from(connectContext) .parse("select * from " + tableName + " as et join db1.t on et.id = t.a") .customAnalyzer(Optional.of(customTableResolver)) // analyze internal relation - .rewrite() .matches( logicalJoin( - logicalOlapScan().when(r -> r.getTable() == externalOlapTable), - logicalOlapScan().when(r -> r.getTable().getName().equals("t")) + logicalSubQueryAlias( + logicalOlapScan().when(r -> r.getTable() == externalOlapTable) + ), + logicalOlapScan().when(r -> r.getTable().getName().equals("t")) ) ); }