From 039c84b803ab8cc2705435763255ceb8ff05d6e9 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sat, 30 Nov 2024 09:52:04 +0100 Subject: Merging upstream version 25.32.1. Signed-off-by: Daniel Baumann --- tests/dialects/test_bigquery.py | 31 ++++++++++++++++++++++--------- tests/dialects/test_mysql.py | 7 +++++++ 2 files changed, 29 insertions(+), 9 deletions(-) (limited to 'tests') diff --git a/tests/dialects/test_bigquery.py b/tests/dialects/test_bigquery.py index 366cade..26b12a1 100644 --- a/tests/dialects/test_bigquery.py +++ b/tests/dialects/test_bigquery.py @@ -1574,14 +1574,6 @@ WHERE "snowflake": "IFF((y) <> 0, (x) / (y), NULL)", }, ) - self.validate_all( - """SELECT JSON_QUERY('{"class": {"students": []}}', '$.class')""", - write={ - "bigquery": """SELECT JSON_QUERY('{"class": {"students": []}}', '$.class')""", - "duckdb": """SELECT '{"class": {"students": []}}' -> '$.class'""", - "snowflake": """SELECT GET_PATH(PARSE_JSON('{"class": {"students": []}}'), 'class')""", - }, - ) self.validate_all( """SELECT JSON_VALUE_ARRAY('{"arr": [1, "a"]}', '$.arr')""", write={ @@ -2139,7 +2131,16 @@ OPTIONS ( }, ) - def test_json_extract_scalar(self): + def test_json_extract(self): + self.validate_all( + """SELECT JSON_QUERY('{"class": {"students": []}}', '$.class')""", + write={ + "bigquery": """SELECT JSON_QUERY('{"class": {"students": []}}', '$.class')""", + "duckdb": """SELECT '{"class": {"students": []}}' -> '$.class'""", + "snowflake": """SELECT GET_PATH(PARSE_JSON('{"class": {"students": []}}'), 'class')""", + }, + ) + for func in ("JSON_EXTRACT_SCALAR", "JSON_VALUE"): with self.subTest(f"Testing BigQuery's {func}"): self.validate_all( @@ -2164,6 +2165,18 @@ OPTIONS ( self.parse_one(sql).sql("bigquery", normalize_functions="upper"), sql ) + # Test double quote escaping + for func in ("JSON_VALUE", "JSON_QUERY", "JSON_QUERY_ARRAY"): + self.validate_identity( + f"{func}(doc, '$. a b c .d')", f"""{func}(doc, '$." a b c ".d')""" + ) + + # Test single quote & bracket escaping + for func in ("JSON_EXTRACT", "JSON_EXTRACT_SCALAR", "JSON_EXTRACT_ARRAY"): + self.validate_identity( + f"{func}(doc, '$. a b c .d')", f"""{func}(doc, '$[\\' a b c \\'].d')""" + ) + def test_json_extract_array(self): for func in ("JSON_QUERY_ARRAY", "JSON_EXTRACT_ARRAY"): with self.subTest(f"Testing BigQuery's {func}"): diff --git a/tests/dialects/test_mysql.py b/tests/dialects/test_mysql.py index fd6b36f..9e5b74e 100644 --- a/tests/dialects/test_mysql.py +++ b/tests/dialects/test_mysql.py @@ -118,6 +118,13 @@ class TestMySQL(Validator): "CREATE TABLE `foo` (a VARCHAR(10), INDEX idx_a (a DESC))", ) + self.validate_all( + "insert into t(i) values (default)", + write={ + "duckdb": "INSERT INTO t (i) VALUES (DEFAULT)", + "mysql": "INSERT INTO t (i) VALUES (DEFAULT)", + }, + ) self.validate_all( "CREATE TABLE t (id INT UNSIGNED)", write={ -- cgit v1.2.3