Skip to content

Commit ce997d9

Browse files
committed
Fix double appendpipe planner assertion error (#5173)
visitAppendPipe re-visits parent AST in new planner context, causing assertion failure. Use relBuilder stack directly instead of AST re-visitation to stay within the same planner context. Signed-off-by: Songkan Tang <songkant@amazon.com>
1 parent 8a7524c commit ce997d9

1 file changed

Lines changed: 7 additions & 14 deletions

File tree

core/src/main/java/org/opensearch/sql/calcite/CalciteRelNodeVisitor.java

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -299,22 +299,15 @@ public RelNode visitFilter(Filter node, CalcitePlanContext context) {
299299
@Override
300300
public RelNode visitAppendPipe(AppendPipe node, CalcitePlanContext context) {
301301
visitChildren(node, context);
302-
UnresolvedPlan subqueryPlan = node.getSubQuery();
303-
UnresolvedPlan childNode = subqueryPlan;
304-
while (childNode.getChild() != null
305-
&& !childNode.getChild().isEmpty()
306-
&& !(childNode.getChild().getFirst() instanceof Values)) {
307-
if (childNode.getChild().size() > 1) {
308-
throw new RuntimeException("AppendPipe doesn't support multiply children subquery.");
309-
}
310-
childNode = (UnresolvedPlan) childNode.getChild().getFirst();
311-
}
312-
childNode.attach(node.getChild().getFirst());
313-
314-
subqueryPlan.accept(this, context);
302+
// Use the main plan from the relBuilder stack directly instead of re-visiting
303+
// the parent AST. Re-visiting causes "belongs to a different planner" assertion
304+
// when multiple appendpipe commands are chained.
305+
RelNode mainNode = context.relBuilder.peek();
306+
context.relBuilder.push(mainNode);
307+
node.getSubQuery().accept(this, context);
315308

316309
RelNode subPipelineNode = context.relBuilder.build();
317-
RelNode mainNode = context.relBuilder.build();
310+
mainNode = context.relBuilder.build();
318311
return mergeTableAndResolveColumnConflict(mainNode, subPipelineNode, context);
319312
}
320313

0 commit comments

Comments
 (0)