test: migrate duckdb tests, part 1 (#6870)

* test: migrate duckdb tests

Signed-off-by: Dennis Zhuang <killme2008@gmail.com>

* fix: style

Signed-off-by: Dennis Zhuang <killme2008@gmail.com>

* test: add more duckdb tests

Signed-off-by: Dennis Zhuang <killme2008@gmail.com>

* fix: stable order

Signed-off-by: Dennis Zhuang <killme2008@gmail.com>

* chore: simplfy comments

Signed-off-by: Dennis Zhuang <killme2008@gmail.com>

* chore: remove tests/cases/standalone/common/DUCKDB_MIGRATION_GUIDE.md

* fix: incorrect_sql.sql

Signed-off-by: Dennis Zhuang <killme2008@gmail.com>

* fix: integer flow test

Signed-off-by: Dennis Zhuang <killme2008@gmail.com>

* fix: integer flow test

Signed-off-by: Dennis Zhuang <killme2008@gmail.com>

* docs: add todo

Signed-off-by: Dennis Zhuang <killme2008@gmail.com>

---------

Signed-off-by: Dennis Zhuang <killme2008@gmail.com>
This commit is contained in:
dennis zhuang
2025-09-05 14:10:14 +08:00
committed by Weny Xu
parent 3dcd40c4ba
commit b94ce9019d
38 changed files with 2005 additions and 0 deletions

View File

@@ -0,0 +1,94 @@
-- Migrated from DuckDB test: test/sql/cast/boolean_autocast.test
-- Description: Test boolean casts
-- Note: GreptimeDB doesn't support automatic boolean-integer comparisons
-- Test explicit boolean casts (supported)
SELECT 1::BOOLEAN;
+----------+
| Int64(1) |
+----------+
| true |
+----------+
SELECT 0::BOOLEAN;
+----------+
| Int64(0) |
+----------+
| false |
+----------+
SELECT 'true'::BOOLEAN;
+--------------+
| Utf8("true") |
+--------------+
| true |
+--------------+
SELECT 'false'::BOOLEAN;
+---------------+
| Utf8("false") |
+---------------+
| false |
+---------------+
-- Test boolean operations
SELECT true AND false;
+----------------------------------+
| Boolean(true) AND Boolean(false) |
+----------------------------------+
| false |
+----------------------------------+
SELECT true OR false;
+---------------------------------+
| Boolean(true) OR Boolean(false) |
+---------------------------------+
| true |
+---------------------------------+
SELECT NOT true;
+-------------------+
| NOT Boolean(true) |
+-------------------+
| false |
+-------------------+
SELECT NOT false;
+--------------------+
| NOT Boolean(false) |
+--------------------+
| true |
+--------------------+
-- Test boolean comparisons (same type)
SELECT true = true;
+-------------------------------+
| Boolean(true) = Boolean(true) |
+-------------------------------+
| true |
+-------------------------------+
SELECT true = false;
+--------------------------------+
| Boolean(true) = Boolean(false) |
+--------------------------------+
| false |
+--------------------------------+
SELECT false = false;
+---------------------------------+
| Boolean(false) = Boolean(false) |
+---------------------------------+
| true |
+---------------------------------+

View File

@@ -0,0 +1,28 @@
-- Migrated from DuckDB test: test/sql/cast/boolean_autocast.test
-- Description: Test boolean casts
-- Note: GreptimeDB doesn't support automatic boolean-integer comparisons
-- Test explicit boolean casts (supported)
SELECT 1::BOOLEAN;
SELECT 0::BOOLEAN;
SELECT 'true'::BOOLEAN;
SELECT 'false'::BOOLEAN;
-- Test boolean operations
SELECT true AND false;
SELECT true OR false;
SELECT NOT true;
SELECT NOT false;
-- Test boolean comparisons (same type)
SELECT true = true;
SELECT true = false;
SELECT false = false;

View File

@@ -0,0 +1,95 @@
-- Migrated from DuckDB test: test/sql/cast/string_to_integer_decimal_cast.test
-- Description: String to number casts
-- Note: GreptimeDB doesn't support decimal string to integer conversion
-- Valid integer string conversions
SELECT '0'::INT;
+-----------+
| Utf8("0") |
+-----------+
| 0 |
+-----------+
SELECT '1'::INT;
+-----------+
| Utf8("1") |
+-----------+
| 1 |
+-----------+
SELECT '1000000'::INT;
+-----------------+
| Utf8("1000000") |
+-----------------+
| 1000000 |
+-----------------+
SELECT '-1'::INT;
+------------+
| Utf8("-1") |
+------------+
| -1 |
+------------+
SELECT '-1000'::INT;
+---------------+
| Utf8("-1000") |
+---------------+
| -1000 |
+---------------+
-- Test with BIGINT
SELECT '0'::BIGINT;
+-----------+
| Utf8("0") |
+-----------+
| 0 |
+-----------+
SELECT '1000000'::BIGINT;
+-----------------+
| Utf8("1000000") |
+-----------------+
| 1000000 |
+-----------------+
-- Convert decimal strings to DOUBLE first, then to INT if needed
SELECT '0.5'::DOUBLE;
+-------------+
| Utf8("0.5") |
+-------------+
| 0.5 |
+-------------+
SELECT '1.50004'::DOUBLE;
+-----------------+
| Utf8("1.50004") |
+-----------------+
| 1.50004 |
+-----------------+
SELECT '-0.5'::DOUBLE;
+--------------+
| Utf8("-0.5") |
+--------------+
| -0.5 |
+--------------+
-- Test invalid cases (should error)
SELECT '0.5'::INT;
Error: 3001(EngineExecuteQuery), Cast error: Cannot cast string '0.5' to value of Int32 type
SELECT 'abc'::INT;
Error: 3001(EngineExecuteQuery), Cast error: Cannot cast string 'abc' to value of Int32 type

View File

@@ -0,0 +1,31 @@
-- Migrated from DuckDB test: test/sql/cast/string_to_integer_decimal_cast.test
-- Description: String to number casts
-- Note: GreptimeDB doesn't support decimal string to integer conversion
-- Valid integer string conversions
SELECT '0'::INT;
SELECT '1'::INT;
SELECT '1000000'::INT;
SELECT '-1'::INT;
SELECT '-1000'::INT;
-- Test with BIGINT
SELECT '0'::BIGINT;
SELECT '1000000'::BIGINT;
-- Convert decimal strings to DOUBLE first, then to INT if needed
SELECT '0.5'::DOUBLE;
SELECT '1.50004'::DOUBLE;
SELECT '-0.5'::DOUBLE;
-- Test invalid cases (should error)
SELECT '0.5'::INT;
SELECT 'abc'::INT;

View File

@@ -0,0 +1,92 @@
-- Migrated from DuckDB test: test/sql/error/incorrect_sql.test
-- Typo in SELECT
SELEC 42;
Error: 1001(Unsupported), SQL statement is not supported, keyword: SELEC
-- Unrecognized column
SELECT x FROM (SELECT 1 as y);
Error: 3000(PlanQuery), Failed to plan SQL: No field named x. Valid fields are y.
-- Unrecognized function
SELECT FUNFUNFUN();
Error: 3000(PlanQuery), Failed to plan SQL: Error during planning: Invalid function 'funfunfun'.
Did you mean 'range_fn'?
-- Wrong aggregate parameters
SELECT SUM(42, 84, 11, 'hello');
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.
Candidate functions:
sum(UserDefined)
-- No matching function signature
SELECT cos(0, 1, 2, 3);
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.
Candidate functions:
cos(Float64/Float32)
-- Multiple WHERE clauses
SELECT 42 WHERE 1=1 WHERE 1=0;
Error: 1001(Unsupported), SQL statement is not supported, keyword: WHERE
-- Multiple statements without semicolon
SELECT 42
SELECT 42;
Error: 1001(Unsupported), SQL statement is not supported, keyword: SELECT
-- Non-existent table
SELECT * FROM integers2;
Error: 4001(TableNotFound), Failed to plan SQL: Table not found: greptime.public.integers2
-- Non-existent schema
SELECT * FROM bla.integers2;
Error: 4001(TableNotFound), Failed to plan SQL: Table not found: greptime.bla.integers2
CREATE TABLE integers(integ INTEGER, ts TIMESTAMP TIME INDEX);
Affected Rows: 0
CREATE TABLE strings(str VARCHAR, ts TIMESTAMP TIME INDEX);
Affected Rows: 0
CREATE TABLE chickens(feather INTEGER, beak INTEGER, ts TIMESTAMP TIME INDEX);
Affected Rows: 0
-- Non-existent column
SELECT feathe FROM chickens;
Error: 3000(PlanQuery), Failed to plan SQL: No field named feathe. Valid fields are chickens.feather, chickens.beak, chickens.ts.
-- Non-existent column with multiple tables
SELECT feathe FROM chickens, integers, strings;
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.
-- Ambiguous column reference
SELECT ts FROM chickens, integers;
Error: 3000(PlanQuery), Failed to plan SQL: Ambiguous reference to unqualified field ts
-- Clean up
DROP TABLE chickens;
Affected Rows: 0
DROP TABLE strings;
Affected Rows: 0
DROP TABLE integers;
Affected Rows: 0

View File

@@ -0,0 +1,51 @@
-- Migrated from DuckDB test: test/sql/error/incorrect_sql.test
-- Typo in SELECT
SELEC 42;
-- Unrecognized column
SELECT x FROM (SELECT 1 as y);
-- Unrecognized function
SELECT FUNFUNFUN();
-- Wrong aggregate parameters
SELECT SUM(42, 84, 11, 'hello');
-- No matching function signature
SELECT cos(0, 1, 2, 3);
-- Multiple WHERE clauses
SELECT 42 WHERE 1=1 WHERE 1=0;
-- Multiple statements without semicolon
SELECT 42
SELECT 42;
-- Non-existent table
SELECT * FROM integers2;
-- Non-existent schema
SELECT * FROM bla.integers2;
CREATE TABLE integers(integ INTEGER, ts TIMESTAMP TIME INDEX);
CREATE TABLE strings(str VARCHAR, ts TIMESTAMP TIME INDEX);
CREATE TABLE chickens(feather INTEGER, beak INTEGER, ts TIMESTAMP TIME INDEX);
-- Non-existent column
SELECT feathe FROM chickens;
-- Non-existent column with multiple tables
SELECT feathe FROM chickens, integers, strings;
-- Ambiguous column reference
SELECT ts FROM chickens, integers;
-- Clean up
DROP TABLE chickens;
DROP TABLE strings;
DROP TABLE integers;

View File

@@ -0,0 +1,125 @@
-- Migrated from DuckDB test: test/sql/filter/test_constant_comparisons.test
-- Description: Test expressions with constant comparisons
CREATE TABLE integers(a INTEGER, b INTEGER, ts TIMESTAMP TIME INDEX);
Affected Rows: 0
INSERT INTO integers VALUES (2, 12, 1000);
Affected Rows: 1
-- Test various constant comparisons
SELECT * FROM integers WHERE 2=2;
+---+----+---------------------+
| a | b | ts |
+---+----+---------------------+
| 2 | 12 | 1970-01-01T00:00:01 |
+---+----+---------------------+
SELECT * FROM integers WHERE 2=3;
++
++
SELECT * FROM integers WHERE 2<>3;
+---+----+---------------------+
| a | b | ts |
+---+----+---------------------+
| 2 | 12 | 1970-01-01T00:00:01 |
+---+----+---------------------+
SELECT * FROM integers WHERE 2<>2;
++
++
SELECT * FROM integers WHERE 2>1;
+---+----+---------------------+
| a | b | ts |
+---+----+---------------------+
| 2 | 12 | 1970-01-01T00:00:01 |
+---+----+---------------------+
SELECT * FROM integers WHERE 2>2;
++
++
SELECT * FROM integers WHERE 2>=2;
+---+----+---------------------+
| a | b | ts |
+---+----+---------------------+
| 2 | 12 | 1970-01-01T00:00:01 |
+---+----+---------------------+
SELECT * FROM integers WHERE 2>=3;
++
++
SELECT * FROM integers WHERE 2<3;
+---+----+---------------------+
| a | b | ts |
+---+----+---------------------+
| 2 | 12 | 1970-01-01T00:00:01 |
+---+----+---------------------+
SELECT * FROM integers WHERE 2<2;
++
++
SELECT * FROM integers WHERE 2<=2;
+---+----+---------------------+
| a | b | ts |
+---+----+---------------------+
| 2 | 12 | 1970-01-01T00:00:01 |
+---+----+---------------------+
SELECT * FROM integers WHERE 2<=1;
++
++
-- NULL comparisons
SELECT a=NULL FROM integers;
+-------------------+
| integers.a = NULL |
+-------------------+
| |
+-------------------+
SELECT NULL=a FROM integers;
+-------------------+
| NULL = integers.a |
+-------------------+
| |
+-------------------+
-- IN clause with constants
SELECT * FROM integers WHERE 2 IN (2, 3, 4, 5);
+---+----+---------------------+
| a | b | ts |
+---+----+---------------------+
| 2 | 12 | 1970-01-01T00:00:01 |
+---+----+---------------------+
SELECT * FROM integers WHERE 2 IN (1, 3, 4, 5);
++
++
-- Clean up
DROP TABLE integers;
Affected Rows: 0

View File

@@ -0,0 +1,44 @@
-- Migrated from DuckDB test: test/sql/filter/test_constant_comparisons.test
-- Description: Test expressions with constant comparisons
CREATE TABLE integers(a INTEGER, b INTEGER, ts TIMESTAMP TIME INDEX);
INSERT INTO integers VALUES (2, 12, 1000);
-- Test various constant comparisons
SELECT * FROM integers WHERE 2=2;
SELECT * FROM integers WHERE 2=3;
SELECT * FROM integers WHERE 2<>3;
SELECT * FROM integers WHERE 2<>2;
SELECT * FROM integers WHERE 2>1;
SELECT * FROM integers WHERE 2>2;
SELECT * FROM integers WHERE 2>=2;
SELECT * FROM integers WHERE 2>=3;
SELECT * FROM integers WHERE 2<3;
SELECT * FROM integers WHERE 2<2;
SELECT * FROM integers WHERE 2<=2;
SELECT * FROM integers WHERE 2<=1;
-- NULL comparisons
SELECT a=NULL FROM integers;
SELECT NULL=a FROM integers;
-- IN clause with constants
SELECT * FROM integers WHERE 2 IN (2, 3, 4, 5);
SELECT * FROM integers WHERE 2 IN (1, 3, 4, 5);
-- Clean up
DROP TABLE integers;

View File

@@ -0,0 +1,74 @@
-- Migrated from DuckDB test: test/sql/join/test_complex_join_expr.test
CREATE TABLE test (a INTEGER, b INTEGER, ts TIMESTAMP TIME INDEX);
Affected Rows: 0
INSERT INTO test VALUES (4, 1, 1000), (2, 2, 2000);
Affected Rows: 2
CREATE TABLE test2 (b INTEGER, c INTEGER, ts TIMESTAMP TIME INDEX);
Affected Rows: 0
INSERT INTO test2 VALUES (1, 2, 3000), (3, 0, 4000);
Affected Rows: 2
-- INNER JOIN with complex expression
SELECT * FROM test JOIN test2 ON test.a+test2.c=test.b+test2.b ORDER BY test.a;
+---+---+---------------------+---+---+---------------------+
| a | b | ts | b | c | ts |
+---+---+---------------------+---+---+---------------------+
| 4 | 1 | 1970-01-01T00:00:01 | 3 | 0 | 1970-01-01T00:00:04 |
+---+---+---------------------+---+---+---------------------+
-- LEFT JOIN with complex expression
SELECT * FROM test LEFT JOIN test2 ON test.a+test2.c=test.b+test2.b ORDER BY test.a;
+---+---+---------------------+---+---+---------------------+
| a | b | ts | b | c | ts |
+---+---+---------------------+---+---+---------------------+
| 2 | 2 | 1970-01-01T00:00:02 | | | |
| 4 | 1 | 1970-01-01T00:00:01 | 3 | 0 | 1970-01-01T00:00:04 |
+---+---+---------------------+---+---+---------------------+
-- RIGHT JOIN with complex expression
SELECT * FROM test RIGHT JOIN test2 ON test.a+test2.c=test.b+test2.b ORDER BY test.a NULLS FIRST;
+---+---+---------------------+---+---+---------------------+
| a | b | ts | b | c | ts |
+---+---+---------------------+---+---+---------------------+
| | | | 1 | 2 | 1970-01-01T00:00:03 |
| 4 | 1 | 1970-01-01T00:00:01 | 3 | 0 | 1970-01-01T00:00:04 |
+---+---+---------------------+---+---+---------------------+
-- FULL JOIN with complex expression
SELECT * FROM test FULL OUTER JOIN test2 ON test.a+test2.c=test.b+test2.b ORDER BY test.a NULLS FIRST;
+---+---+---------------------+---+---+---------------------+
| a | b | ts | b | c | ts |
+---+---+---------------------+---+---+---------------------+
| | | | 1 | 2 | 1970-01-01T00:00:03 |
| 2 | 2 | 1970-01-01T00:00:02 | | | |
| 4 | 1 | 1970-01-01T00:00:01 | 3 | 0 | 1970-01-01T00:00:04 |
+---+---+---------------------+---+---+---------------------+
-- Basic equi-join
SELECT * FROM test JOIN test2 ON test.b = test2.b ORDER BY test.a;
+---+---+---------------------+---+---+---------------------+
| a | b | ts | b | c | ts |
+---+---+---------------------+---+---+---------------------+
| 4 | 1 | 1970-01-01T00:00:01 | 1 | 2 | 1970-01-01T00:00:03 |
+---+---+---------------------+---+---+---------------------+
DROP TABLE test2;
Affected Rows: 0
DROP TABLE test;
Affected Rows: 0

View File

@@ -0,0 +1,27 @@
-- Migrated from DuckDB test: test/sql/join/test_complex_join_expr.test
CREATE TABLE test (a INTEGER, b INTEGER, ts TIMESTAMP TIME INDEX);
INSERT INTO test VALUES (4, 1, 1000), (2, 2, 2000);
CREATE TABLE test2 (b INTEGER, c INTEGER, ts TIMESTAMP TIME INDEX);
INSERT INTO test2 VALUES (1, 2, 3000), (3, 0, 4000);
-- INNER JOIN with complex expression
SELECT * FROM test JOIN test2 ON test.a+test2.c=test.b+test2.b ORDER BY test.a;
-- LEFT JOIN with complex expression
SELECT * FROM test LEFT JOIN test2 ON test.a+test2.c=test.b+test2.b ORDER BY test.a;
-- RIGHT JOIN with complex expression
SELECT * FROM test RIGHT JOIN test2 ON test.a+test2.c=test.b+test2.b ORDER BY test.a NULLS FIRST;
-- FULL JOIN with complex expression
SELECT * FROM test FULL OUTER JOIN test2 ON test.a+test2.c=test.b+test2.b ORDER BY test.a NULLS FIRST;
-- Basic equi-join
SELECT * FROM test JOIN test2 ON test.b = test2.b ORDER BY test.a;
DROP TABLE test2;
DROP TABLE test;

View File

@@ -0,0 +1,41 @@
-- Migrated from DuckDB test: test/sql/keywords/escaped_quotes_expressions.test
-- Note: Schema names don't support escaped quotes in GreptimeDB
CREATE TABLE test_table("COL""UMN" VARCHAR, "NA""ME" VARCHAR, ts TIMESTAMP TIME INDEX);
Affected Rows: 0
INSERT INTO test_table VALUES ('ALL', 'test', 1000);
Affected Rows: 1
-- Column references with escaped quotes
SELECT "COL""UMN" FROM test_table;
+---------+
| COL"UMN |
+---------+
| ALL |
+---------+
-- Multiple escaped quote columns
SELECT "COL""UMN", "NA""ME" FROM test_table;
+---------+-------+
| COL"UMN | NA"ME |
+---------+-------+
| ALL | test |
+---------+-------+
-- Table-qualified references
SELECT test_table."COL""UMN", test_table."NA""ME" FROM test_table;
+---------+-------+
| COL"UMN | NA"ME |
+---------+-------+
| ALL | test |
+---------+-------+
DROP TABLE test_table;
Affected Rows: 0

View File

@@ -0,0 +1,17 @@
-- Migrated from DuckDB test: test/sql/keywords/escaped_quotes_expressions.test
-- Note: Schema names don't support escaped quotes in GreptimeDB
CREATE TABLE test_table("COL""UMN" VARCHAR, "NA""ME" VARCHAR, ts TIMESTAMP TIME INDEX);
INSERT INTO test_table VALUES ('ALL', 'test', 1000);
-- Column references with escaped quotes
SELECT "COL""UMN" FROM test_table;
-- Multiple escaped quote columns
SELECT "COL""UMN", "NA""ME" FROM test_table;
-- Table-qualified references
SELECT test_table."COL""UMN", test_table."NA""ME" FROM test_table;
DROP TABLE test_table;

View File

@@ -0,0 +1,78 @@
-- Migrated from DuckDB test: test/sql/keywords/keywords_in_expressions.test
CREATE SCHEMA "SCHEMA";
Affected Rows: 1
CREATE TABLE "SCHEMA"."TABLE"("COLUMN" VARCHAR, ts TIMESTAMP TIME INDEX);
Affected Rows: 0
INSERT INTO "SCHEMA"."TABLE" VALUES ('ALL', 1000);
Affected Rows: 1
-- Column references with quoted keywords
SELECT "COLUMN" FROM "SCHEMA"."TABLE";
+--------+
| COLUMN |
+--------+
| ALL |
+--------+
-- Table-qualified column reference
SELECT "TABLE"."COLUMN" FROM "SCHEMA"."TABLE";
+--------+
| COLUMN |
+--------+
| ALL |
+--------+
-- Schema-qualified column reference
SELECT "SCHEMA"."TABLE"."COLUMN" FROM "SCHEMA"."TABLE";
+--------+
| COLUMN |
+--------+
| ALL |
+--------+
DROP TABLE "SCHEMA"."TABLE";
Affected Rows: 0
DROP SCHEMA "SCHEMA";
Affected Rows: 0
-- Common reserved keywords
CREATE TABLE "SELECT"("WHERE" INTEGER, "FROM" VARCHAR, ts TIMESTAMP TIME INDEX);
Affected Rows: 0
INSERT INTO "SELECT" VALUES (1, 'test', 2000);
Affected Rows: 1
SELECT "WHERE", "FROM" FROM "SELECT";
+-------+------+
| WHERE | FROM |
+-------+------+
| 1 | test |
+-------+------+
-- Qualified references
SELECT "SELECT"."WHERE", "SELECT"."FROM" FROM "SELECT";
+-------+------+
| WHERE | FROM |
+-------+------+
| 1 | test |
+-------+------+
DROP TABLE "SELECT";
Affected Rows: 0

View File

@@ -0,0 +1,31 @@
-- Migrated from DuckDB test: test/sql/keywords/keywords_in_expressions.test
CREATE SCHEMA "SCHEMA";
CREATE TABLE "SCHEMA"."TABLE"("COLUMN" VARCHAR, ts TIMESTAMP TIME INDEX);
INSERT INTO "SCHEMA"."TABLE" VALUES ('ALL', 1000);
-- Column references with quoted keywords
SELECT "COLUMN" FROM "SCHEMA"."TABLE";
-- Table-qualified column reference
SELECT "TABLE"."COLUMN" FROM "SCHEMA"."TABLE";
-- Schema-qualified column reference
SELECT "SCHEMA"."TABLE"."COLUMN" FROM "SCHEMA"."TABLE";
DROP TABLE "SCHEMA"."TABLE";
DROP SCHEMA "SCHEMA";
-- Common reserved keywords
CREATE TABLE "SELECT"("WHERE" INTEGER, "FROM" VARCHAR, ts TIMESTAMP TIME INDEX);
INSERT INTO "SELECT" VALUES (1, 'test', 2000);
SELECT "WHERE", "FROM" FROM "SELECT";
-- Qualified references
SELECT "SELECT"."WHERE", "SELECT"."FROM" FROM "SELECT";
DROP TABLE "SELECT";

View File

@@ -0,0 +1,71 @@
-- Migrated from DuckDB test: test/sql/limit/test_preserve_insertion_order.test
CREATE TABLE integers(i INTEGER, ts TIMESTAMP TIME INDEX);
Affected Rows: 0
INSERT INTO integers VALUES
(1, 1000), (1, 2000), (1, 3000), (1, 4000), (1, 5000),
(2, 6000), (3, 7000), (4, 8000), (5, 9000), (10, 10000);
Affected Rows: 10
SELECT MIN(i), MAX(i), COUNT(*) FROM integers;
+-----------------+-----------------+----------+
| min(integers.i) | max(integers.i) | count(*) |
+-----------------+-----------------+----------+
| 1 | 10 | 10 |
+-----------------+-----------------+----------+
SELECT * FROM integers ORDER BY ts LIMIT 5;
+---+---------------------+
| i | ts |
+---+---------------------+
| 1 | 1970-01-01T00:00:01 |
| 1 | 1970-01-01T00:00:02 |
| 1 | 1970-01-01T00:00:03 |
| 1 | 1970-01-01T00:00:04 |
| 1 | 1970-01-01T00:00:05 |
+---+---------------------+
SELECT * FROM integers ORDER BY ts LIMIT 3 OFFSET 2;
+---+---------------------+
| i | ts |
+---+---------------------+
| 1 | 1970-01-01T00:00:03 |
| 1 | 1970-01-01T00:00:04 |
| 1 | 1970-01-01T00:00:05 |
+---+---------------------+
SELECT * FROM integers WHERE i IN (1, 3, 5, 10) ORDER BY i;
+----+---------------------+
| i | ts |
+----+---------------------+
| 1 | 1970-01-01T00:00:01 |
| 1 | 1970-01-01T00:00:02 |
| 1 | 1970-01-01T00:00:03 |
| 1 | 1970-01-01T00:00:04 |
| 1 | 1970-01-01T00:00:05 |
| 3 | 1970-01-01T00:00:07 |
| 5 | 1970-01-01T00:00:09 |
| 10 | 1970-01-01T00:00:10 |
+----+---------------------+
SELECT * FROM integers WHERE i IN (1, 3, 5, 10) ORDER BY i, ts LIMIT 3;
+---+---------------------+
| i | ts |
+---+---------------------+
| 1 | 1970-01-01T00:00:01 |
| 1 | 1970-01-01T00:00:02 |
| 1 | 1970-01-01T00:00:03 |
+---+---------------------+
-- Clean up
DROP TABLE integers;
Affected Rows: 0

View File

@@ -0,0 +1,20 @@
-- Migrated from DuckDB test: test/sql/limit/test_preserve_insertion_order.test
CREATE TABLE integers(i INTEGER, ts TIMESTAMP TIME INDEX);
INSERT INTO integers VALUES
(1, 1000), (1, 2000), (1, 3000), (1, 4000), (1, 5000),
(2, 6000), (3, 7000), (4, 8000), (5, 9000), (10, 10000);
SELECT MIN(i), MAX(i), COUNT(*) FROM integers;
SELECT * FROM integers ORDER BY ts LIMIT 5;
SELECT * FROM integers ORDER BY ts LIMIT 3 OFFSET 2;
SELECT * FROM integers WHERE i IN (1, 3, 5, 10) ORDER BY i;
SELECT * FROM integers WHERE i IN (1, 3, 5, 10) ORDER BY i, ts LIMIT 3;
-- Clean up
DROP TABLE integers;

View File

@@ -0,0 +1,33 @@
-- Migrated from DuckDB test: test/sql/limit/test_limit0.test
-- Description: Test limit 0
CREATE TABLE test_data(i INTEGER, ts TIMESTAMP TIME INDEX);
Affected Rows: 0
INSERT INTO test_data VALUES (1, 1000), (2, 2000), (3, 3000);
Affected Rows: 3
-- Test LIMIT 0 returns empty result
SELECT * FROM test_data LIMIT 0;
++
++
-- Test LIMIT 0 with aggregation
SELECT SUM(i) FROM test_data LIMIT 0;
++
++
-- Test LIMIT 0 with WHERE clause
SELECT * FROM test_data WHERE i > 0 LIMIT 0;
++
++
-- Clean up
DROP TABLE test_data;
Affected Rows: 0

View File

@@ -0,0 +1,18 @@
-- Migrated from DuckDB test: test/sql/limit/test_limit0.test
-- Description: Test limit 0
CREATE TABLE test_data(i INTEGER, ts TIMESTAMP TIME INDEX);
INSERT INTO test_data VALUES (1, 1000), (2, 2000), (3, 3000);
-- Test LIMIT 0 returns empty result
SELECT * FROM test_data LIMIT 0;
-- Test LIMIT 0 with aggregation
SELECT SUM(i) FROM test_data LIMIT 0;
-- Test LIMIT 0 with WHERE clause
SELECT * FROM test_data WHERE i > 0 LIMIT 0;
-- Clean up
DROP TABLE test_data;

View File

@@ -0,0 +1,108 @@
-- Migrated from DuckDB test: test/sql/overflow/integer_overflow.test
-- Note: GreptimeDB wraps on overflow, DuckDB throws error
-- TINYINT addition tests
SELECT 100::TINYINT + 1::TINYINT;
+-----------------------+
| Int64(100) + Int64(1) |
+-----------------------+
| 101 |
+-----------------------+
-- overflow: wraps to -106
SELECT 100::TINYINT + 50::TINYINT;
+------------------------+
| Int64(100) + Int64(50) |
+------------------------+
| -106 |
+------------------------+
SELECT 0::TINYINT + (-127)::TINYINT;
+------------------------+
| Int64(0) + Int64(-127) |
+------------------------+
| -127 |
+------------------------+
-- underflow: wraps to 127
SELECT (-2)::TINYINT + (-127)::TINYINT;
+-------------------------+
| Int64(-2) + Int64(-127) |
+-------------------------+
| 127 |
+-------------------------+
-- SMALLINT addition tests
SELECT 30000::SMALLINT + 1::SMALLINT;
+-------------------------+
| Int64(30000) + Int64(1) |
+-------------------------+
| 30001 |
+-------------------------+
-- overflow: wraps to -30536
SELECT 30000::SMALLINT + 5000::SMALLINT;
+----------------------------+
| Int64(30000) + Int64(5000) |
+----------------------------+
| -30536 |
+----------------------------+
SELECT 0::SMALLINT + (-32767)::SMALLINT;
+--------------------------+
| Int64(0) + Int64(-32767) |
+--------------------------+
| -32767 |
+--------------------------+
-- underflow: wraps to 32767
SELECT (-2)::SMALLINT + (-32767)::SMALLINT;
+---------------------------+
| Int64(-2) + Int64(-32767) |
+---------------------------+
| 32767 |
+---------------------------+
-- INTEGER addition tests
SELECT 2147483640::INTEGER + 1::INTEGER;
+------------------------------+
| Int64(2147483640) + Int64(1) |
+------------------------------+
| 2147483641 |
+------------------------------+
-- overflow: wraps
SELECT 2147483640::INTEGER + 5000::INTEGER;
+---------------------------------+
| Int64(2147483640) + Int64(5000) |
+---------------------------------+
| -2147478656 |
+---------------------------------+
-- BIGINT addition tests
SELECT 9223372036854775800::BIGINT + 1::BIGINT;
+---------------------------------------+
| Int64(9223372036854775800) + Int64(1) |
+---------------------------------------+
| 9223372036854775801 |
+---------------------------------------+
-- overflow: wraps
SELECT 9223372036854775800::BIGINT + 1000::BIGINT;
+------------------------------------------+
| Int64(9223372036854775800) + Int64(1000) |
+------------------------------------------+
| -9223372036854774816 |
+------------------------------------------+

View File

@@ -0,0 +1,36 @@
-- Migrated from DuckDB test: test/sql/overflow/integer_overflow.test
-- Note: GreptimeDB wraps on overflow, DuckDB throws error
-- TINYINT addition tests
SELECT 100::TINYINT + 1::TINYINT;
-- overflow: wraps to -106
SELECT 100::TINYINT + 50::TINYINT;
SELECT 0::TINYINT + (-127)::TINYINT;
-- underflow: wraps to 127
SELECT (-2)::TINYINT + (-127)::TINYINT;
-- SMALLINT addition tests
SELECT 30000::SMALLINT + 1::SMALLINT;
-- overflow: wraps to -30536
SELECT 30000::SMALLINT + 5000::SMALLINT;
SELECT 0::SMALLINT + (-32767)::SMALLINT;
-- underflow: wraps to 32767
SELECT (-2)::SMALLINT + (-32767)::SMALLINT;
-- INTEGER addition tests
SELECT 2147483640::INTEGER + 1::INTEGER;
-- overflow: wraps
SELECT 2147483640::INTEGER + 5000::INTEGER;
-- BIGINT addition tests
SELECT 9223372036854775800::BIGINT + 1::BIGINT;
-- overflow: wraps
SELECT 9223372036854775800::BIGINT + 1000::BIGINT;

View File

@@ -1,3 +1,4 @@
-- Existing operator precedence tests
SELECT 2*3+1;
+--------------------------------+
@@ -86,3 +87,40 @@ SELECT 2*3^2;
| 4 |
+--------------------------------------+
-- Migrated from DuckDB test: test/sql/parser/division_operator_precedence.test
-- Additional division operator precedence tests (only standard division)
-- Division operator precedence
SELECT 6 * 1 / 2;
+--------------------------------+
| Int64(6) * Int64(1) / Int64(2) |
+--------------------------------+
| 3 |
+--------------------------------+
-- Addition and division precedence
SELECT 6 + 1 / 2;
+--------------------------------+
| Int64(6) + Int64(1) / Int64(2) |
+--------------------------------+
| 6 |
+--------------------------------+
-- More division precedence tests
SELECT 10 / 2 * 3;
+---------------------------------+
| Int64(10) / Int64(2) * Int64(3) |
+---------------------------------+
| 15 |
+---------------------------------+
SELECT 10 / (2 * 3);
+---------------------------------+
| Int64(10) / Int64(2) * Int64(3) |
+---------------------------------+
| 1 |
+---------------------------------+

View File

@@ -1,3 +1,4 @@
-- Existing operator precedence tests
SELECT 2*3+1;
SELECT 1+2*3;
@@ -19,3 +20,17 @@ SELECT 2*3*2;
SELECT 2^3*2;
SELECT 2*3^2;
-- Migrated from DuckDB test: test/sql/parser/division_operator_precedence.test
-- Additional division operator precedence tests (only standard division)
-- Division operator precedence
SELECT 6 * 1 / 2;
-- Addition and division precedence
SELECT 6 + 1 / 2;
-- More division precedence tests
SELECT 10 / 2 * 3;
SELECT 10 / (2 * 3);

View File

@@ -0,0 +1,71 @@
-- Migrated from DuckDB test: test/sql/select/test_multi_column_reference.test
-- Description: Test multi column reference
-- Note: Adapted for GreptimeDB - focusing on schema.table.column references
-- Test schema -> table -> column reference
CREATE SCHEMA test;
Affected Rows: 1
CREATE TABLE test.tbl(col INTEGER, ts TIMESTAMP TIME INDEX);
Affected Rows: 0
INSERT INTO test.tbl VALUES (1, 1000), (2, 2000), (3, 3000);
Affected Rows: 3
-- Full qualified reference: schema.table.column
SELECT test.tbl.col FROM test.tbl ORDER BY col;
+-----+
| col |
+-----+
| 1 |
| 2 |
| 3 |
+-----+
-- Table qualified reference
SELECT tbl.col FROM test.tbl ORDER BY col;
+-----+
| col |
+-----+
| 1 |
| 2 |
| 3 |
+-----+
-- Simple column reference
SELECT col FROM test.tbl ORDER BY col;
+-----+
| col |
+-----+
| 1 |
| 2 |
| 3 |
+-----+
-- Test with table alias
SELECT t.col FROM test.tbl t ORDER BY col;
+-----+
| col |
+-----+
| 1 |
| 2 |
| 3 |
+-----+
-- Note: DuckDB's struct field access (t.t.t pattern) is not applicable to GreptimeDB
-- as GreptimeDB doesn't support ROW/STRUCT types in the same way
-- Clean up
DROP TABLE test.tbl;
Affected Rows: 0
DROP SCHEMA test;
Affected Rows: 0

View File

@@ -0,0 +1,30 @@
-- Migrated from DuckDB test: test/sql/select/test_multi_column_reference.test
-- Description: Test multi column reference
-- Note: Adapted for GreptimeDB - focusing on schema.table.column references
-- Test schema -> table -> column reference
CREATE SCHEMA test;
CREATE TABLE test.tbl(col INTEGER, ts TIMESTAMP TIME INDEX);
INSERT INTO test.tbl VALUES (1, 1000), (2, 2000), (3, 3000);
-- Full qualified reference: schema.table.column
SELECT test.tbl.col FROM test.tbl ORDER BY col;
-- Table qualified reference
SELECT tbl.col FROM test.tbl ORDER BY col;
-- Simple column reference
SELECT col FROM test.tbl ORDER BY col;
-- Test with table alias
SELECT t.col FROM test.tbl t ORDER BY col;
-- Note: DuckDB's struct field access (t.t.t pattern) is not applicable to GreptimeDB
-- as GreptimeDB doesn't support ROW/STRUCT types in the same way
-- Clean up
DROP TABLE test.tbl;
DROP SCHEMA test;

View File

@@ -0,0 +1,66 @@
-- Migrated from DuckDB test: test/sql/select/test_projection_names.test
-- Description: Test projection lists
-- Note: Adapted for GreptimeDB - testing column selection and naming
CREATE TABLE integers(COL1 INTEGER, COL2 INTEGER, ts TIMESTAMP TIME INDEX);
Affected Rows: 0
INSERT INTO integers VALUES (1, 10, 1000), (2, 20, 2000);
Affected Rows: 2
-- Test 1: SELECT * projection
SELECT * FROM integers ORDER BY ts;
+------+------+---------------------+
| col1 | col2 | ts |
+------+------+---------------------+
| 1 | 10 | 1970-01-01T00:00:01 |
| 2 | 20 | 1970-01-01T00:00:02 |
+------+------+---------------------+
-- Test 2: Explicit column projection
SELECT COL1, COL2 FROM integers ORDER BY COL1;
+------+------+
| col1 | col2 |
+------+------+
| 1 | 10 |
| 2 | 20 |
+------+------+
-- Test 3: Table-qualified column reference
SELECT integers.COL1, integers.COL2 FROM integers ORDER BY COL1;
+------+------+
| col1 | col2 |
+------+------+
| 1 | 10 |
| 2 | 20 |
+------+------+
-- Test 4: Column alias
SELECT COL1 as c1, COL2 as c2 FROM integers ORDER BY c1;
+----+----+
| c1 | c2 |
+----+----+
| 1 | 10 |
| 2 | 20 |
+----+----+
-- Test 5: Mixed qualified and unqualified references
SELECT integers.COL1, COL2 FROM integers ORDER BY COL1;
+------+------+
| col1 | col2 |
+------+------+
| 1 | 10 |
| 2 | 20 |
+------+------+
-- Clean up
DROP TABLE integers;
Affected Rows: 0

View File

@@ -0,0 +1,25 @@
-- Migrated from DuckDB test: test/sql/select/test_projection_names.test
-- Description: Test projection lists
-- Note: Adapted for GreptimeDB - testing column selection and naming
CREATE TABLE integers(COL1 INTEGER, COL2 INTEGER, ts TIMESTAMP TIME INDEX);
INSERT INTO integers VALUES (1, 10, 1000), (2, 20, 2000);
-- Test 1: SELECT * projection
SELECT * FROM integers ORDER BY ts;
-- Test 2: Explicit column projection
SELECT COL1, COL2 FROM integers ORDER BY COL1;
-- Test 3: Table-qualified column reference
SELECT integers.COL1, integers.COL2 FROM integers ORDER BY COL1;
-- Test 4: Column alias
SELECT COL1 as c1, COL2 as c2 FROM integers ORDER BY c1;
-- Test 5: Mixed qualified and unqualified references
SELECT integers.COL1, COL2 FROM integers ORDER BY COL1;
-- Clean up
DROP TABLE integers;

View File

@@ -0,0 +1,51 @@
-- Migrated from DuckDB test: test/sql/select/test_select_qualified_view.test
-- Description: Test selecting a view through a qualified reference
CREATE SCHEMA s;
Affected Rows: 1
-- Create table with TIME INDEX for GreptimeDB
CREATE TABLE s.a(col1 STRING, ts TIMESTAMP TIME INDEX);
Affected Rows: 0
INSERT INTO s.a VALUES ('hello', 1000);
Affected Rows: 1
-- Create view
CREATE VIEW s.b AS SELECT * FROM s.a;
Affected Rows: 0
-- Test schema-qualified view reference
SELECT s.b.col1 FROM s.b;
+-------+
| col1 |
+-------+
| hello |
+-------+
-- Test table-qualified view reference
SELECT b.col1 FROM s.b;
+-------+
| col1 |
+-------+
| hello |
+-------+
-- Clean up
DROP VIEW s.b;
Affected Rows: 0
DROP TABLE s.a;
Affected Rows: 0
DROP SCHEMA s;
Affected Rows: 0

View File

@@ -0,0 +1,25 @@
-- Migrated from DuckDB test: test/sql/select/test_select_qualified_view.test
-- Description: Test selecting a view through a qualified reference
CREATE SCHEMA s;
-- Create table with TIME INDEX for GreptimeDB
CREATE TABLE s.a(col1 STRING, ts TIMESTAMP TIME INDEX);
INSERT INTO s.a VALUES ('hello', 1000);
-- Create view
CREATE VIEW s.b AS SELECT * FROM s.a;
-- Test schema-qualified view reference
SELECT s.b.col1 FROM s.b;
-- Test table-qualified view reference
SELECT b.col1 FROM s.b;
-- Clean up
DROP VIEW s.b;
DROP TABLE s.a;
DROP SCHEMA s;

View File

@@ -0,0 +1,38 @@
-- Migrated from DuckDB test: test/sql/select/test_schema_reference.test
-- Description: Test schema reference in column reference
CREATE SCHEMA s1;
Affected Rows: 1
CREATE TABLE s1.tbl(i INTEGER, ts TIMESTAMP TIME INDEX);
Affected Rows: 0
INSERT INTO s1.tbl VALUES (1, 1000), (2, 2000);
Affected Rows: 2
-- Standard schema reference: schema.table.column
SELECT s1.tbl.i FROM s1.tbl ORDER BY i;
+---+
| i |
+---+
| 1 |
| 2 |
+---+
-- Test schema mismatch error - should fail
SELECT s2.tbl.i FROM s1.tbl;
Error: 3000(PlanQuery), Failed to plan SQL: No field named s2.tbl.i. Valid fields are s1.tbl.i, s1.tbl.ts.
-- Clean up
DROP TABLE s1.tbl;
Affected Rows: 0
DROP SCHEMA s1;
Affected Rows: 0

View File

@@ -0,0 +1,19 @@
-- Migrated from DuckDB test: test/sql/select/test_schema_reference.test
-- Description: Test schema reference in column reference
CREATE SCHEMA s1;
CREATE TABLE s1.tbl(i INTEGER, ts TIMESTAMP TIME INDEX);
INSERT INTO s1.tbl VALUES (1, 1000), (2, 2000);
-- Standard schema reference: schema.table.column
SELECT s1.tbl.i FROM s1.tbl ORDER BY i;
-- Test schema mismatch error - should fail
SELECT s2.tbl.i FROM s1.tbl;
-- Clean up
DROP TABLE s1.tbl;
DROP SCHEMA s1;

View File

@@ -0,0 +1,141 @@
-- Migrated from DuckDB test: test/sql/setops/test_setops.test
SELECT 1 UNION ALL SELECT 2;
+----------+
| Int64(1) |
+----------+
| 1 |
| 2 |
+----------+
SELECT 1, 'a' UNION ALL SELECT 2, 'b';
+----------+-----------+
| Int64(1) | Utf8("a") |
+----------+-----------+
| 1 | a |
| 2 | b |
+----------+-----------+
SELECT 1, 'a' UNION ALL SELECT 2, 'b' UNION ALL SELECT 3, 'c' ORDER BY 1;
+----------+-----------+
| Int64(1) | Utf8("a") |
+----------+-----------+
| 1 | a |
| 2 | b |
| 3 | c |
+----------+-----------+
SELECT 1, 'a' UNION ALL SELECT 2, 'b' UNION ALL SELECT 3, 'c' UNION ALL SELECT 4, 'd' ORDER BY 1;
+----------+-----------+
| Int64(1) | Utf8("a") |
+----------+-----------+
| 1 | a |
| 2 | b |
| 3 | c |
| 4 | d |
+----------+-----------+
-- NULL values
SELECT NULL UNION SELECT NULL;
+------+
| NULL |
+------+
| |
+------+
SELECT NULL EXCEPT SELECT NULL;
++
++
SELECT NULL INTERSECT SELECT NULL;
+------+
| NULL |
+------+
| |
+------+
CREATE TABLE test (a INTEGER, b INTEGER, ts TIMESTAMP TIME INDEX);
Affected Rows: 0
INSERT INTO test VALUES (11, 1, 1000), (12, 1, 2000), (13, 2, 3000);
Affected Rows: 3
-- Table data
SELECT a FROM test WHERE a < 13 UNION ALL SELECT a FROM test WHERE a = 13 ORDER BY a;
+----+
| a |
+----+
| 11 |
| 12 |
| 13 |
+----+
SELECT b FROM test WHERE a < 13 UNION ALL SELECT b FROM test WHERE a > 11 ORDER BY b;
+---+
| b |
+---+
| 1 |
| 1 |
| 1 |
| 2 |
+---+
-- Type mixing
SELECT 1 UNION ALL SELECT 'asdf';
+----------+
| Int64(1) |
+----------+
| 1 |
| asdf |
+----------+
-- UNION deduplication
SELECT 1 UNION SELECT 1;
+----------+
| Int64(1) |
+----------+
| 1 |
+----------+
SELECT 1 EXCEPT SELECT 2;
+----------+
| Int64(1) |
+----------+
| 1 |
+----------+
SELECT 1 EXCEPT SELECT 1;
++
++
SELECT 1 INTERSECT SELECT 1;
+----------+
| Int64(1) |
+----------+
| 1 |
+----------+
SELECT 1 INTERSECT SELECT 2;
++
++
DROP TABLE test;
Affected Rows: 0

View File

@@ -0,0 +1,41 @@
-- Migrated from DuckDB test: test/sql/setops/test_setops.test
SELECT 1 UNION ALL SELECT 2;
SELECT 1, 'a' UNION ALL SELECT 2, 'b';
SELECT 1, 'a' UNION ALL SELECT 2, 'b' UNION ALL SELECT 3, 'c' ORDER BY 1;
SELECT 1, 'a' UNION ALL SELECT 2, 'b' UNION ALL SELECT 3, 'c' UNION ALL SELECT 4, 'd' ORDER BY 1;
-- NULL values
SELECT NULL UNION SELECT NULL;
SELECT NULL EXCEPT SELECT NULL;
SELECT NULL INTERSECT SELECT NULL;
CREATE TABLE test (a INTEGER, b INTEGER, ts TIMESTAMP TIME INDEX);
INSERT INTO test VALUES (11, 1, 1000), (12, 1, 2000), (13, 2, 3000);
-- Table data
SELECT a FROM test WHERE a < 13 UNION ALL SELECT a FROM test WHERE a = 13 ORDER BY a;
SELECT b FROM test WHERE a < 13 UNION ALL SELECT b FROM test WHERE a > 11 ORDER BY b;
-- Type mixing
SELECT 1 UNION ALL SELECT 'asdf';
-- UNION deduplication
SELECT 1 UNION SELECT 1;
SELECT 1 EXCEPT SELECT 2;
SELECT 1 EXCEPT SELECT 1;
SELECT 1 INTERSECT SELECT 1;
SELECT 1 INTERSECT SELECT 2;
DROP TABLE test;

View File

@@ -0,0 +1,81 @@
-- Migrated from DuckDB test: test/sql/subquery/test_neumann.test
-- Description: Test subqueries from the paper 'Unnesting Arbitrary Subqueries'
CREATE TABLE students("id" INTEGER, "name" VARCHAR, major VARCHAR, "year" INTEGER, ts TIMESTAMP TIME INDEX);
Affected Rows: 0
CREATE TABLE exams(sid INTEGER, course VARCHAR, curriculum VARCHAR, grade INTEGER, "year" INTEGER, ts TIMESTAMP TIME INDEX);
Affected Rows: 0
INSERT INTO students VALUES (1, 'Mark', 'CS', 2017, 1000);
Affected Rows: 1
INSERT INTO students VALUES (2, 'Dirk', 'CS', 2017, 2000);
Affected Rows: 1
INSERT INTO exams VALUES (1, 'Database Systems', 'CS', 10, 2015, 3000);
Affected Rows: 1
INSERT INTO exams VALUES (1, 'Graphics', 'CS', 9, 2016, 4000);
Affected Rows: 1
INSERT INTO exams VALUES (2, 'Database Systems', 'CS', 7, 2015, 5000);
Affected Rows: 1
INSERT INTO exams VALUES (2, 'Graphics', 'CS', 7, 2016, 6000);
Affected Rows: 1
-- Test 1: Subquery with MAX aggregation
SELECT s."name", e.course, e.grade
FROM students s, exams e
WHERE s."id"=e.sid AND e.grade=(SELECT MAX(e2.grade) FROM exams e2 WHERE s."id"=e2.sid)
ORDER BY "name", course;
+------+------------------+-------+
| name | course | grade |
+------+------------------+-------+
| Dirk | Database Systems | 7 |
| Dirk | Graphics | 7 |
| Mark | Database Systems | 10 |
+------+------------------+-------+
-- Test 2: Complex subquery with AVG and conditions
-- TODO: It raise an error right now: Physical plan does not support logical expression ScalarSubquery(<subquery>)
SELECT s."name", e.course, e.grade
FROM students s, exams e
WHERE s."id"=e.sid
AND (s.major = 'CS' OR s.major = 'Games Eng')
AND e.grade <= (SELECT AVG(e2.grade) - 1 FROM exams e2 WHERE s."id"=e2.sid OR (e2.curriculum=s.major AND s."year">=e2."year"))
ORDER BY "name", course;
Error: 1001(Unsupported), This feature is not implemented: Physical plan does not support logical expression ScalarSubquery(<subquery>)
-- Test 3: EXISTS subquery
SELECT "name", major
FROM students s
WHERE EXISTS(SELECT * FROM exams e WHERE e.sid=s."id" AND grade=10) OR s."name"='Dirk'
ORDER BY "name";
+------+-------+
| name | major |
+------+-------+
| Dirk | CS |
| Mark | CS |
+------+-------+
-- Clean up
DROP TABLE exams;
Affected Rows: 0
DROP TABLE students;
Affected Rows: 0

View File

@@ -0,0 +1,44 @@
-- Migrated from DuckDB test: test/sql/subquery/test_neumann.test
-- Description: Test subqueries from the paper 'Unnesting Arbitrary Subqueries'
CREATE TABLE students("id" INTEGER, "name" VARCHAR, major VARCHAR, "year" INTEGER, ts TIMESTAMP TIME INDEX);
CREATE TABLE exams(sid INTEGER, course VARCHAR, curriculum VARCHAR, grade INTEGER, "year" INTEGER, ts TIMESTAMP TIME INDEX);
INSERT INTO students VALUES (1, 'Mark', 'CS', 2017, 1000);
INSERT INTO students VALUES (2, 'Dirk', 'CS', 2017, 2000);
INSERT INTO exams VALUES (1, 'Database Systems', 'CS', 10, 2015, 3000);
INSERT INTO exams VALUES (1, 'Graphics', 'CS', 9, 2016, 4000);
INSERT INTO exams VALUES (2, 'Database Systems', 'CS', 7, 2015, 5000);
INSERT INTO exams VALUES (2, 'Graphics', 'CS', 7, 2016, 6000);
-- Test 1: Subquery with MAX aggregation
SELECT s."name", e.course, e.grade
FROM students s, exams e
WHERE s."id"=e.sid AND e.grade=(SELECT MAX(e2.grade) FROM exams e2 WHERE s."id"=e2.sid)
ORDER BY "name", course;
-- Test 2: Complex subquery with AVG and conditions
-- TODO: It raise an error right now: Physical plan does not support logical expression ScalarSubquery(<subquery>)
SELECT s."name", e.course, e.grade
FROM students s, exams e
WHERE s."id"=e.sid
AND (s.major = 'CS' OR s.major = 'Games Eng')
AND e.grade <= (SELECT AVG(e2.grade) - 1 FROM exams e2 WHERE s."id"=e2.sid OR (e2.curriculum=s.major AND s."year">=e2."year"))
ORDER BY "name", course;
-- Test 3: EXISTS subquery
SELECT "name", major
FROM students s
WHERE EXISTS(SELECT * FROM exams e WHERE e.sid=s."id" AND grade=10) OR s."name"='Dirk'
ORDER BY "name";
-- Clean up
DROP TABLE exams;
DROP TABLE students;

View File

@@ -0,0 +1,43 @@
-- Migrated from DuckDB test: test/sql/subquery/test_offset.test
-- Description: Test bound offset in subquery
-- Test with VALUES clause equivalent using a simple table
CREATE TABLE temp_values(c0 INTEGER, ts TIMESTAMP TIME INDEX);
Affected Rows: 0
INSERT INTO temp_values VALUES (1, 1);
Affected Rows: 1
SELECT (SELECT c0 FROM temp_values OFFSET 1) as result;
++
++
-- Test with actual data
SELECT (SELECT c0 FROM temp_values OFFSET 0) as result;
+--------+
| result |
+--------+
| 1 |
+--------+
-- Test with multiple rows
INSERT INTO temp_values VALUES (2, 2), (3, 3);
Affected Rows: 2
SELECT (SELECT c0 FROM temp_values ORDER BY c0 OFFSET 1 LIMIT 1) as result;
+--------+
| result |
+--------+
| 2 |
+--------+
-- Clean up
DROP TABLE temp_values;
Affected Rows: 0

View File

@@ -0,0 +1,19 @@
-- Migrated from DuckDB test: test/sql/subquery/test_offset.test
-- Description: Test bound offset in subquery
-- Test with VALUES clause equivalent using a simple table
CREATE TABLE temp_values(c0 INTEGER, ts TIMESTAMP TIME INDEX);
INSERT INTO temp_values VALUES (1, 1);
SELECT (SELECT c0 FROM temp_values OFFSET 1) as result;
-- Test with actual data
SELECT (SELECT c0 FROM temp_values OFFSET 0) as result;
-- Test with multiple rows
INSERT INTO temp_values VALUES (2, 2), (3, 3);
SELECT (SELECT c0 FROM temp_values ORDER BY c0 OFFSET 1 LIMIT 1) as result;
-- Clean up
DROP TABLE temp_values;

View File

@@ -0,0 +1,105 @@
-- Migrated from DuckDB test: test/sql/window/test_basic_window.test
-- Description: Most basic window function
CREATE TABLE empsalary (depname varchar, empno bigint, salary int, enroll_date date, ts TIMESTAMP TIME INDEX);
Affected Rows: 0
INSERT INTO empsalary VALUES
('develop', 10, 5200, '2007-08-01', 1000),
('sales', 1, 5000, '2006-10-01', 2000),
('personnel', 5, 3500, '2007-12-10', 3000),
('sales', 4, 4800, '2007-08-08', 4000),
('personnel', 2, 3900, '2006-12-23', 5000),
('develop', 7, 4200, '2008-01-01', 6000),
('develop', 9, 4500, '2008-01-01', 7000),
('sales', 3, 4800, '2007-08-01', 8000),
('develop', 8, 6000, '2006-10-01', 9000),
('develop', 11, 5200, '2007-08-15', 10000);
Affected Rows: 10
-- Basic window function: SUM with PARTITION BY and ORDER BY
SELECT depname, empno, salary, sum(salary) OVER (PARTITION BY depname ORDER BY empno)
FROM empsalary
ORDER BY depname, empno;
+-----------+-------+--------+----------------------------------------------------------------------------------------------------------------------------------------------------+
| depname | empno | salary | sum(empsalary.salary) PARTITION BY [empsalary.depname] ORDER BY [empsalary.empno ASC NULLS LAST] RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW |
+-----------+-------+--------+----------------------------------------------------------------------------------------------------------------------------------------------------+
| develop | 7 | 4200 | 4200 |
| develop | 8 | 6000 | 10200 |
| develop | 9 | 4500 | 14700 |
| develop | 10 | 5200 | 19900 |
| develop | 11 | 5200 | 25100 |
| personnel | 2 | 3900 | 3900 |
| personnel | 5 | 3500 | 7400 |
| sales | 1 | 5000 | 5000 |
| sales | 3 | 4800 | 9800 |
| sales | 4 | 4800 | 14600 |
+-----------+-------+--------+----------------------------------------------------------------------------------------------------------------------------------------------------+
-- SUM with different ordering
SELECT sum(salary) OVER (PARTITION BY depname ORDER BY salary) as ss
FROM empsalary
ORDER BY depname, ss;
+-------+
| ss |
+-------+
| 4200 |
| 8700 |
| 19100 |
| 19100 |
| 25100 |
| 3500 |
| 7400 |
| 9600 |
| 9600 |
| 14600 |
+-------+
-- ROW_NUMBER function
SELECT row_number() OVER (PARTITION BY depname ORDER BY salary) as rn
FROM empsalary
ORDER BY depname, rn;
+----+
| rn |
+----+
| 1 |
| 2 |
| 3 |
| 4 |
| 5 |
| 1 |
| 2 |
| 1 |
| 2 |
| 3 |
+----+
-- FIRST_VALUE function
SELECT empno, first_value(empno) OVER (PARTITION BY depname ORDER BY empno) as fv
FROM empsalary
ORDER BY fv DESC, empno ASC;
+-------+----+
| empno | fv |
+-------+----+
| 7 | 7 |
| 8 | 7 |
| 9 | 7 |
| 10 | 7 |
| 11 | 7 |
| 2 | 2 |
| 5 | 2 |
| 1 | 1 |
| 3 | 1 |
| 4 | 1 |
+-------+----+
-- Clean up
DROP TABLE empsalary;
Affected Rows: 0

View File

@@ -0,0 +1,39 @@
-- Migrated from DuckDB test: test/sql/window/test_basic_window.test
-- Description: Most basic window function
CREATE TABLE empsalary (depname varchar, empno bigint, salary int, enroll_date date, ts TIMESTAMP TIME INDEX);
INSERT INTO empsalary VALUES
('develop', 10, 5200, '2007-08-01', 1000),
('sales', 1, 5000, '2006-10-01', 2000),
('personnel', 5, 3500, '2007-12-10', 3000),
('sales', 4, 4800, '2007-08-08', 4000),
('personnel', 2, 3900, '2006-12-23', 5000),
('develop', 7, 4200, '2008-01-01', 6000),
('develop', 9, 4500, '2008-01-01', 7000),
('sales', 3, 4800, '2007-08-01', 8000),
('develop', 8, 6000, '2006-10-01', 9000),
('develop', 11, 5200, '2007-08-15', 10000);
-- Basic window function: SUM with PARTITION BY and ORDER BY
SELECT depname, empno, salary, sum(salary) OVER (PARTITION BY depname ORDER BY empno)
FROM empsalary
ORDER BY depname, empno;
-- SUM with different ordering
SELECT sum(salary) OVER (PARTITION BY depname ORDER BY salary) as ss
FROM empsalary
ORDER BY depname, ss;
-- ROW_NUMBER function
SELECT row_number() OVER (PARTITION BY depname ORDER BY salary) as rn
FROM empsalary
ORDER BY depname, rn;
-- FIRST_VALUE function
SELECT empno, first_value(empno) OVER (PARTITION BY depname ORDER BY empno) as fv
FROM empsalary
ORDER BY fv DESC, empno ASC;
-- Clean up
DROP TABLE empsalary;