Skip to content

Commit b37aa3e

Browse files
committed
Add tests with literals
1 parent 45962d6 commit b37aa3e

File tree

4 files changed

+266
-0
lines changed

4 files changed

+266
-0
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
-- Unit tests for simple NOT IN predicate subquery across multiple columns.
2+
--
3+
-- See not-in-single-column-unit-tests.sql for an introduction.
4+
-- This file has the same test cases as not-in-unit-tests-multi-column.sql with literals instead of
5+
-- subqueries. Small changes have been made to the literals to make them typecheck.
6+
7+
CREATE TEMPORARY VIEW m AS SELECT * FROM VALUES
8+
(null, null),
9+
(null, 1.0),
10+
(2, 3.0),
11+
(4, 5.0)
12+
AS m(a, b);
13+
14+
-- Case 1 (not possible to write a literal with no rows, so we ignore it.)
15+
-- (subquery is empty -> row is returned)
16+
17+
-- Case 2
18+
-- (subquery contains a row with null in all columns -> row not returned)
19+
SELECT *
20+
FROM m
21+
WHERE (a, b) NOT IN ((CAST (null AS INT), CAST (null AS DECIMAL(2, 1))));
22+
23+
-- Case 3
24+
-- (probe-side columns are all null -> row not returned)
25+
SELECT *
26+
FROM m
27+
WHERE a IS NULL AND b IS NULL -- Matches only (null, null)
28+
AND (a, b) NOT IN ((0, 1.0), (2, 3.0), (4, CAST(null AS DECIMAL(2, 1))));
29+
30+
-- Case 4
31+
-- (one column null, other column matches a row in the subquery result -> row not returned)
32+
SELECT *
33+
FROM m
34+
WHERE b = 1.0 -- Matches (null, 1.0)
35+
AND (a, b) NOT IN ((0, 1.0), (2, 3.0), (4, CAST(null AS DECIMAL(2, 1))));
36+
37+
-- Case 5
38+
-- (one null column with no match -> row is returned)
39+
SELECT *
40+
FROM m
41+
WHERE b = 1.0 -- Matches (null, 1.0)
42+
AND (a, b) NOT IN ((2, 3.0));
43+
44+
-- Case 6
45+
-- (no null columns with match -> row not returned)
46+
SELECT *
47+
FROM m
48+
WHERE b = 3.0 -- Matches (2, 3.0)
49+
AND (a, b) NOT IN ((2, 3.0))
50+
;
51+
52+
-- Case 7
53+
-- (no null columns with no match -> row is returned)
54+
SELECT *
55+
FROM m
56+
WHERE b = 5.0 -- Matches (4, 5.0)
57+
AND (a, b) NOT IN ((2, 3.0))
58+
;
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
-- Unit tests for simple NOT IN with a literal expression of a single column
2+
--
3+
-- More information can be found in not-in-unit-tests-single-column.sql.
4+
-- This file has the same test cases as not-in-unit-tests-single-column.sql with literals instead of
5+
-- subqueries.
6+
7+
CREATE TEMPORARY VIEW m AS SELECT * FROM VALUES
8+
(null, 1.0),
9+
(2, 3.0),
10+
(4, 5.0)
11+
AS m(a, b);
12+
13+
-- Uncorrelated NOT IN Subquery test cases
14+
-- Case 1 (not possible to write a literal with no rows, so we ignore it.)
15+
-- (empty subquery -> all rows returned)
16+
17+
-- Case 2
18+
-- (subquery includes null -> no rows returned)
19+
SELECT *
20+
FROM m
21+
WHERE a NOT IN (null);
22+
23+
-- Case 3
24+
-- (probe column is null -> row not returned)
25+
SELECT *
26+
FROM m
27+
WHERE b = 1.0 -- Only matches (null, 1.0)
28+
AND a NOT IN (2);
29+
30+
-- Case 4
31+
-- (probe column matches subquery row -> row not returned)
32+
SELECT *
33+
FROM m
34+
WHERE b = 3.0 -- Only matches (2, 3.0)
35+
AND a NOT IN (2);
36+
37+
-- Case 5
38+
-- (probe column does not match subquery row -> row is returned)
39+
SELECT *
40+
FROM m
41+
WHERE b = 3.0 -- Only matches (2, 3.0)
42+
AND a NOT IN (6);
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
-- Automatically generated by SQLQueryTestSuite
2+
-- Number of queries: 7
3+
4+
5+
-- !query 0
6+
CREATE TEMPORARY VIEW m AS SELECT * FROM VALUES
7+
(null, null),
8+
(null, 1.0),
9+
(2, 3.0),
10+
(4, 5.0)
11+
AS m(a, b)
12+
-- !query 0 schema
13+
struct<>
14+
-- !query 0 output
15+
16+
17+
18+
-- !query 1
19+
-- Case 1 (not possible to write a literal with no rows, so we ignore it.)
20+
-- (subquery is empty -> row is returned)
21+
22+
-- Case 2
23+
-- (subquery contains a row with null in all columns -> row not returned)
24+
SELECT *
25+
FROM m
26+
WHERE (a, b) NOT IN ((CAST (null AS INT), CAST (null AS DECIMAL(2, 1))))
27+
-- !query 1 schema
28+
struct<a:int,b:decimal(2,1)>
29+
-- !query 1 output
30+
2 3
31+
4 5
32+
NULL 1
33+
34+
35+
-- !query 2
36+
-- Case 3
37+
-- (probe-side columns are all null -> row not returned)
38+
SELECT *
39+
FROM m
40+
WHERE a IS NULL AND b IS NULL -- Matches only (null, null)
41+
AND (a, b) NOT IN ((0, 1.0), (2, 3.0), (4, CAST(null AS DECIMAL(2, 1))))
42+
-- !query 2 schema
43+
struct<a:int,b:decimal(2,1)>
44+
-- !query 2 output
45+
NULL NULL
46+
47+
48+
-- !query 3
49+
-- Case 4
50+
-- (one column null, other column matches a row in the subquery result -> row not returned)
51+
SELECT *
52+
FROM m
53+
WHERE b = 1.0 -- Matches (null, 1.0)
54+
AND (a, b) NOT IN ((0, 1.0), (2, 3.0), (4, CAST(null AS DECIMAL(2, 1))))
55+
-- !query 3 schema
56+
struct<a:int,b:decimal(2,1)>
57+
-- !query 3 output
58+
NULL 1
59+
60+
61+
-- !query 4
62+
-- Case 5
63+
-- (one null column with no match -> row is returned)
64+
SELECT *
65+
FROM m
66+
WHERE b = 1.0 -- Matches (null, 1.0)
67+
AND (a, b) NOT IN ((2, 3.0))
68+
-- !query 4 schema
69+
struct<a:int,b:decimal(2,1)>
70+
-- !query 4 output
71+
NULL 1
72+
73+
74+
-- !query 5
75+
-- Case 6
76+
-- (no null columns with match -> row not returned)
77+
SELECT *
78+
FROM m
79+
WHERE b = 3.0 -- Matches (2, 3.0)
80+
AND (a, b) NOT IN ((2, 3.0))
81+
-- !query 5 schema
82+
struct<a:int,b:decimal(2,1)>
83+
-- !query 5 output
84+
85+
86+
87+
-- !query 6
88+
-- Case 7
89+
-- (no null columns with no match -> row is returned)
90+
SELECT *
91+
FROM m
92+
WHERE b = 5.0 -- Matches (4, 5.0)
93+
AND (a, b) NOT IN ((2, 3.0))
94+
-- !query 6 schema
95+
struct<a:int,b:decimal(2,1)>
96+
-- !query 6 output
97+
4 5
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
-- Automatically generated by SQLQueryTestSuite
2+
-- Number of queries: 5
3+
4+
5+
-- !query 0
6+
CREATE TEMPORARY VIEW m AS SELECT * FROM VALUES
7+
(null, 1.0),
8+
(2, 3.0),
9+
(4, 5.0)
10+
AS m(a, b)
11+
-- !query 0 schema
12+
struct<>
13+
-- !query 0 output
14+
15+
16+
17+
-- !query 1
18+
-- Uncorrelated NOT IN Subquery test cases
19+
-- Case 1 (not possible to write a literal with no rows, so we ignore it.)
20+
-- (empty subquery -> all rows returned)
21+
22+
-- Case 2
23+
-- (subquery includes null -> no rows returned)
24+
SELECT *
25+
FROM m
26+
WHERE a NOT IN (null)
27+
-- !query 1 schema
28+
struct<a:int,b:decimal(2,1)>
29+
-- !query 1 output
30+
31+
32+
33+
-- !query 2
34+
-- Case 3
35+
-- (probe column is null -> row not returned)
36+
SELECT *
37+
FROM m
38+
WHERE b = 1.0 -- Only matches (null, 1.0)
39+
AND a NOT IN (2)
40+
-- !query 2 schema
41+
struct<a:int,b:decimal(2,1)>
42+
-- !query 2 output
43+
44+
45+
46+
-- !query 3
47+
-- Case 4
48+
-- (probe column matches subquery row -> row not returned)
49+
SELECT *
50+
FROM m
51+
WHERE b = 3.0 -- Only matches (2, 3.0)
52+
AND a NOT IN (2)
53+
-- !query 3 schema
54+
struct<a:int,b:decimal(2,1)>
55+
-- !query 3 output
56+
57+
58+
59+
-- !query 4
60+
-- Case 5
61+
-- (probe column does not match subquery row -> row is returned)
62+
SELECT *
63+
FROM m
64+
WHERE b = 3.0 -- Only matches (2, 3.0)
65+
AND a NOT IN (6)
66+
-- !query 4 schema
67+
struct<a:int,b:decimal(2,1)>
68+
-- !query 4 output
69+
2 3

0 commit comments

Comments
 (0)