File tree Expand file tree Collapse file tree 1 file changed +78
-0
lines changed
datafusion/sqllogictest/test_files Expand file tree Collapse file tree 1 file changed +78
-0
lines changed Original file line number Diff line number Diff line change @@ -20,6 +20,7 @@ select * from (WITH source AS (select 1 as e) SELECT * FROM source) t1, (WITH
2020----
21211 1
2222
23+ # trivial recursive CTE works
2324query I rowsort
2425WITH RECURSIVE nodes AS (
2526 SELECT 1 as id
@@ -40,3 +41,80 @@ SELECT * FROM nodes
40417
41428
42439
44+
45+ # setup
46+ statement ok
47+ CREATE EXTERNAL TABLE beg_account_balance STORED as CSV WITH HEADER ROW LOCATION '../../testing/data/csv/recursive_query_account_beg_2.csv'
48+
49+ # setup
50+ statement ok
51+ CREATE EXTERNAL TABLE account_balance_growth STORED as CSV WITH HEADER ROW LOCATION '../../testing/data/csv/recursive_query_account_growth_2.csv'
52+
53+ # recursive CTE with static term derived from table works
54+ query ITI rowsort
55+ WITH RECURSIVE balances AS (
56+ SELECT * from beg_account_balance
57+ UNION ALL
58+ SELECT time + 1 as time, name, account_balance + 10 as account_balance
59+ FROM balances
60+ WHERE time < 10
61+ )
62+ SELECT * FROM balances
63+ ----
64+ 1 John 100
65+ 1 Tim 200
66+ 10 John 190
67+ 10 Tim 290
68+ 2 John 110
69+ 2 Tim 210
70+ 3 John 120
71+ 3 Tim 220
72+ 4 John 130
73+ 4 Tim 230
74+ 5 John 140
75+ 5 Tim 240
76+ 6 John 150
77+ 6 Tim 250
78+ 7 John 160
79+ 7 Tim 260
80+ 8 John 170
81+ 8 Tim 270
82+ 9 John 180
83+ 9 Tim 280
84+
85+
86+ # recursive CTE with recursive join works
87+ query ITI
88+ WITH RECURSIVE balances AS (
89+ SELECT time as time, name as name, account_balance as account_balance
90+ FROM beg_account_balance
91+ UNION ALL
92+ SELECT time + 1 as time, balances.name, account_balance + account_balance_growth.account_growth as account_balance
93+ FROM balances
94+ JOIN account_balance_growth
95+ ON balances.name = account_balance_growth.name
96+ WHERE time < 10
97+ )
98+ SELECT * FROM balances
99+ ORDER BY time, name
100+ ----
101+ 1 John 100
102+ 1 Tim 200
103+ 2 John 103
104+ 2 Tim 220
105+ 3 John 106
106+ 3 Tim 240
107+ 4 John 109
108+ 4 Tim 260
109+ 5 John 112
110+ 5 Tim 280
111+ 6 John 115
112+ 6 Tim 300
113+ 7 John 118
114+ 7 Tim 320
115+ 8 John 121
116+ 8 Tim 340
117+ 9 John 124
118+ 9 Tim 360
119+ 10 John 127
120+ 10 Tim 380
You can’t perform that action at this time.
0 commit comments