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
28 changed files
with
1,666 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
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); | ||
} | ||
} |
102 changes: 88 additions & 14 deletions
102
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
Oops, something went wrong.