-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy pathpredicates.slt
482 lines (394 loc) · 10.8 KB
/
predicates.slt
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
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
##########
## Limit Tests
##########
statement ok
CREATE EXTERNAL TABLE aggregate_test_100 (
c1 VARCHAR NOT NULL,
c2 TINYINT NOT NULL,
c3 SMALLINT NOT NULL,
c4 SMALLINT,
c5 INT,
c6 BIGINT NOT NULL,
c7 SMALLINT NOT NULL,
c8 INT NOT NULL,
c9 BIGINT UNSIGNED NOT NULL,
c10 VARCHAR NOT NULL,
c11 FLOAT NOT NULL,
c12 DOUBLE NOT NULL,
c13 VARCHAR NOT NULL
)
STORED AS CSV
WITH HEADER ROW
LOCATION '../../testing/data/csv/aggregate_test_100.csv'
statement ok
CREATE EXTERNAL TABLE alltypes_plain STORED AS PARQUET LOCATION '../../parquet-testing/data/alltypes_plain.parquet';
# async fn csv_query_with_predicate()
query TR
SELECT c1, c12 FROM aggregate_test_100 WHERE c12 > 0.376 AND c12 < 0.4
----
e 0.391444365692
d 0.38870280984
# async fn csv_query_with_negative_predicate
query TI
SELECT c1, c4 FROM aggregate_test_100 WHERE c3 < -55 AND -c4 > 30000
----
e -31500
c -30187
# async fn csv_query_with_negated_predicate()
query I
SELECT COUNT(1) FROM aggregate_test_100 WHERE NOT(c1 != 'a')
----
21
# async fn csv_query_with_is_not_null_predicate
query I
SELECT COUNT(1) FROM aggregate_test_100 WHERE c1 IS NOT NULL
----
100
# async fn csv_query_with_is_null_predicate
query I
SELECT COUNT(1) FROM aggregate_test_100 WHERE c1 IS NULL
----
0
# async fn query_where_neg_num
query II
select c7, c8 from aggregate_test_100 where c7 >= -2 and c7 < 10
----
7 45465
5 40622
0 61069
2 20120
4 39363
query II
select c7, c8 from aggregate_test_100 where c7 >= -2.9 and c7 < 10
----
7 45465
5 40622
0 61069
2 20120
4 39363
# async fn like
query I
SELECT COUNT(c1) FROM aggregate_test_100 WHERE c13 LIKE '%FB%'
----
1
# async fn csv_between_expr
query I
SELECT c4 FROM aggregate_test_100 WHERE c12 BETWEEN 0.995 AND 1.0
----
10837
# async fn csv_between_expr_negated
query I
SELECT c4 FROM aggregate_test_100 WHERE c12 NOT BETWEEN 0 AND 0.995
----
10837
# async fn csv_in_set_test
query I
SELECT count(*) FROM aggregate_test_100 WHERE c7 in ('25','155','204','77','208','67','139','191','26','7','202','113','129','197','249','146','129','220','154','163','220','19','71','243','150','231','196','170','99','255')
----
36
# async fn except_with_null_not_equal
query ?I
SELECT * FROM (SELECT null AS id1, 1 AS id2) t1
EXCEPT
SELECT * FROM (SELECT null AS id1, 2 AS id2) t2
----
NULL 1
# async fn except_with_null_equal
query ?I
SELECT * FROM (SELECT null AS id1, 1 AS id2) t1
EXCEPT
SELECT * FROM (SELECT null AS id1, 1 AS id2) t2
----
statement ok
CREATE TABLE IF NOT EXISTS test AS VALUES('foo'),('bar'),(NULL),('fazzz');
# async fn like_on_strings
query T
SELECT * FROM test WHERE column1 LIKE '%a%'
----
bar
fazzz
# async fn like_on_string_dictionaries
query T
SELECT * FROM test WHERE column1 LIKE '%a%'
----
bar
fazzz
# async fn in_list_string_dictionaries_with_null
query T
SELECT * FROM test WHERE column1 IN ('Bar')
----
query T
SELECT * FROM test WHERE column1 IN ('foo')
----
foo
query T
SELECT * FROM test WHERE column1 IN ('bar', 'foo')
----
foo
bar
query T
SELECT * FROM test WHERE column1 IN ('Bar', 'foo')
----
foo
query T
SELECT * FROM test WHERE column1 IN ('foo', 'Bar', 'fazzz')
----
foo
fazzz
# async fn in_set_string_dictionaries
query T
SELECT * FROM test WHERE column1 IN ('foo', 'Bar', 'fazzz')
----
foo
fazzz
statement ok
DROP TABLE test;
statement ok
CREATE TABLE IF NOT EXISTS test AS VALUES('foo'),('Barrr'),('Bazzz'),('ZZZZZ');
# async fn test_regexp_is_match
query error Error during planning: Cannot infer common argument type for regex operation Int64 \~ Utf8
SELECT * FROM test WHERE 12 ~ 'z'
query T
SELECT * FROM test WHERE column1 ~ 'z'
----
Bazzz
query T
SELECT * FROM test WHERE column1 ~* 'z'
----
Bazzz
ZZZZZ
query T
SELECT * FROM test WHERE column1 !~ 'z'
----
foo
Barrr
ZZZZZ
query T
SELECT * FROM test WHERE column1 !~* 'z'
----
foo
Barrr
statement ok
DROP TABLE test;
statement ok
CREATE TABLE IF NOT EXISTS test AS VALUES('foo'),('bar'),('fazzz');
# async fn in_list_string_dictionaries
query T
SELECT * FROM test WHERE column1 IN ('Bar')
----
query T
SELECT * FROM test WHERE column1 IN ('foo')
----
foo
query T
SELECT * FROM test WHERE column1 IN ('bar', 'foo')
----
foo
bar
query T
SELECT * FROM test WHERE column1 IN ('Bar', 'foo')
----
foo
query T
SELECT * FROM test WHERE column1 IN ('foo', 'Bar', 'fazzz')
----
foo
fazzz
statement ok
CREATE TABLE IF NOT EXISTS test_float AS VALUES
('a', 1.2, 2.3, 1.2, -3.5, 1.1),
('b', 2.1, 'NaN'::double, -1.7, -8.2, NULL),
('c', NULL, NULL, '-NaN'::double, -5.4, 1.5),
('d', 'NaN'::double, 'NaN'::double, 1.1, '-NaN'::double, NULL),
('e', '-NaN'::double, 6.2, 'NaN'::double, -3.3, 5.6)
;
# IN expr for float
query T
SELECT column1 FROM test_float WHERE column2 IN (0.0, -1.2)
----
query T
SELECT column1 FROM test_float WHERE column2 IN (0.0, 1.2)
----
a
query T
SELECT column1 FROM test_float WHERE column2 IN (2.1, 1.2)
----
a
b
query T
SELECT column1 FROM test_float WHERE column2 IN (0.0, 1.2, NULL)
----
a
query T
SELECT column1 FROM test_float WHERE column2 IN (0.0, -1.2, NULL)
----
query T
SELECT column1 FROM test_float WHERE column2 IN (0.0, 1.2, 'NaN'::double, '-NaN'::double)
----
a
d
e
query T
SELECT column1 FROM test_float WHERE column2 IN (column3, column4, column5, column6)
----
a
d
query T
SELECT column1 FROM test_float WHERE column2 IN (column3, column4, column5, column6, 2.1, NULL, '-NaN'::double)
----
a
b
d
e
query T
SELECT column1 FROM test_float WHERE column2 NOT IN (column3, column4, column5, column6)
----
e
query T
SELECT column1 FROM test_float WHERE column2 NOT IN (column3, column4, column5, column6, 2.1, NULL, '-NaN'::double)
----
query T
SELECT column1 FROM test_float WHERE NULL IN (column2, column2 + 1, column2 + 2, column2 + 3)
----
query T
SELECT column1 FROM test_float WHERE 'NaN'::double IN (column2, column2 + 1, column2 + 2, column2 + 3)
----
d
query T
SELECT column1 FROM test_float WHERE '-NaN'::double IN (column2, column2 + 1, column2 + 2, column2 + 3)
----
e
query II
SELECT c3, c7 FROM aggregate_test_100 WHERE c3 IN (c7 / 10, c7 / 20, c7 / 30, c7 / 40, 68, 103)
----
1 25
103 146
68 224
68 121
3 133
###
# Test logical plan simplifies large OR chains
###
statement ok
set datafusion.explain.logical_plan_only = true
# Number of OR statements is less than or equal to threshold
query TT
EXPLAIN SELECT * FROM test WHERE column1 = 'foo' OR column1 = 'bar' OR column1 = 'fazzz'
----
logical_plan
Filter: test.column1 = Utf8("foo") OR test.column1 = Utf8("bar") OR test.column1 = Utf8("fazzz")
--TableScan: test projection=[column1]
# Number of OR statements is greater than threshold
query TT
EXPLAIN SELECT * FROM test WHERE column1 = 'foo' OR column1 = 'bar' OR column1 = 'fazzz' OR column1 = 'barfoo'
----
logical_plan
Filter: test.column1 IN ([Utf8("foo"), Utf8("bar"), Utf8("fazzz"), Utf8("barfoo")])
--TableScan: test projection=[column1]
# Complex OR statements
query TT
EXPLAIN SELECT * FROM test WHERE column1 = 'foo' OR column1 = 'bar' OR column1 = 'fazzz' OR column1 = 'barfoo' OR false OR column1 = 'foobar'
----
logical_plan
Filter: test.column1 IN ([Utf8("foo"), Utf8("bar"), Utf8("fazzz"), Utf8("barfoo"), Utf8("foobar")])
--TableScan: test projection=[column1]
# Balanced OR structures
query TT
EXPLAIN SELECT * FROM test WHERE (column1 = 'foo' OR column1 = 'bar') OR (column1 = 'fazzz' OR column1 = 'barfoo')
----
logical_plan
Filter: test.column1 IN ([Utf8("foo"), Utf8("bar"), Utf8("fazzz"), Utf8("barfoo")])
--TableScan: test projection=[column1]
# Right-deep OR structures
query TT
EXPLAIN SELECT * FROM test WHERE column1 = 'foo' OR (column1 = 'bar' OR (column1 = 'fazzz' OR column1 = 'barfoo'))
----
logical_plan
Filter: test.column1 IN ([Utf8("foo"), Utf8("bar"), Utf8("fazzz"), Utf8("barfoo")])
--TableScan: test projection=[column1]
# Not simplifiable, mixed column
query TT
EXPLAIN SELECT * FROM aggregate_test_100
WHERE (c2 = 1 OR c3 = 100) OR (c2 = 2 OR c2 = 3 OR c2 = 4)
----
logical_plan
Filter: aggregate_test_100.c2 = Int8(1) OR aggregate_test_100.c3 = Int16(100) OR aggregate_test_100.c2 = Int8(2) OR aggregate_test_100.c2 = Int8(3) OR aggregate_test_100.c2 = Int8(4)
--TableScan: aggregate_test_100 projection=[c1, c2, c3, c4, c5, c6, c7, c8, c9, c10, c11, c12, c13], partial_filters=[aggregate_test_100.c2 = Int8(1) OR aggregate_test_100.c3 = Int16(100) OR aggregate_test_100.c2 = Int8(2) OR aggregate_test_100.c2 = Int8(3) OR aggregate_test_100.c2 = Int8(4)]
# Partially simplifiable, mixed column
query TT
EXPLAIN SELECT * FROM aggregate_test_100
WHERE (c2 = 1 OR c3 = 100) OR (c2 = 2 OR c2 = 3 OR c2 = 4 OR c2 = 5)
----
logical_plan
Filter: aggregate_test_100.c2 = Int8(1) OR aggregate_test_100.c3 = Int16(100) OR aggregate_test_100.c2 IN ([Int8(2), Int8(3), Int8(4), Int8(5)])
--TableScan: aggregate_test_100 projection=[c1, c2, c3, c4, c5, c6, c7, c8, c9, c10, c11, c12, c13], partial_filters=[aggregate_test_100.c2 = Int8(1) OR aggregate_test_100.c3 = Int16(100) OR aggregate_test_100.c2 IN ([Int8(2), Int8(3), Int8(4), Int8(5)])]
statement ok
set datafusion.explain.logical_plan_only = false
# async fn test_expect_all
query IR
SELECT int_col, double_col FROM alltypes_plain where int_col > 0 EXCEPT ALL SELECT int_col, double_col FROM alltypes_plain where int_col < 1
----
1 10.1
1 10.1
1 10.1
1 10.1
# async fn test_expect_distinct
query IR
SELECT int_col, double_col FROM alltypes_plain where int_col > 0 EXCEPT SELECT int_col, double_col FROM alltypes_plain where int_col < 1
----
1 10.1
########
# Clean up after the test
########
statement ok
drop table aggregate_test_100;
statement ok
drop table alltypes_plain;
statement ok
DROP TABLE test;
statement ok
DROP TABLE test_float;
#########
# Predicates on memory tables / statistics generation
# Reproducer for https://github.com/apache/arrow-datafusion/issues/7125
#########
statement ok
CREATE TABLE t (i integer, s string, b boolean) AS VALUES
(1, 'One', true),
(2, 'Two', false),
(NULL, NULL, NULL),
(4, 'Four', false)
;
query ITB
select * from t where (b OR b) = b;
----
1 One true
2 Two false
4 Four false
query ITB
select * from t where (s LIKE 'T%') = true;
----
2 Two false
query ITB
select * from t where (i & 3) = 1;
----
1 One true
########
# Clean up after the test
########
statement ok
DROP TABLE t;