Skip to content

Commit e40279b

Browse files
starocean999BiteTheDDDDt
authored andcommitted
fix bug
1 parent fe5aa75 commit e40279b

File tree

2 files changed

+13
-15
lines changed

2 files changed

+13
-15
lines changed

fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/AnalyzeCTE.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -152,10 +152,14 @@ private Pair<CTEContext, LogicalCTEProducer<Plan>> analyzeRecursiveCte(LogicalSu
152152
});
153153
cascadesContext.addPlanProcesses(innerAnchorCascadesCtx.getPlanProcesses());
154154
LogicalPlan analyzedAnchorChild = (LogicalPlan) innerAnchorCascadesCtx.getRewritePlan();
155-
if (!analyzedAnchorChild.collect(LogicalRecursiveCteScan.class::isInstance).isEmpty()) {
156-
throw new AnalysisException(
157-
String.format("recursive reference to query %s must not appear within its non-recursive term",
158-
aliasQuery.getAlias()));
155+
Set<LogicalRecursiveCteScan> recursiveCteScans = analyzedAnchorChild
156+
.collect(LogicalRecursiveCteScan.class::isInstance);
157+
for (LogicalRecursiveCteScan cteScan : recursiveCteScans) {
158+
if (cteScan.getTable().getName().equalsIgnoreCase(aliasQuery.getAlias())) {
159+
throw new AnalysisException(
160+
String.format("recursive reference to query %s must not appear within its non-recursive term",
161+
aliasQuery.getAlias()));
162+
}
159163
}
160164
checkColumnAlias(aliasQuery, analyzedAnchorChild.getOutput());
161165
// make all output nullable

fe/fe-core/src/main/java/org/apache/doris/qe/runtime/ThriftPlansBuilder.java

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -636,19 +636,14 @@ private static Set<Integer> setParamsForRecursiveCteNode(List<PipelineDistribute
636636

637637
List<RecursiveCteNode> recursiveCteNodes = planFragment.getPlanRoot()
638638
.collectInCurrentFragment(RecursiveCteNode.class::isInstance);
639-
if (!recursiveCteNodes.isEmpty()) {
640-
if (recursiveCteNodes.size() != 1) {
641-
throw new IllegalStateException(
642-
String.format("one fragment can only have 1 recursive cte node, but there is %d",
643-
recursiveCteNodes.size()));
644-
}
645-
639+
for (RecursiveCteNode recursiveCteNode : recursiveCteNodes) {
646640
List<TRecCTETarget> targets = new ArrayList<>();
647641
List<TRecCTEResetInfo> fragmentsToReset = new ArrayList<>();
648-
// PhysicalPlanTranslator will swap recursiveCteNode's child fragment,
649-
// so we get recursive one by 1st child and collect all child fragment of recursive side
642+
// recursiveCteNode's right child is recursive part (exchange node)
643+
// so we get collect all child fragment from exchange node's child node
650644
List<PlanFragment> childFragments = new ArrayList<>();
651-
planFragment.getChild(0).collectAll(PlanFragment.class::isInstance, childFragments);
645+
recursiveCteNode.getChild(1).getChild(0).getFragment().collectAll(PlanFragment.class::isInstance,
646+
childFragments);
652647
for (PlanFragment child : childFragments) {
653648
PlanFragmentId childFragmentId = child.getFragmentId();
654649
// the fragment need to be notified to close
@@ -676,7 +671,6 @@ private static Set<Integer> setParamsForRecursiveCteNode(List<PipelineDistribute
676671
}
677672
}
678673

679-
RecursiveCteNode recursiveCteNode = recursiveCteNodes.get(0);
680674
List<List<Expr>> materializedResultExprLists = recursiveCteNode.getMaterializedResultExprLists();
681675
List<List<TExpr>> texprLists = new ArrayList<>(materializedResultExprLists.size());
682676
for (List<Expr> exprList : materializedResultExprLists) {

0 commit comments

Comments
 (0)