From b94ce9019d73a8823abdf0e0f022e0cb4fef0518 Mon Sep 17 00:00:00 2001 From: dennis zhuang Date: Fri, 5 Sep 2025 14:10:14 +0800 Subject: [PATCH] test: migrate duckdb tests, part 1 (#6870) * test: migrate duckdb tests Signed-off-by: Dennis Zhuang * fix: style Signed-off-by: Dennis Zhuang * test: add more duckdb tests Signed-off-by: Dennis Zhuang * fix: stable order Signed-off-by: Dennis Zhuang * chore: simplfy comments Signed-off-by: Dennis Zhuang * chore: remove tests/cases/standalone/common/DUCKDB_MIGRATION_GUIDE.md * fix: incorrect_sql.sql Signed-off-by: Dennis Zhuang * fix: integer flow test Signed-off-by: Dennis Zhuang * fix: integer flow test Signed-off-by: Dennis Zhuang * docs: add todo Signed-off-by: Dennis Zhuang --------- Signed-off-by: Dennis Zhuang --- .../common/cast/boolean_cast.result | 94 ++++++++++++ .../standalone/common/cast/boolean_cast.sql | 28 ++++ .../common/cast/string_to_integer.result | 95 ++++++++++++ .../common/cast/string_to_integer.sql | 31 ++++ .../common/error/incorrect_sql.result | 92 ++++++++++++ .../standalone/common/error/incorrect_sql.sql | 51 +++++++ .../common/filter/constant_comparisons.result | 125 ++++++++++++++++ .../common/filter/constant_comparisons.sql | 44 ++++++ .../common/join/complex_join_expr.result | 74 +++++++++ .../common/join/complex_join_expr.sql | 27 ++++ .../common/keywords/escaped_quotes.result | 41 +++++ .../common/keywords/escaped_quotes.sql | 17 +++ .../keywords/keywords_expressions.result | 78 ++++++++++ .../common/keywords/keywords_expressions.sql | 31 ++++ .../common/limit/limit_advanced.result | 71 +++++++++ .../common/limit/limit_advanced.sql | 20 +++ .../standalone/common/order/limit_zero.result | 33 ++++ .../standalone/common/order/limit_zero.sql | 18 +++ .../common/overflow/integer_overflow.result | 108 ++++++++++++++ .../common/overflow/integer_overflow.sql | 36 +++++ .../common/parser/operator_precedence.result | 38 +++++ .../common/parser/operator_precedence.sql | 15 ++ .../common/select/multi_column_ref.result | 71 +++++++++ .../common/select/multi_column_ref.sql | 30 ++++ .../common/select/projection_names.result | 66 ++++++++ .../common/select/projection_names.sql | 25 ++++ .../common/select/qualified_view.result | 51 +++++++ .../common/select/qualified_view.sql | 25 ++++ .../common/select/schema_reference.result | 38 +++++ .../common/select/schema_reference.sql | 19 +++ .../common/setops/basic_setops.result | 141 ++++++++++++++++++ .../standalone/common/setops/basic_setops.sql | 41 +++++ .../standalone/common/subquery/neumann.result | 81 ++++++++++ .../standalone/common/subquery/neumann.sql | 44 ++++++ .../standalone/common/subquery/offset.result | 43 ++++++ .../standalone/common/subquery/offset.sql | 19 +++ .../common/window/basic_window.result | 105 +++++++++++++ .../standalone/common/window/basic_window.sql | 39 +++++ 38 files changed, 2005 insertions(+) create mode 100644 tests/cases/standalone/common/cast/boolean_cast.result create mode 100644 tests/cases/standalone/common/cast/boolean_cast.sql create mode 100644 tests/cases/standalone/common/cast/string_to_integer.result create mode 100644 tests/cases/standalone/common/cast/string_to_integer.sql create mode 100644 tests/cases/standalone/common/error/incorrect_sql.result create mode 100644 tests/cases/standalone/common/error/incorrect_sql.sql create mode 100644 tests/cases/standalone/common/filter/constant_comparisons.result create mode 100644 tests/cases/standalone/common/filter/constant_comparisons.sql create mode 100644 tests/cases/standalone/common/join/complex_join_expr.result create mode 100644 tests/cases/standalone/common/join/complex_join_expr.sql create mode 100644 tests/cases/standalone/common/keywords/escaped_quotes.result create mode 100644 tests/cases/standalone/common/keywords/escaped_quotes.sql create mode 100644 tests/cases/standalone/common/keywords/keywords_expressions.result create mode 100644 tests/cases/standalone/common/keywords/keywords_expressions.sql create mode 100644 tests/cases/standalone/common/limit/limit_advanced.result create mode 100644 tests/cases/standalone/common/limit/limit_advanced.sql create mode 100644 tests/cases/standalone/common/order/limit_zero.result create mode 100644 tests/cases/standalone/common/order/limit_zero.sql create mode 100644 tests/cases/standalone/common/overflow/integer_overflow.result create mode 100644 tests/cases/standalone/common/overflow/integer_overflow.sql create mode 100644 tests/cases/standalone/common/select/multi_column_ref.result create mode 100644 tests/cases/standalone/common/select/multi_column_ref.sql create mode 100644 tests/cases/standalone/common/select/projection_names.result create mode 100644 tests/cases/standalone/common/select/projection_names.sql create mode 100644 tests/cases/standalone/common/select/qualified_view.result create mode 100644 tests/cases/standalone/common/select/qualified_view.sql create mode 100644 tests/cases/standalone/common/select/schema_reference.result create mode 100644 tests/cases/standalone/common/select/schema_reference.sql create mode 100644 tests/cases/standalone/common/setops/basic_setops.result create mode 100644 tests/cases/standalone/common/setops/basic_setops.sql create mode 100644 tests/cases/standalone/common/subquery/neumann.result create mode 100644 tests/cases/standalone/common/subquery/neumann.sql create mode 100644 tests/cases/standalone/common/subquery/offset.result create mode 100644 tests/cases/standalone/common/subquery/offset.sql create mode 100644 tests/cases/standalone/common/window/basic_window.result create mode 100644 tests/cases/standalone/common/window/basic_window.sql diff --git a/tests/cases/standalone/common/cast/boolean_cast.result b/tests/cases/standalone/common/cast/boolean_cast.result new file mode 100644 index 0000000000..13fc0efd13 --- /dev/null +++ b/tests/cases/standalone/common/cast/boolean_cast.result @@ -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 | ++---------------------------------+ + diff --git a/tests/cases/standalone/common/cast/boolean_cast.sql b/tests/cases/standalone/common/cast/boolean_cast.sql new file mode 100644 index 0000000000..4531df26ef --- /dev/null +++ b/tests/cases/standalone/common/cast/boolean_cast.sql @@ -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; diff --git a/tests/cases/standalone/common/cast/string_to_integer.result b/tests/cases/standalone/common/cast/string_to_integer.result new file mode 100644 index 0000000000..8ad8aefaa9 --- /dev/null +++ b/tests/cases/standalone/common/cast/string_to_integer.result @@ -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 + diff --git a/tests/cases/standalone/common/cast/string_to_integer.sql b/tests/cases/standalone/common/cast/string_to_integer.sql new file mode 100644 index 0000000000..e197eff728 --- /dev/null +++ b/tests/cases/standalone/common/cast/string_to_integer.sql @@ -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; diff --git a/tests/cases/standalone/common/error/incorrect_sql.result b/tests/cases/standalone/common/error/incorrect_sql.result new file mode 100644 index 0000000000..5069376ed6 --- /dev/null +++ b/tests/cases/standalone/common/error/incorrect_sql.result @@ -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 + diff --git a/tests/cases/standalone/common/error/incorrect_sql.sql b/tests/cases/standalone/common/error/incorrect_sql.sql new file mode 100644 index 0000000000..dc212782aa --- /dev/null +++ b/tests/cases/standalone/common/error/incorrect_sql.sql @@ -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; diff --git a/tests/cases/standalone/common/filter/constant_comparisons.result b/tests/cases/standalone/common/filter/constant_comparisons.result new file mode 100644 index 0000000000..9dba691e91 --- /dev/null +++ b/tests/cases/standalone/common/filter/constant_comparisons.result @@ -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 + diff --git a/tests/cases/standalone/common/filter/constant_comparisons.sql b/tests/cases/standalone/common/filter/constant_comparisons.sql new file mode 100644 index 0000000000..37a8d1c863 --- /dev/null +++ b/tests/cases/standalone/common/filter/constant_comparisons.sql @@ -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; diff --git a/tests/cases/standalone/common/join/complex_join_expr.result b/tests/cases/standalone/common/join/complex_join_expr.result new file mode 100644 index 0000000000..57d9a87391 --- /dev/null +++ b/tests/cases/standalone/common/join/complex_join_expr.result @@ -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 + diff --git a/tests/cases/standalone/common/join/complex_join_expr.sql b/tests/cases/standalone/common/join/complex_join_expr.sql new file mode 100644 index 0000000000..135b85d5a7 --- /dev/null +++ b/tests/cases/standalone/common/join/complex_join_expr.sql @@ -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; diff --git a/tests/cases/standalone/common/keywords/escaped_quotes.result b/tests/cases/standalone/common/keywords/escaped_quotes.result new file mode 100644 index 0000000000..690c65ca4a --- /dev/null +++ b/tests/cases/standalone/common/keywords/escaped_quotes.result @@ -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 + diff --git a/tests/cases/standalone/common/keywords/escaped_quotes.sql b/tests/cases/standalone/common/keywords/escaped_quotes.sql new file mode 100644 index 0000000000..2b3fe11779 --- /dev/null +++ b/tests/cases/standalone/common/keywords/escaped_quotes.sql @@ -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; diff --git a/tests/cases/standalone/common/keywords/keywords_expressions.result b/tests/cases/standalone/common/keywords/keywords_expressions.result new file mode 100644 index 0000000000..c252f0a540 --- /dev/null +++ b/tests/cases/standalone/common/keywords/keywords_expressions.result @@ -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 + diff --git a/tests/cases/standalone/common/keywords/keywords_expressions.sql b/tests/cases/standalone/common/keywords/keywords_expressions.sql new file mode 100644 index 0000000000..8cc22de862 --- /dev/null +++ b/tests/cases/standalone/common/keywords/keywords_expressions.sql @@ -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"; diff --git a/tests/cases/standalone/common/limit/limit_advanced.result b/tests/cases/standalone/common/limit/limit_advanced.result new file mode 100644 index 0000000000..d43f319fee --- /dev/null +++ b/tests/cases/standalone/common/limit/limit_advanced.result @@ -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 + diff --git a/tests/cases/standalone/common/limit/limit_advanced.sql b/tests/cases/standalone/common/limit/limit_advanced.sql new file mode 100644 index 0000000000..dc44596187 --- /dev/null +++ b/tests/cases/standalone/common/limit/limit_advanced.sql @@ -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; diff --git a/tests/cases/standalone/common/order/limit_zero.result b/tests/cases/standalone/common/order/limit_zero.result new file mode 100644 index 0000000000..8460464b4f --- /dev/null +++ b/tests/cases/standalone/common/order/limit_zero.result @@ -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 + diff --git a/tests/cases/standalone/common/order/limit_zero.sql b/tests/cases/standalone/common/order/limit_zero.sql new file mode 100644 index 0000000000..6b34c559ac --- /dev/null +++ b/tests/cases/standalone/common/order/limit_zero.sql @@ -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; diff --git a/tests/cases/standalone/common/overflow/integer_overflow.result b/tests/cases/standalone/common/overflow/integer_overflow.result new file mode 100644 index 0000000000..6891d9d4d1 --- /dev/null +++ b/tests/cases/standalone/common/overflow/integer_overflow.result @@ -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 | ++------------------------------------------+ + diff --git a/tests/cases/standalone/common/overflow/integer_overflow.sql b/tests/cases/standalone/common/overflow/integer_overflow.sql new file mode 100644 index 0000000000..23885aeedc --- /dev/null +++ b/tests/cases/standalone/common/overflow/integer_overflow.sql @@ -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; diff --git a/tests/cases/standalone/common/parser/operator_precedence.result b/tests/cases/standalone/common/parser/operator_precedence.result index aa0a1895d1..7d2a91d9c7 100644 --- a/tests/cases/standalone/common/parser/operator_precedence.result +++ b/tests/cases/standalone/common/parser/operator_precedence.result @@ -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 | ++---------------------------------+ + diff --git a/tests/cases/standalone/common/parser/operator_precedence.sql b/tests/cases/standalone/common/parser/operator_precedence.sql index 93f23cf38e..f3fe031507 100644 --- a/tests/cases/standalone/common/parser/operator_precedence.sql +++ b/tests/cases/standalone/common/parser/operator_precedence.sql @@ -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); diff --git a/tests/cases/standalone/common/select/multi_column_ref.result b/tests/cases/standalone/common/select/multi_column_ref.result new file mode 100644 index 0000000000..8a65d3bf61 --- /dev/null +++ b/tests/cases/standalone/common/select/multi_column_ref.result @@ -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 + diff --git a/tests/cases/standalone/common/select/multi_column_ref.sql b/tests/cases/standalone/common/select/multi_column_ref.sql new file mode 100644 index 0000000000..c7d7c4d93e --- /dev/null +++ b/tests/cases/standalone/common/select/multi_column_ref.sql @@ -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; diff --git a/tests/cases/standalone/common/select/projection_names.result b/tests/cases/standalone/common/select/projection_names.result new file mode 100644 index 0000000000..3f512f0533 --- /dev/null +++ b/tests/cases/standalone/common/select/projection_names.result @@ -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 + diff --git a/tests/cases/standalone/common/select/projection_names.sql b/tests/cases/standalone/common/select/projection_names.sql new file mode 100644 index 0000000000..2a286782b8 --- /dev/null +++ b/tests/cases/standalone/common/select/projection_names.sql @@ -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; diff --git a/tests/cases/standalone/common/select/qualified_view.result b/tests/cases/standalone/common/select/qualified_view.result new file mode 100644 index 0000000000..29e52fab4a --- /dev/null +++ b/tests/cases/standalone/common/select/qualified_view.result @@ -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 + diff --git a/tests/cases/standalone/common/select/qualified_view.sql b/tests/cases/standalone/common/select/qualified_view.sql new file mode 100644 index 0000000000..f6a6e57dc1 --- /dev/null +++ b/tests/cases/standalone/common/select/qualified_view.sql @@ -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; diff --git a/tests/cases/standalone/common/select/schema_reference.result b/tests/cases/standalone/common/select/schema_reference.result new file mode 100644 index 0000000000..37d2de4c8c --- /dev/null +++ b/tests/cases/standalone/common/select/schema_reference.result @@ -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 + diff --git a/tests/cases/standalone/common/select/schema_reference.sql b/tests/cases/standalone/common/select/schema_reference.sql new file mode 100644 index 0000000000..94f6086251 --- /dev/null +++ b/tests/cases/standalone/common/select/schema_reference.sql @@ -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; diff --git a/tests/cases/standalone/common/setops/basic_setops.result b/tests/cases/standalone/common/setops/basic_setops.result new file mode 100644 index 0000000000..47a2bedcfe --- /dev/null +++ b/tests/cases/standalone/common/setops/basic_setops.result @@ -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 + diff --git a/tests/cases/standalone/common/setops/basic_setops.sql b/tests/cases/standalone/common/setops/basic_setops.sql new file mode 100644 index 0000000000..dca9e06c92 --- /dev/null +++ b/tests/cases/standalone/common/setops/basic_setops.sql @@ -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; diff --git a/tests/cases/standalone/common/subquery/neumann.result b/tests/cases/standalone/common/subquery/neumann.result new file mode 100644 index 0000000000..66d167bfbc --- /dev/null +++ b/tests/cases/standalone/common/subquery/neumann.result @@ -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() +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() + +-- 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 + diff --git a/tests/cases/standalone/common/subquery/neumann.sql b/tests/cases/standalone/common/subquery/neumann.sql new file mode 100644 index 0000000000..9501048810 --- /dev/null +++ b/tests/cases/standalone/common/subquery/neumann.sql @@ -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() +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; diff --git a/tests/cases/standalone/common/subquery/offset.result b/tests/cases/standalone/common/subquery/offset.result new file mode 100644 index 0000000000..aa5398b38e --- /dev/null +++ b/tests/cases/standalone/common/subquery/offset.result @@ -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 + diff --git a/tests/cases/standalone/common/subquery/offset.sql b/tests/cases/standalone/common/subquery/offset.sql new file mode 100644 index 0000000000..9fc966024e --- /dev/null +++ b/tests/cases/standalone/common/subquery/offset.sql @@ -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; diff --git a/tests/cases/standalone/common/window/basic_window.result b/tests/cases/standalone/common/window/basic_window.result new file mode 100644 index 0000000000..bf23d9eb84 --- /dev/null +++ b/tests/cases/standalone/common/window/basic_window.result @@ -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 + diff --git a/tests/cases/standalone/common/window/basic_window.sql b/tests/cases/standalone/common/window/basic_window.sql new file mode 100644 index 0000000000..3c961bd1db --- /dev/null +++ b/tests/cases/standalone/common/window/basic_window.sql @@ -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;