@@ -20,6 +20,10 @@ select * from (WITH source AS (select 1 as e) SELECT * FROM source) t1, (WITH
20
20
----
21
21
1 1
22
22
23
+ # enable recursive CTEs
24
+ statement ok
25
+ set datafusion.execution.enable_recursive_ctes = true;
26
+
23
27
# trivial recursive CTE works
24
28
query I rowsort
25
29
WITH RECURSIVE nodes AS (
@@ -81,7 +85,48 @@ CREATE EXTERNAL TABLE balance STORED as CSV WITH HEADER ROW LOCATION '../../test
81
85
statement ok
82
86
CREATE EXTERNAL TABLE growth STORED as CSV WITH HEADER ROW LOCATION '../../testing/data/csv/r_cte_growth.csv'
83
87
88
+ # setup
89
+ statement ok
90
+ set datafusion.execution.batch_size = 2;
91
+
92
+ # recursive CTE with static term derived from table works.
93
+ # use explain to ensure that batch size is set to 2. This should produce multiple batches per iteration since the input
94
+ # table 'balances' has 4 rows
95
+ query TT
96
+ EXPLAIN WITH RECURSIVE balances AS (
97
+ SELECT * from balance
98
+ UNION ALL
99
+ SELECT time + 1 as time, name, account_balance + 10 as account_balance
100
+ FROM balances
101
+ WHERE time < 10
102
+ )
103
+ SELECT * FROM balances
104
+ ORDER BY time, name, account_balance
105
+ ----
106
+ logical_plan
107
+ Sort: balances.time ASC NULLS LAST, balances.name ASC NULLS LAST, balances.account_balance ASC NULLS LAST
108
+ --Projection: balances.time, balances.name, balances.account_balance
109
+ ----SubqueryAlias: balances
110
+ ------RecursiveQuery: is_distinct=false
111
+ --------Projection: balance.time, balance.name, balance.account_balance
112
+ ----------TableScan: balance
113
+ --------Projection: balances.time + Int64(1) AS time, balances.name, balances.account_balance + Int64(10) AS account_balance
114
+ ----------Filter: balances.time < Int64(10)
115
+ ------------TableScan: balances
116
+ physical_plan
117
+ SortExec: expr=[time@0 ASC NULLS LAST,name@1 ASC NULLS LAST,account_balance@2 ASC NULLS LAST]
118
+ --RecursiveQueryExec: is_distinct=false
119
+ ----CsvExec: file_groups={1 group: [[WORKSPACE_ROOT/testing/data/csv/r_cte_balance.csv]]}, projection=[time, name, account_balance], has_header=true
120
+ ----CoalescePartitionsExec
121
+ ------ProjectionExec: expr=[time@0 + 1 as time, name@1 as name, account_balance@2 + 10 as account_balance]
122
+ --------CoalesceBatchesExec: target_batch_size=2
123
+ ----------FilterExec: time@0 < 10
124
+ ------------RepartitionExec: partitioning=RoundRobinBatch(4), input_partitions=1
125
+ --------------WorkTableExec: name=balances
126
+
84
127
# recursive CTE with static term derived from table works
128
+ # note that this is run with batch size set to 2. This should produce multiple batches per iteration since the input
129
+ # table 'balances' has 4 rows
85
130
query ITI
86
131
WITH RECURSIVE balances AS (
87
132
SELECT * from balance
@@ -132,6 +177,9 @@ ORDER BY time, name, account_balance
132
177
10 Tim 290
133
178
10 Tim 480
134
179
180
+ # reset batch size to default
181
+ statement ok
182
+ set datafusion.execution.batch_size = 8182;
135
183
136
184
# recursive CTE with recursive join works
137
185
query ITI
0 commit comments