Skip to content

Commit 24e5c9f

Browse files
authored
test: migrate duckdb tests, part 1 (#6870)
* test: migrate duckdb tests Signed-off-by: Dennis Zhuang <[email protected]> * fix: style Signed-off-by: Dennis Zhuang <[email protected]> * test: add more duckdb tests Signed-off-by: Dennis Zhuang <[email protected]> * fix: stable order Signed-off-by: Dennis Zhuang <[email protected]> * chore: simplfy comments Signed-off-by: Dennis Zhuang <[email protected]> * chore: remove tests/cases/standalone/common/DUCKDB_MIGRATION_GUIDE.md * fix: incorrect_sql.sql Signed-off-by: Dennis Zhuang <[email protected]> * fix: integer flow test Signed-off-by: Dennis Zhuang <[email protected]> * fix: integer flow test Signed-off-by: Dennis Zhuang <[email protected]> * docs: add todo Signed-off-by: Dennis Zhuang <[email protected]> --------- Signed-off-by: Dennis Zhuang <[email protected]>
1 parent 4158afa commit 24e5c9f

38 files changed

+2005
-0
lines changed
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
-- Migrated from DuckDB test: test/sql/cast/boolean_autocast.test
2+
-- Description: Test boolean casts
3+
-- Note: GreptimeDB doesn't support automatic boolean-integer comparisons
4+
-- Test explicit boolean casts (supported)
5+
SELECT 1::BOOLEAN;
6+
7+
+----------+
8+
| Int64(1) |
9+
+----------+
10+
| true |
11+
+----------+
12+
13+
SELECT 0::BOOLEAN;
14+
15+
+----------+
16+
| Int64(0) |
17+
+----------+
18+
| false |
19+
+----------+
20+
21+
SELECT 'true'::BOOLEAN;
22+
23+
+--------------+
24+
| Utf8("true") |
25+
+--------------+
26+
| true |
27+
+--------------+
28+
29+
SELECT 'false'::BOOLEAN;
30+
31+
+---------------+
32+
| Utf8("false") |
33+
+---------------+
34+
| false |
35+
+---------------+
36+
37+
-- Test boolean operations
38+
SELECT true AND false;
39+
40+
+----------------------------------+
41+
| Boolean(true) AND Boolean(false) |
42+
+----------------------------------+
43+
| false |
44+
+----------------------------------+
45+
46+
SELECT true OR false;
47+
48+
+---------------------------------+
49+
| Boolean(true) OR Boolean(false) |
50+
+---------------------------------+
51+
| true |
52+
+---------------------------------+
53+
54+
SELECT NOT true;
55+
56+
+-------------------+
57+
| NOT Boolean(true) |
58+
+-------------------+
59+
| false |
60+
+-------------------+
61+
62+
SELECT NOT false;
63+
64+
+--------------------+
65+
| NOT Boolean(false) |
66+
+--------------------+
67+
| true |
68+
+--------------------+
69+
70+
-- Test boolean comparisons (same type)
71+
SELECT true = true;
72+
73+
+-------------------------------+
74+
| Boolean(true) = Boolean(true) |
75+
+-------------------------------+
76+
| true |
77+
+-------------------------------+
78+
79+
SELECT true = false;
80+
81+
+--------------------------------+
82+
| Boolean(true) = Boolean(false) |
83+
+--------------------------------+
84+
| false |
85+
+--------------------------------+
86+
87+
SELECT false = false;
88+
89+
+---------------------------------+
90+
| Boolean(false) = Boolean(false) |
91+
+---------------------------------+
92+
| true |
93+
+---------------------------------+
94+
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
-- Migrated from DuckDB test: test/sql/cast/boolean_autocast.test
2+
-- Description: Test boolean casts
3+
-- Note: GreptimeDB doesn't support automatic boolean-integer comparisons
4+
5+
-- Test explicit boolean casts (supported)
6+
SELECT 1::BOOLEAN;
7+
8+
SELECT 0::BOOLEAN;
9+
10+
SELECT 'true'::BOOLEAN;
11+
12+
SELECT 'false'::BOOLEAN;
13+
14+
-- Test boolean operations
15+
SELECT true AND false;
16+
17+
SELECT true OR false;
18+
19+
SELECT NOT true;
20+
21+
SELECT NOT false;
22+
23+
-- Test boolean comparisons (same type)
24+
SELECT true = true;
25+
26+
SELECT true = false;
27+
28+
SELECT false = false;
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
-- Migrated from DuckDB test: test/sql/cast/string_to_integer_decimal_cast.test
2+
-- Description: String to number casts
3+
-- Note: GreptimeDB doesn't support decimal string to integer conversion
4+
-- Valid integer string conversions
5+
SELECT '0'::INT;
6+
7+
+-----------+
8+
| Utf8("0") |
9+
+-----------+
10+
| 0 |
11+
+-----------+
12+
13+
SELECT '1'::INT;
14+
15+
+-----------+
16+
| Utf8("1") |
17+
+-----------+
18+
| 1 |
19+
+-----------+
20+
21+
SELECT '1000000'::INT;
22+
23+
+-----------------+
24+
| Utf8("1000000") |
25+
+-----------------+
26+
| 1000000 |
27+
+-----------------+
28+
29+
SELECT '-1'::INT;
30+
31+
+------------+
32+
| Utf8("-1") |
33+
+------------+
34+
| -1 |
35+
+------------+
36+
37+
SELECT '-1000'::INT;
38+
39+
+---------------+
40+
| Utf8("-1000") |
41+
+---------------+
42+
| -1000 |
43+
+---------------+
44+
45+
-- Test with BIGINT
46+
SELECT '0'::BIGINT;
47+
48+
+-----------+
49+
| Utf8("0") |
50+
+-----------+
51+
| 0 |
52+
+-----------+
53+
54+
SELECT '1000000'::BIGINT;
55+
56+
+-----------------+
57+
| Utf8("1000000") |
58+
+-----------------+
59+
| 1000000 |
60+
+-----------------+
61+
62+
-- Convert decimal strings to DOUBLE first, then to INT if needed
63+
SELECT '0.5'::DOUBLE;
64+
65+
+-------------+
66+
| Utf8("0.5") |
67+
+-------------+
68+
| 0.5 |
69+
+-------------+
70+
71+
SELECT '1.50004'::DOUBLE;
72+
73+
+-----------------+
74+
| Utf8("1.50004") |
75+
+-----------------+
76+
| 1.50004 |
77+
+-----------------+
78+
79+
SELECT '-0.5'::DOUBLE;
80+
81+
+--------------+
82+
| Utf8("-0.5") |
83+
+--------------+
84+
| -0.5 |
85+
+--------------+
86+
87+
-- Test invalid cases (should error)
88+
SELECT '0.5'::INT;
89+
90+
Error: 3001(EngineExecuteQuery), Cast error: Cannot cast string '0.5' to value of Int32 type
91+
92+
SELECT 'abc'::INT;
93+
94+
Error: 3001(EngineExecuteQuery), Cast error: Cannot cast string 'abc' to value of Int32 type
95+
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
-- Migrated from DuckDB test: test/sql/cast/string_to_integer_decimal_cast.test
2+
-- Description: String to number casts
3+
-- Note: GreptimeDB doesn't support decimal string to integer conversion
4+
5+
-- Valid integer string conversions
6+
SELECT '0'::INT;
7+
8+
SELECT '1'::INT;
9+
10+
SELECT '1000000'::INT;
11+
12+
SELECT '-1'::INT;
13+
14+
SELECT '-1000'::INT;
15+
16+
-- Test with BIGINT
17+
SELECT '0'::BIGINT;
18+
19+
SELECT '1000000'::BIGINT;
20+
21+
-- Convert decimal strings to DOUBLE first, then to INT if needed
22+
SELECT '0.5'::DOUBLE;
23+
24+
SELECT '1.50004'::DOUBLE;
25+
26+
SELECT '-0.5'::DOUBLE;
27+
28+
-- Test invalid cases (should error)
29+
SELECT '0.5'::INT;
30+
31+
SELECT 'abc'::INT;
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
-- Migrated from DuckDB test: test/sql/error/incorrect_sql.test
2+
-- Typo in SELECT
3+
SELEC 42;
4+
5+
Error: 1001(Unsupported), SQL statement is not supported, keyword: SELEC
6+
7+
-- Unrecognized column
8+
SELECT x FROM (SELECT 1 as y);
9+
10+
Error: 3000(PlanQuery), Failed to plan SQL: No field named x. Valid fields are y.
11+
12+
-- Unrecognized function
13+
SELECT FUNFUNFUN();
14+
15+
Error: 3000(PlanQuery), Failed to plan SQL: Error during planning: Invalid function 'funfunfun'.
16+
Did you mean 'range_fn'?
17+
18+
-- Wrong aggregate parameters
19+
SELECT SUM(42, 84, 11, 'hello');
20+
21+
Error: 3000(PlanQuery), Failed to plan SQL: Error during planning: Execution error: Function 'sum' user-defined coercion failed with "Execution error: sum function requires 1 argument, got 4" No function matches the given name and argument types 'sum(Int64, Int64, Int64, Utf8)'. You might need to add explicit type casts.
22+
Candidate functions:
23+
sum(UserDefined)
24+
25+
-- No matching function signature
26+
SELECT cos(0, 1, 2, 3);
27+
28+
Error: 3000(PlanQuery), Failed to plan SQL: Error during planning: Failed to coerce arguments to satisfy a call to 'cos' function: coercion from [Int64, Int64, Int64, Int64] to the signature Uniform(1, [Float64, Float32]) failed No function matches the given name and argument types 'cos(Int64, Int64, Int64, Int64)'. You might need to add explicit type casts.
29+
Candidate functions:
30+
cos(Float64/Float32)
31+
32+
-- Multiple WHERE clauses
33+
SELECT 42 WHERE 1=1 WHERE 1=0;
34+
35+
Error: 1001(Unsupported), SQL statement is not supported, keyword: WHERE
36+
37+
-- Multiple statements without semicolon
38+
SELECT 42
39+
SELECT 42;
40+
41+
Error: 1001(Unsupported), SQL statement is not supported, keyword: SELECT
42+
43+
-- Non-existent table
44+
SELECT * FROM integers2;
45+
46+
Error: 4001(TableNotFound), Failed to plan SQL: Table not found: greptime.public.integers2
47+
48+
-- Non-existent schema
49+
SELECT * FROM bla.integers2;
50+
51+
Error: 4001(TableNotFound), Failed to plan SQL: Table not found: greptime.bla.integers2
52+
53+
CREATE TABLE integers(integ INTEGER, ts TIMESTAMP TIME INDEX);
54+
55+
Affected Rows: 0
56+
57+
CREATE TABLE strings(str VARCHAR, ts TIMESTAMP TIME INDEX);
58+
59+
Affected Rows: 0
60+
61+
CREATE TABLE chickens(feather INTEGER, beak INTEGER, ts TIMESTAMP TIME INDEX);
62+
63+
Affected Rows: 0
64+
65+
-- Non-existent column
66+
SELECT feathe FROM chickens;
67+
68+
Error: 3000(PlanQuery), Failed to plan SQL: No field named feathe. Valid fields are chickens.feather, chickens.beak, chickens.ts.
69+
70+
-- Non-existent column with multiple tables
71+
SELECT feathe FROM chickens, integers, strings;
72+
73+
Error: 3000(PlanQuery), Failed to plan SQL: No field named feathe. Valid fields are chickens.feather, chickens.beak, chickens.ts, integers.integ, integers.ts, strings.str, strings.ts.
74+
75+
-- Ambiguous column reference
76+
SELECT ts FROM chickens, integers;
77+
78+
Error: 3000(PlanQuery), Failed to plan SQL: Ambiguous reference to unqualified field ts
79+
80+
-- Clean up
81+
DROP TABLE chickens;
82+
83+
Affected Rows: 0
84+
85+
DROP TABLE strings;
86+
87+
Affected Rows: 0
88+
89+
DROP TABLE integers;
90+
91+
Affected Rows: 0
92+
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
-- Migrated from DuckDB test: test/sql/error/incorrect_sql.test
2+
3+
-- Typo in SELECT
4+
SELEC 42;
5+
6+
-- Unrecognized column
7+
SELECT x FROM (SELECT 1 as y);
8+
9+
-- Unrecognized function
10+
SELECT FUNFUNFUN();
11+
12+
-- Wrong aggregate parameters
13+
SELECT SUM(42, 84, 11, 'hello');
14+
15+
-- No matching function signature
16+
SELECT cos(0, 1, 2, 3);
17+
18+
-- Multiple WHERE clauses
19+
SELECT 42 WHERE 1=1 WHERE 1=0;
20+
21+
-- Multiple statements without semicolon
22+
SELECT 42
23+
SELECT 42;
24+
25+
-- Non-existent table
26+
SELECT * FROM integers2;
27+
28+
-- Non-existent schema
29+
SELECT * FROM bla.integers2;
30+
31+
CREATE TABLE integers(integ INTEGER, ts TIMESTAMP TIME INDEX);
32+
33+
CREATE TABLE strings(str VARCHAR, ts TIMESTAMP TIME INDEX);
34+
35+
CREATE TABLE chickens(feather INTEGER, beak INTEGER, ts TIMESTAMP TIME INDEX);
36+
37+
-- Non-existent column
38+
SELECT feathe FROM chickens;
39+
40+
-- Non-existent column with multiple tables
41+
SELECT feathe FROM chickens, integers, strings;
42+
43+
-- Ambiguous column reference
44+
SELECT ts FROM chickens, integers;
45+
46+
-- Clean up
47+
DROP TABLE chickens;
48+
49+
DROP TABLE strings;
50+
51+
DROP TABLE integers;

0 commit comments

Comments
 (0)