Skip to content

Commit 2c330fc

Browse files
committed
chore: forgot null type
Signed-off-by: Dennis Zhuang <[email protected]>
1 parent e43b944 commit 2c330fc

File tree

2 files changed

+220
-0
lines changed

2 files changed

+220
-0
lines changed
Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
-- Migrated from DuckDB test: test/sql/types/null/test_null.test
2+
-- Test NULL value handling across different contexts
3+
-- Test NULL in basic operations
4+
CREATE TABLE null_test(i INTEGER, s VARCHAR, ts TIMESTAMP TIME INDEX);
5+
6+
Affected Rows: 0
7+
8+
INSERT INTO null_test VALUES
9+
(1, 'hello', 1000),
10+
(NULL, 'world', 2000),
11+
(3, NULL, 3000),
12+
(NULL, NULL, 4000);
13+
14+
Affected Rows: 4
15+
16+
-- Test NULL comparisons
17+
SELECT i, s FROM null_test WHERE i IS NULL ORDER BY ts;
18+
19+
+---+-------+
20+
| i | s |
21+
+---+-------+
22+
| | world |
23+
| | |
24+
+---+-------+
25+
26+
SELECT i, s FROM null_test WHERE i IS NOT NULL ORDER BY ts;
27+
28+
+---+-------+
29+
| i | s |
30+
+---+-------+
31+
| 1 | hello |
32+
| 3 | |
33+
+---+-------+
34+
35+
SELECT i, s FROM null_test WHERE s IS NULL ORDER BY ts;
36+
37+
+---+---+
38+
| i | s |
39+
+---+---+
40+
| 3 | |
41+
| | |
42+
+---+---+
43+
44+
SELECT i, s FROM null_test WHERE s IS NOT NULL ORDER BY ts;
45+
46+
+---+-------+
47+
| i | s |
48+
+---+-------+
49+
| 1 | hello |
50+
| | world |
51+
+---+-------+
52+
53+
-- Test NULL in arithmetic
54+
SELECT i, i + 1, i * 2, i - 5 FROM null_test ORDER BY ts;
55+
56+
+---+------------------------+------------------------+------------------------+
57+
| i | null_test.i + Int64(1) | null_test.i * Int64(2) | null_test.i - Int64(5) |
58+
+---+------------------------+------------------------+------------------------+
59+
| 1 | 2 | 2 | -4 |
60+
| | | | |
61+
| 3 | 4 | 6 | -2 |
62+
| | | | |
63+
+---+------------------------+------------------------+------------------------+
64+
65+
-- Test NULL in string operations
66+
SELECT s, CONCAT(s, ' test'), UPPER(s), LENGTH(s) FROM null_test ORDER BY ts;
67+
68+
+-------+-----------------------------------+--------------------+-------------------------------+
69+
| s | concat(null_test.s,Utf8(" test")) | upper(null_test.s) | character_length(null_test.s) |
70+
+-------+-----------------------------------+--------------------+-------------------------------+
71+
| hello | hello test | HELLO | 5 |
72+
| world | world test | WORLD | 5 |
73+
| | test | | |
74+
| | test | | |
75+
+-------+-----------------------------------+--------------------+-------------------------------+
76+
77+
-- Test NULL with COALESCE
78+
SELECT i, s, COALESCE(i, -1), COALESCE(s, 'missing') FROM null_test ORDER BY ts;
79+
80+
+---+-------+---------------------------------+---------------------------------------+
81+
| i | s | coalesce(null_test.i,Int64(-1)) | coalesce(null_test.s,Utf8("missing")) |
82+
+---+-------+---------------------------------+---------------------------------------+
83+
| 1 | hello | 1 | hello |
84+
| | world | -1 | world |
85+
| 3 | | 3 | missing |
86+
| | | -1 | missing |
87+
+---+-------+---------------------------------+---------------------------------------+
88+
89+
-- Test NULL in aggregates
90+
SELECT COUNT(*), COUNT(i), COUNT(s) FROM null_test;
91+
92+
+----------+--------------------+--------------------+
93+
| count(*) | count(null_test.i) | count(null_test.s) |
94+
+----------+--------------------+--------------------+
95+
| 4 | 2 | 2 |
96+
+----------+--------------------+--------------------+
97+
98+
SELECT SUM(i), AVG(i), MAX(i), MIN(i) FROM null_test;
99+
100+
+------------------+------------------+------------------+------------------+
101+
| sum(null_test.i) | avg(null_test.i) | max(null_test.i) | min(null_test.i) |
102+
+------------------+------------------+------------------+------------------+
103+
| 4 | 2.0 | 3 | 1 |
104+
+------------------+------------------+------------------+------------------+
105+
106+
-- Test NULL in CASE expressions
107+
SELECT i, s,
108+
CASE
109+
WHEN i IS NULL THEN 'no number'
110+
WHEN i > 2 THEN 'big number'
111+
ELSE 'small number'
112+
END as category
113+
FROM null_test ORDER BY ts;
114+
115+
+---+-------+--------------+
116+
| i | s | category |
117+
+---+-------+--------------+
118+
| 1 | hello | small number |
119+
| | world | no number |
120+
| 3 | | big number |
121+
| | | no number |
122+
+---+-------+--------------+
123+
124+
-- Test NULL in GROUP BY
125+
SELECT i, COUNT(*) FROM null_test GROUP BY i ORDER BY i;
126+
127+
+---+----------+
128+
| i | count(*) |
129+
+---+----------+
130+
| 1 | 1 |
131+
| 3 | 1 |
132+
| | 2 |
133+
+---+----------+
134+
135+
SELECT s, COUNT(*) FROM null_test GROUP BY s ORDER BY s;
136+
137+
+-------+----------+
138+
| s | count(*) |
139+
+-------+----------+
140+
| hello | 1 |
141+
| world | 1 |
142+
| | 2 |
143+
+-------+----------+
144+
145+
-- Test NULLIF function
146+
SELECT i, NULLIF(i, 1) FROM null_test ORDER BY ts;
147+
148+
+---+------------------------------+
149+
| i | nullif(null_test.i,Int64(1)) |
150+
+---+------------------------------+
151+
| 1 | |
152+
| | |
153+
| 3 | 3 |
154+
| | |
155+
+---+------------------------------+
156+
157+
SELECT s, NULLIF(s, 'hello') FROM null_test ORDER BY ts;
158+
159+
+-------+-----------------------------------+
160+
| s | nullif(null_test.s,Utf8("hello")) |
161+
+-------+-----------------------------------+
162+
| hello | |
163+
| world | world |
164+
| | |
165+
| | |
166+
+-------+-----------------------------------+
167+
168+
DROP TABLE null_test;
169+
170+
Affected Rows: 0
171+
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
-- Migrated from DuckDB test: test/sql/types/null/test_null.test
2+
-- Test NULL value handling across different contexts
3+
4+
-- Test NULL in basic operations
5+
CREATE TABLE null_test(i INTEGER, s VARCHAR, ts TIMESTAMP TIME INDEX);
6+
7+
INSERT INTO null_test VALUES
8+
(1, 'hello', 1000),
9+
(NULL, 'world', 2000),
10+
(3, NULL, 3000),
11+
(NULL, NULL, 4000);
12+
13+
-- Test NULL comparisons
14+
SELECT i, s FROM null_test WHERE i IS NULL ORDER BY ts;
15+
SELECT i, s FROM null_test WHERE i IS NOT NULL ORDER BY ts;
16+
SELECT i, s FROM null_test WHERE s IS NULL ORDER BY ts;
17+
SELECT i, s FROM null_test WHERE s IS NOT NULL ORDER BY ts;
18+
19+
-- Test NULL in arithmetic
20+
SELECT i, i + 1, i * 2, i - 5 FROM null_test ORDER BY ts;
21+
22+
-- Test NULL in string operations
23+
SELECT s, CONCAT(s, ' test'), UPPER(s), LENGTH(s) FROM null_test ORDER BY ts;
24+
25+
-- Test NULL with COALESCE
26+
SELECT i, s, COALESCE(i, -1), COALESCE(s, 'missing') FROM null_test ORDER BY ts;
27+
28+
-- Test NULL in aggregates
29+
SELECT COUNT(*), COUNT(i), COUNT(s) FROM null_test;
30+
SELECT SUM(i), AVG(i), MAX(i), MIN(i) FROM null_test;
31+
32+
-- Test NULL in CASE expressions
33+
SELECT i, s,
34+
CASE
35+
WHEN i IS NULL THEN 'no number'
36+
WHEN i > 2 THEN 'big number'
37+
ELSE 'small number'
38+
END as category
39+
FROM null_test ORDER BY ts;
40+
41+
-- Test NULL in GROUP BY
42+
SELECT i, COUNT(*) FROM null_test GROUP BY i ORDER BY i;
43+
SELECT s, COUNT(*) FROM null_test GROUP BY s ORDER BY s;
44+
45+
-- Test NULLIF function
46+
SELECT i, NULLIF(i, 1) FROM null_test ORDER BY ts;
47+
SELECT s, NULLIF(s, 'hello') FROM null_test ORDER BY ts;
48+
49+
DROP TABLE null_test;

0 commit comments

Comments
 (0)