forked from apache/doris
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
364 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
fe/fe-core/src/main/java/org/apache/doris/nereids/commonCTE/ConsumerRewriter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package org.apache.doris.nereids.commonCTE; | ||
|
||
import org.apache.doris.nereids.trees.expressions.CTEId; | ||
import org.apache.doris.nereids.trees.expressions.Slot; | ||
import org.apache.doris.nereids.trees.expressions.StatementScopeIdGenerator; | ||
import org.apache.doris.nereids.trees.plans.Plan; | ||
import org.apache.doris.nereids.trees.plans.logical.AbstractLogicalPlan; | ||
import org.apache.doris.nereids.trees.plans.logical.LogicalCTEConsumer; | ||
import org.apache.doris.nereids.trees.plans.logical.LogicalPlan; | ||
import org.apache.doris.nereids.trees.plans.visitor.DefaultPlanRewriter; | ||
import org.apache.doris.nereids.trees.plans.visitor.PlanVisitor; | ||
|
||
import com.google.common.collect.ImmutableMap; | ||
import com.google.common.collect.ImmutableMultimap; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class ConsumerRewriter extends DefaultPlanRewriter<ConsumerRewriterContext> { | ||
public static final ConsumerRewriter INSTANCE = new ConsumerRewriter(); | ||
@Override | ||
public Plan visit(Plan plan, ConsumerRewriterContext context) { | ||
if (context.isTarget(plan)) { | ||
context.producer.getOutput(); | ||
plan.getOutput(); | ||
ImmutableMap.Builder<Slot, Slot> cToPBuilder = ImmutableMap.builder(); | ||
ImmutableMultimap.Builder<Slot, Slot> pToCBuilder = ImmutableMultimap.builder(); | ||
for (int i = 0; i< context.producer.getOutput().size(); i++) { | ||
cToPBuilder.put(plan.getOutput().get(i), context.producer.getOutput().get(i)); | ||
pToCBuilder.put(context.producer.getOutput().get(i), plan.getOutput().get(i)); | ||
} | ||
return new LogicalCTEConsumer(StatementScopeIdGenerator.newRelationId(), context.cteId, | ||
"comm_cte_" + context.cteId.asInt(), cToPBuilder.build(), pToCBuilder.build()); | ||
} | ||
return visitChildren(this, plan, context); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
fe/fe-core/src/main/java/org/apache/doris/nereids/commonCTE/ConsumerRewriterContext.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package org.apache.doris.nereids.commonCTE; | ||
|
||
import org.apache.doris.nereids.trees.expressions.CTEId; | ||
import org.apache.doris.nereids.trees.plans.Plan; | ||
import org.apache.doris.nereids.trees.plans.logical.AbstractLogicalPlan; | ||
|
||
import java.util.List; | ||
|
||
public class ConsumerRewriterContext { | ||
private final List<Plan> targets; | ||
public Plan producer; | ||
public final CTEId cteId; | ||
|
||
public ConsumerRewriterContext(List<Plan> targets, Plan producer, CTEId cteId) { | ||
this.targets = targets; | ||
this.producer = producer; | ||
this.cteId = cteId; | ||
} | ||
public boolean isTarget(Plan plan) { | ||
return targets.contains(plan); | ||
} | ||
} |
97 changes: 83 additions & 14 deletions
97
fe/fe-core/src/main/java/org/apache/doris/nereids/commonCTE/CteExtractor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
-- This file is automatically generated. You should know what you did if you want to edit this | ||
-- !1 -- | ||
LogicalResultSink[168] ( outputExprs=[a#34] ) | ||
+--LogicalAggregate[166] ( groupByExpr=[a#34], outputExpr=[a#34], hasRepeat=false ) | ||
+--LogicalUnion ( qualifier=ALL, outputs=[a#34], regularChildrenOutputs=[[a#32], [b#33]], constantExprsList=[], hasPushedFilter=false ) | ||
|--LogicalAggregate[157] ( groupByExpr=[], outputExpr=[count(*) AS `a`#32], hasRepeat=false ) | ||
| +--LogicalProject[155] ( distinct=false, projects=[1 AS `1`#41] ) | ||
| +--LogicalOlapScan[129] ( qualified=internal.regression_test_query_p0_common_cte.lineitem, indexName=<index_not_selected>, selectedIndexId=1596500, preAgg=ON ) | ||
+--LogicalAggregate[160] ( groupByExpr=[], outputExpr=[count(*) AS `b`#33], hasRepeat=false ) | ||
+--LogicalProject[158] ( distinct=false, projects=[1 AS `1`#42] ) | ||
+--LogicalOlapScan[132] ( qualified=internal.regression_test_query_p0_common_cte.lineitem, indexName=<index_not_selected>, selectedIndexId=1596500, preAgg=ON ) | ||
common cte info | ||
SPJG [1596499] | ||
155 129 132 158 | ||
SPJG AGG [1596499] | ||
157 160 | ||
|
25 changes: 25 additions & 0 deletions
25
regression-test/suites/query_p0/common_cte/common_cte.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// 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. | ||
|
||
suite("common_cte") { | ||
qt_1 " explain rewritten plan select * from (select count() a from lineitem union all select count() b from lineitem) T" | ||
} | ||
|
||
set enable_common_cte=false; | ||
explain physical plan | ||
with x as (select count() a from lineitem) | ||
select * from (select * from x union all select * from x) T; |
Oops, something went wrong.