forked from feldera/feldera
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_interval.py
More file actions
301 lines (248 loc) · 9.98 KB
/
test_interval.py
File metadata and controls
301 lines (248 loc) · 9.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
from tests.aggregate_tests.aggtst_base import TstView
# LONG INTERVAL
class arithtst_atbl_long_interval(TstView):
"""Define the view used by long interval tests as input"""
def __init__(self):
# Result validation is not required for local views
self.data = []
self.sql = """CREATE LOCAL VIEW atbl_long_interval AS SELECT
id,
(c1 - c2)MONTH AS months
FROM timestamp_tbl"""
class arithtst_atbl_long_interval_res(TstView):
def __init__(self):
# Validated on MySQL
self.data = [
{"id": 0, "months_res": 60},
{"id": 1, "months_res": -32},
{"id": 2, "months_res": 126},
]
self.sql = """CREATE MATERIALIZED VIEW atbl_long_interval_res AS SELECT
id,
CAST((months) AS BIGINT) AS months_res
FROM atbl_long_interval"""
# Equivalent MySQL program
# SELECT
# id,
# TIMESTAMPDIFF(MONTH, c2, c1) AS f_c1
# FROM timestamp_tbl;
# SHORT INTERVAL
class arithtst_atbl_short_interval(TstView):
"""Define the view used by short interval tests as input"""
def __init__(self):
# Result validation is not required for local views
self.data = []
self.sql = """CREATE LOCAL VIEW atbl_short_interval AS SELECT
id,
(c1 - c2)SECOND AS seconds
FROM timestamp_tbl"""
class arithtst_atbl_short_interval_res(TstView):
def __init__(self):
# Validated on MySQL
self.data = [
{"id": 0, "seconds_res": 160342920},
{"id": 1, "seconds_res": -84686400},
{"id": 2, "seconds_res": 332907420},
]
self.sql = """CREATE MATERIALIZED VIEW atbl_short_interval_res AS SELECT
id,
CAST((seconds) AS BIGINT) AS seconds_res
FROM atbl_short_interval"""
# Equivalent MySQL program
# SELECT
# id,
# TIMESTAMPDIFF(SECOND, c2, c1) AS f_c1
# FROM timestamp_tbl;
class arithtst_linterval_minus_linterval(TstView):
def __init__(self):
# Result validation is not required for local views
self.data = []
self.sql = """CREATE LOCAL VIEW linterval_minus_linterval AS SELECT
id,
months - INTERVAL '10' MONTH AS f_c1
FROM atbl_long_interval"""
class arithtst_linterval_minus_linterval_res(TstView):
def __init__(self):
# checked manually
self.data = [
{"id": 0, "f_c1_res": 50},
{"id": 1, "f_c1_res": -42},
{"id": 2, "f_c1_res": 116},
]
self.sql = """CREATE MATERIALIZED VIEW linterval_minus_linterval_res AS SELECT
id,
CAST((f_c1) AS BIGINT) AS f_c1_res
FROM linterval_minus_linterval"""
class arithtst_sinterval_minus_sinterval(TstView):
def __init__(self):
# Result validation is not required for local views
self.data = []
self.sql = """CREATE LOCAL VIEW sinterval_minus_sinterval AS SELECT
id,
seconds - INTERVAL '1567890' SECOND AS f_c1
FROM atbl_short_interval"""
class arithtst_sinterval_minus_sinterval_res(TstView):
def __init__(self):
# Validated on Postgres
self.data = [
{"id": 0, "f_c1_res": 158775030},
{"id": 1, "f_c1_res": -86254290},
{"id": 2, "f_c1_res": 331339530},
]
self.sql = """CREATE MATERIALIZED VIEW sinterval_minus_sinterval_res AS SELECT
id,
CAST((f_c1) AS BIGINT) AS f_c1_res
FROM sinterval_minus_sinterval"""
# Equivalent Postgres SQL
# CREATE TABLE atbl_interval AS SELECT
# id,
# c1 - c2 AS c1_minus_c2
# FROM timestamp_tbl;
#
# SELECT
# id,
# EXTRACT(EPOCH FROM (c1_minus_c2 - INTERVAL '1567890 second')) AS f_c1
# FROM atbl_interval;
class arithtst_linterval_plus_linterval(TstView):
def __init__(self):
# Result validation is not required for local views
self.data = []
self.sql = """CREATE LOCAL VIEW linterval_plus_linterval AS SELECT
id,
months + INTERVAL '10' MONTH AS f_c1
FROM atbl_long_interval"""
class arithtst_linterval_plus_linterval_res(TstView):
def __init__(self):
# checked manually
self.data = [
{"id": 0, "f_c1_res": 70},
{"id": 1, "f_c1_res": -22},
{"id": 2, "f_c1_res": 136},
]
self.sql = """CREATE MATERIALIZED VIEW linterval_plus_linterval_res AS SELECT
id,
CAST((f_c1) AS BIGINT) AS f_c1_res
FROM linterval_plus_linterval"""
class arithtst_sinterval_plus_sinterval(TstView):
def __init__(self):
# Result validation is not required for local views
self.data = []
self.sql = """CREATE LOCAL VIEW sinterval_plus_sinterval AS SELECT
id,
seconds + INTERVAL '1567890' SECOND AS f_c1
FROM atbl_short_interval"""
class arithtst_sinterval_plus_sinterval_res(TstView):
def __init__(self):
# Validated on Postgres
self.data = [
{"id": 0, "f_c1_res": 161910810},
{"id": 1, "f_c1_res": -83118510},
{"id": 2, "f_c1_res": 334475310},
]
self.sql = """CREATE MATERIALIZED VIEW sinterval_plus_sinterval_res AS SELECT
id,
CAST((f_c1) AS BIGINT) AS f_c1_res
FROM sinterval_plus_sinterval"""
# Equivalent Postgres SQL
# CREATE TABLE atbl_interval AS SELECT
# id,
# c1 - c2 AS c1_minus_c2
# FROM timestamp_tbl;
#
# SELECT
# id,
# EXTRACT(EPOCH FROM (c1_minus_c2 + INTERVAL '1567890 second')) AS f_c1
# FROM atbl_interval;
class arithtst_linterval_negation(TstView):
def __init__(self):
# Validated on Postgres
self.data = [
{"id": 0, "f_c1": "2019-12-05", "f_c2": "2014-12-05T08:27:00"},
{"id": 1, "f_c1": "2027-08-05", "f_c2": "2022-08-05T08:27:00"},
{"id": 2, "f_c1": "2014-06-05", "f_c2": "2009-06-05T08:27:00"},
]
self.sql = """CREATE MATERIALIZED VIEW linterval_negation AS SELECT
id,
'2024-12-05':: DATE + (- months) AS f_c1,
'2019-12-05 08:27:00'::TIMESTAMP + (- months) AS f_c2
FROM atbl_long_interval"""
class arithtst_sinterval_negation(TstView):
def __init__(self):
# Validated on Postgres
self.data = [
{"id": 0, "f_c1": "22:48:00", "f_c2": "2014-11-05T12:45:00"},
{"id": 1, "f_c1": "22:30:00", "f_c2": "2022-08-11T12:27:00"},
{"id": 2, "f_c1": "16:13:00", "f_c2": "2009-05-18T06:10:00"},
]
self.sql = """CREATE MATERIALIZED VIEW sinterval_negation AS SELECT
id,
'18:30:00':: TIME + (- seconds) AS f_c1,
'2019-12-05 08:27:00'::TIMESTAMP + (- seconds) AS f_c2
FROM atbl_short_interval"""
# Equivalent Postgres SQL:
# SELECT '2024-12-05':: DATE + (- INTERVAL 'value in months') date_neg;
# SELECT '2019-12-05 08:27:00'::TIMESTAMP + (- INTERVAL 'value in months/seconds') timestamp_neg;
# SELECT '18:30:00'::TIME + (- INTERVAL 'value in seconds') time_neg;
class arithtst_neg(TstView):
def __init__(self):
# Result validation is not required for local views
self.data = []
self.sql = """CREATE LOCAL VIEW neg AS SELECT
v1.id,
(-v1.months) AS months_neg,
(-v2.seconds) AS seconds_neg
FROM atbl_long_interval v1
JOIN atbl_short_interval v2 ON v1.id = v2.id;"""
class arithtst_neg_res(TstView):
def __init__(self):
# checked manually
self.data = [
{"id": 0, "f_c1": -60, "f_c2": -160342920},
{"id": 1, "f_c1": 32, "f_c2": 84686400},
{"id": 2, "f_c1": -126, "f_c2": -332907420},
]
self.sql = """CREATE MATERIALIZED VIEW neg_res AS SELECT
id,
CAST((months_neg) AS BIGINT) AS f_c1,
CAST((seconds_neg) AS BIGINT) AS f_c2
FROM neg"""
class arithtst_linterval_mul_double(TstView):
def __init__(self):
# Result validation is not required for local views
self.data = []
self.sql = """CREATE LOCAL VIEW linterval_mul_double AS SELECT
id,
months * 2.583 AS f_c1
FROM atbl_long_interval"""
class arithtst_linterval_mul_double_res(TstView):
def __init__(self):
# checked manually
self.data = [
{"id": 0, "f_c1": "+154"},
{"id": 1, "f_c1": "-82"},
{"id": 2, "f_c1": "+325"},
]
self.sql = """CREATE MATERIALIZED VIEW linterval_mul_double_res AS SELECT
id,
CAST((f_c1) AS VARCHAR) AS f_c1
FROM linterval_mul_double"""
class arithtst_linterval_div_double(TstView):
def __init__(self):
# Result validation is not required for local views
self.data = []
self.sql = """CREATE LOCAL VIEW linterval_div_double AS SELECT
id,
months / 2.583 AS f_c1
FROM atbl_long_interval"""
class arithtst_linterval_div_double_res(TstView):
def __init__(self):
# checked manually
self.data = [
{"id": 0, "f_c1": "+23"},
{"id": 1, "f_c1": "-12"},
{"id": 2, "f_c1": "+48"},
]
self.sql = """CREATE MATERIALIZED VIEW linterval_div_double_res AS SELECT
id,
CAST((f_c1) AS VARCHAR) AS f_c1
FROM linterval_div_double"""