File tree Expand file tree Collapse file tree 2 files changed +23
-4
lines changed
Expand file tree Collapse file tree 2 files changed +23
-4
lines changed Original file line number Diff line number Diff line change @@ -304,11 +304,19 @@ fn assign_work_table(
304304 plan : Arc < dyn ExecutionPlan > ,
305305 work_table : Arc < WorkTable > ,
306306) -> Result < Arc < dyn ExecutionPlan > > {
307- plan. transform_down ( & |plan| {
307+ let mut work_table_refs = 0 ;
308+ plan. transform_down_mut ( & mut |plan| {
308309 if let Some ( exec) = plan. as_any ( ) . downcast_ref :: < WorkTableExec > ( ) {
309- Ok ( Transformed :: Yes ( Arc :: new (
310- exec. with_work_table ( work_table. clone ( ) ) ,
311- ) ) )
310+ if work_table_refs > 0 {
311+ not_impl_err ! (
312+ "Multiple recursive references to the same CTE are not supported"
313+ )
314+ } else {
315+ work_table_refs += 1 ;
316+ Ok ( Transformed :: Yes ( Arc :: new (
317+ exec. with_work_table ( work_table. clone ( ) ) ,
318+ ) ) )
319+ }
312320 } else if plan. as_any ( ) . is :: < RecursiveQueryExec > ( ) {
313321 not_impl_err ! ( "Recursive queries cannot be nested" )
314322 } else {
Original file line number Diff line number Diff line change @@ -619,3 +619,14 @@ WITH RECURSIVE outer_cte AS (
619619 )
620620)
621621SELECT a FROM outer_cte;
622+
623+ # expect error when recursive CTE is referenced multiple times in the recursive term
624+ query error DataFusion error: This feature is not implemented: Multiple recursive references to the same CTE are not supported
625+ WITH RECURSIVE my_cte AS (
626+ SELECT 1 as a
627+ UNION ALL
628+ SELECT my_cte.a+2 as a
629+ FROM my_cte join my_cte c2 using(a)
630+ WHERE my_cte.a<5
631+ )
632+ SELECT a FROM my_cte;
You can’t perform that action at this time.
0 commit comments