diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-02-08 05:38:39 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-02-08 05:38:39 +0000 |
commit | aedf35026379f52d7e2b4c1f957691410a758089 (patch) | |
tree | 86540364259b66741173d2333387b78d6f9c31e2 /tests/dialects/test_duckdb.py | |
parent | Adding upstream version 20.11.0. (diff) | |
download | sqlglot-aedf35026379f52d7e2b4c1f957691410a758089.tar.xz sqlglot-aedf35026379f52d7e2b4c1f957691410a758089.zip |
Adding upstream version 21.0.1.upstream/21.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/dialects/test_duckdb.py')
-rw-r--r-- | tests/dialects/test_duckdb.py | 38 |
1 files changed, 34 insertions, 4 deletions
diff --git a/tests/dialects/test_duckdb.py b/tests/dialects/test_duckdb.py index f3b41b4..9c48f69 100644 --- a/tests/dialects/test_duckdb.py +++ b/tests/dialects/test_duckdb.py @@ -41,6 +41,7 @@ class TestDuckDB(Validator): ) self.validate_identity("SELECT 1 WHERE x > $1") self.validate_identity("SELECT 1 WHERE x > $name") + self.validate_identity("""SELECT '{"x": 1}' -> c FROM t""") self.assertEqual( parse_one("select * from t limit (select 5)").sql(dialect="duckdb"), @@ -89,18 +90,26 @@ class TestDuckDB(Validator): }, ) + self.validate_identity("""SELECT '{"duck": [1, 2, 3]}' -> '$.duck[#-1]'""") + self.validate_all( + """SELECT JSON_EXTRACT('{"duck": [1, 2, 3]}', '/duck/0')""", + write={ + "": """SELECT JSON_EXTRACT('{"duck": [1, 2, 3]}', '/duck/0')""", + "duckdb": """SELECT '{"duck": [1, 2, 3]}' -> '/duck/0'""", + }, + ) self.validate_all( """SELECT JSON('{"fruit":"banana"}') -> 'fruit'""", write={ - "duckdb": """SELECT JSON('{"fruit":"banana"}') -> 'fruit'""", - "snowflake": """SELECT PARSE_JSON('{"fruit":"banana"}')['fruit']""", + "duckdb": """SELECT JSON('{"fruit":"banana"}') -> '$.fruit'""", + "snowflake": """SELECT GET_PATH(PARSE_JSON('{"fruit":"banana"}'), 'fruit')""", }, ) self.validate_all( """SELECT JSON('{"fruit": {"foo": "banana"}}') -> 'fruit' -> 'foo'""", write={ - "duckdb": """SELECT JSON('{"fruit": {"foo": "banana"}}') -> 'fruit' -> 'foo'""", - "snowflake": """SELECT PARSE_JSON('{"fruit": {"foo": "banana"}}')['fruit']['foo']""", + "duckdb": """SELECT JSON('{"fruit": {"foo": "banana"}}') -> '$.fruit' -> '$.foo'""", + "snowflake": """SELECT GET_PATH(GET_PATH(PARSE_JSON('{"fruit": {"foo": "banana"}}'), 'fruit'), 'foo')""", }, ) self.validate_all( @@ -199,6 +208,27 @@ class TestDuckDB(Validator): self.validate_identity("FROM x SELECT x UNION SELECT 1", "SELECT x FROM x UNION SELECT 1") self.validate_identity("FROM (FROM tbl)", "SELECT * FROM (SELECT * FROM tbl)") self.validate_identity("FROM tbl", "SELECT * FROM tbl") + self.validate_identity("x -> '$.family'") + self.validate_identity( + """SELECT '{"foo": [1, 2, 3]}' -> 'foo' -> 0""", + """SELECT '{"foo": [1, 2, 3]}' -> '$.foo' -> '$[0]'""", + ) + self.validate_identity( + "JSON_EXTRACT(x, '$.family')", + "x -> '$.family'", + ) + self.validate_identity( + "JSON_EXTRACT_PATH(x, '$.family')", + "x -> '$.family'", + ) + self.validate_identity( + "JSON_EXTRACT_STRING(x, '$.family')", + "x ->> '$.family'", + ) + self.validate_identity( + "JSON_EXTRACT_PATH_TEXT(x, '$.family')", + "x ->> '$.family'", + ) self.validate_identity( "ATTACH DATABASE ':memory:' AS new_database", check_command_warning=True ) |