You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: datafusion/sqllogictest/test_files/stream.slt
+145-19
Original file line number
Diff line number
Diff line change
@@ -2,40 +2,45 @@
2
2
# This file does not contain any Apache Software Foundation copyrighted code.
3
3
4
4
5
-
# Once the PRIMARY KEY is supported, "sn" INTEGER PRIMARY KEY, will be replaced, WITH ORDER (sn ASC) line will be deleted.
5
+
# Please note that sn is PRIMARY KEY for this table.
6
6
statement ok
7
7
CREATE UNBOUNDED EXTERNAL TABLE sales_us (
8
-
"ts" TIMESTAMP,
9
-
"sn" INTEGER,
10
-
"amount" INTEGER,
11
-
"currency" VARCHAR NOT NULL
8
+
ts TIMESTAMP,
9
+
sn INTEGER,
10
+
amount INTEGER,
11
+
currency VARCHAR NOT NULL,
12
+
primary key(sn)
12
13
)
13
14
STORED AS CSV
14
15
WITH HEADER ROW
15
16
WITH ORDER (ts ASC)
16
17
WITH ORDER (sn ASC)
17
18
LOCATION '../core/tests/data/sales_us.csv';
18
19
20
+
# Please note that sn is PRIMARY KEY for this table.
19
21
statement ok
20
22
CREATE UNBOUNDED EXTERNAL TABLE sales_global (
21
-
"ts" TIMESTAMP,
22
-
"sn" INTEGER,
23
-
"amount" INTEGER,
24
-
"currency" VARCHAR NOT NULL
23
+
ts TIMESTAMP,
24
+
sn INTEGER,
25
+
amount INTEGER,
26
+
currency VARCHAR NOT NULL,
27
+
primary key(sn)
25
28
)
26
29
STORED AS CSV
27
30
WITH HEADER ROW
28
31
WITH ORDER (ts ASC)
29
32
WITH ORDER (sn ASC)
30
33
LOCATION '../core/tests/data/sales_global.csv';
31
34
35
+
# Please note that sn is PRIMARY KEY for this table.
32
36
statement ok
33
37
CREATE UNBOUNDED EXTERNAL TABLE exchange_rates (
34
-
"ts" TIMESTAMP,
35
-
"sn" INTEGER,
36
-
"currency_from" VARCHAR NOT NULL,
37
-
"currency_to" VARCHAR NOT NULL,
38
-
"rate" FLOAT
38
+
ts TIMESTAMP,
39
+
sn INTEGER,
40
+
currency_from VARCHAR NOT NULL,
41
+
currency_to VARCHAR NOT NULL,
42
+
rate FLOAT,
43
+
primary key(sn)
39
44
)
40
45
STORED AS CSV
41
46
WITH HEADER ROW
@@ -52,6 +57,20 @@ INTO annotated_sales_us
52
57
FROM sales_us AS s
53
58
ORDER BY sn
54
59
60
+
query PIITI
61
+
SELECT *
62
+
FROM annotated_sales_us
63
+
ORDER BY sn ASC
64
+
LIMIT 5;
65
+
----
66
+
2000-01-01T00:00:00 0 83 EUR 83
67
+
2000-01-01T00:00:15 1 40 TRY 123
68
+
2000-01-01T00:00:30 2 73 TRY 196
69
+
2000-01-01T00:00:45 3 54 EUR 250
70
+
2000-01-01T00:01:00 4 31 EUR 281
71
+
72
+
# This query is the version of the query above where result is not sinked.
73
+
# Physical plan of the query below shouldn't contain any SortExec.
55
74
query TT
56
75
EXPLAIN SELECT s.*, SUM(amount) OVER (ORDER BY sn)
57
76
FROM sales_us AS s
@@ -79,14 +98,16 @@ LIMIT 5
79
98
statement ok
80
99
drop table annotated_sales_us;
81
100
82
-
101
+
# Use other syntax to define window clause
83
102
statement ok
84
103
SELECT s.*, SUM(amount) OVER running_window
85
104
INTO annotated_sales_us
86
105
FROM sales_us AS s
87
106
WINDOW running_window AS (ORDER BY sn)
88
107
ORDER BY sn
89
108
109
+
# This query is the version of the query above where result is not sinked.
110
+
# Physical plan of the query below shouldn't contain SortExec.
90
111
query TT
91
112
EXPLAIN SELECT s.*, SUM(amount) OVER running_window
92
113
FROM sales_us AS s
@@ -123,6 +144,8 @@ FROM sales_us AS s
123
144
WINDOW sliding_window AS (ORDER BY sn ROWS 100 PRECEDING)
124
145
ORDER BY sn
125
146
147
+
# This query is the version of the query above where result is not sinked.
148
+
# Physical plan of the query below shouldn't contain SortExec.
126
149
query TT
127
150
EXPLAIN SELECT s.*, AVG(amount) OVER sliding_window
128
151
FROM sales_us AS s
@@ -151,9 +174,40 @@ LIMIT 5
151
174
statement ok
152
175
drop table annotated_sales_us;
153
176
154
-
# WINDOW sliding_window AS (ORDER BY ts RANGE INTERVAL '10' MINUTE PRECEDING) is not supported.
155
-
# It also gives an error in Postgre
177
+
# Make sure timestamp arithmetic is supported
178
+
statement ok
179
+
SELECT s.*, AVG(amount) OVER sliding_window
180
+
INTO annotated_sales_us
181
+
FROM sales_us AS s
182
+
WINDOW sliding_window AS (ORDER BY ts RANGE BETWEEN INTERVAL '17' SECOND PRECEDING AND INTERVAL '20' SECOND FOLLOWING)
183
+
ORDER BY sn
184
+
185
+
# This query is the version of the query above where result is not sinked.
186
+
# Physical plan of the query below shouldn't contain SortExec.
187
+
query TT
188
+
EXPLAIN SELECT s.*, AVG(amount) OVER sliding_window
189
+
FROM sales_us AS s
190
+
WINDOW sliding_window AS (ORDER BY ts RANGE BETWEEN INTERVAL '17' SECOND PRECEDING AND INTERVAL '20' SECOND FOLLOWING)
191
+
ORDER BY sn
192
+
----
193
+
logical_plan
194
+
Sort: s.sn ASC NULLS LAST
195
+
--WindowAggr: windowExpr=[[AVG(CAST(s.amount AS Float64)) ORDER BY [s.ts ASC NULLS LAST] RANGE BETWEEN 17000000000 PRECEDING AND 20000000000 FOLLOWING AS AVG(s.amount) ORDER BY [s.ts ASC NULLS LAST] RANGE BETWEEN 17 SECOND PRECEDING AND 20 SECOND FOLLOWING]]
BoundedWindowAggExec: wdw=[AVG(s.amount) ORDER BY [s.ts ASC NULLS LAST] RANGE BETWEEN 17 SECOND PRECEDING AND 20 SECOND FOLLOWING: Ok(Field { name: "AVG(s.amount) ORDER BY [s.ts ASC NULLS LAST] RANGE BETWEEN 17 SECOND PRECEDING AND 20 SECOND FOLLOWING", data_type: Float64, nullable: true, dict_id: 0, dict_is_ordered: false, metadata: {} }), frame: WindowFrame { units: Range, start_bound: Preceding(IntervalMonthDayNano("17000000000")), end_bound: Following(IntervalMonthDayNano("20000000000")) }], mode=[Sorted]
--ProjectionExec: expr=[ts@1 as ts, sn@0 as sn, amount@2 as amount, currency@3 as currency, CAST(amount@2 AS Float32) * LAST_VALUE(e.rate)@4 as amount_usd]
316
+
----AggregateExec: mode=FinalPartitioned, gby=[sn@0 as sn, ts@1 as ts, amount@2 as amount, currency@3 as currency], aggr=[LAST_VALUE(e.rate)], ordering_mode=PartiallySorted([0, 1])
----------AggregateExec: mode=Partial, gby=[sn@1 as sn, ts@0 as ts, amount@2 as amount, currency@3 as currency], aggr=[LAST_VALUE(e.rate)], ordering_mode=PartiallySorted([0, 1])
320
+
------------ProjectionExec: expr=[ts@3 as ts, sn@4 as sn, amount@5 as amount, currency@6 as currency, rate@2 as rate]
0 commit comments