From 862ffe93f7f5530e12816e57fbb77d58932c10ad Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Tue, 11 Jun 2024 18:35:00 +0200 Subject: Merging upstream version 25.0.3. Signed-off-by: Daniel Baumann --- tests/dialects/test_duckdb.py | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) (limited to 'tests/dialects/test_duckdb.py') diff --git a/tests/dialects/test_duckdb.py b/tests/dialects/test_duckdb.py index bbf665d..cd68ff9 100644 --- a/tests/dialects/test_duckdb.py +++ b/tests/dialects/test_duckdb.py @@ -1,4 +1,4 @@ -from sqlglot import ErrorLevel, UnsupportedError, exp, parse_one, transpile +from sqlglot import ErrorLevel, ParseError, UnsupportedError, exp, parse_one, transpile from sqlglot.helper import logger as helper_logger from sqlglot.optimizer.annotate_types import annotate_types from tests.dialects.test_dialect import Validator @@ -8,6 +8,9 @@ class TestDuckDB(Validator): dialect = "duckdb" def test_duckdb(self): + with self.assertRaises(ParseError): + parse_one("1 //", read="duckdb") + query = "WITH _data AS (SELECT [{'a': 1, 'b': 2}, {'a': 2, 'b': 3}] AS col) SELECT t.col['b'] FROM _data, UNNEST(_data.col) AS t(col) WHERE t.col['a'] = 1" expr = annotate_types(self.validate_identity(query)) self.assertEqual( @@ -15,6 +18,13 @@ class TestDuckDB(Validator): "WITH _data AS (SELECT [STRUCT(1 AS a, 2 AS b), STRUCT(2 AS a, 3 AS b)] AS col) SELECT col.b FROM _data, UNNEST(_data.col) AS col WHERE col.a = 1", ) + self.validate_all( + "SELECT CAST('2020-01-01 12:05:01' AS TIMESTAMP)", + read={ + "duckdb": "SELECT CAST('2020-01-01 12:05:01' AS TIMESTAMP)", + "snowflake": "SELECT CAST('2020-01-01 12:05:01' AS TIMESTAMPNTZ)", + }, + ) self.validate_all( "SELECT CAST('2020-01-01' AS DATE) + INTERVAL (day_offset) DAY FROM t", read={ @@ -247,7 +257,7 @@ class TestDuckDB(Validator): self.validate_identity("SELECT EPOCH_MS(10) AS t") self.validate_identity("SELECT MAKE_TIMESTAMP(10) AS t") self.validate_identity("SELECT TO_TIMESTAMP(10) AS t") - self.validate_identity("SELECT UNNEST(column, recursive := TRUE) FROM table") + self.validate_identity("SELECT UNNEST(col, recursive := TRUE) FROM t") self.validate_identity("VAR_POP(a)") self.validate_identity("SELECT * FROM foo ASOF LEFT JOIN bar ON a = b") self.validate_identity("PIVOT Cities ON Year USING SUM(Population)") @@ -271,6 +281,10 @@ class TestDuckDB(Validator): self.validate_identity( "SELECT * FROM x LEFT JOIN UNNEST(y)", "SELECT * FROM x LEFT JOIN UNNEST(y) ON TRUE" ) + self.validate_identity( + "SELECT a, LOGICAL_OR(b) FROM foo GROUP BY a", + "SELECT a, BOOL_OR(b) FROM foo GROUP BY a", + ) self.validate_identity( "SELECT JSON_EXTRACT_STRING(c, '$.k1') = 'v1'", "SELECT (c ->> '$.k1') = 'v1'", @@ -424,15 +438,15 @@ class TestDuckDB(Validator): write={"duckdb": 'WITH "x" AS (SELECT 1) SELECT * FROM x'}, ) self.validate_all( - "CREATE TABLE IF NOT EXISTS table (cola INT, colb STRING) USING ICEBERG PARTITIONED BY (colb)", + "CREATE TABLE IF NOT EXISTS t (cola INT, colb STRING) USING ICEBERG PARTITIONED BY (colb)", write={ - "duckdb": "CREATE TABLE IF NOT EXISTS table (cola INT, colb TEXT)", + "duckdb": "CREATE TABLE IF NOT EXISTS t (cola INT, colb TEXT)", }, ) self.validate_all( - "CREATE TABLE IF NOT EXISTS table (cola INT COMMENT 'cola', colb STRING) USING ICEBERG PARTITIONED BY (colb)", + "CREATE TABLE IF NOT EXISTS t (cola INT COMMENT 'cola', colb STRING) USING ICEBERG PARTITIONED BY (colb)", write={ - "duckdb": "CREATE TABLE IF NOT EXISTS table (cola INT, colb TEXT)", + "duckdb": "CREATE TABLE IF NOT EXISTS t (cola INT, colb TEXT)", }, ) self.validate_all( @@ -1086,12 +1100,6 @@ class TestDuckDB(Validator): }, ) - def test_bool_or(self): - self.validate_all( - "SELECT a, LOGICAL_OR(b) FROM table GROUP BY a", - write={"duckdb": "SELECT a, BOOL_OR(b) FROM table GROUP BY a"}, - ) - def test_encode_decode(self): self.validate_all( "ENCODE(x)", -- cgit v1.2.3