summaryrefslogtreecommitdiffstats
path: root/tests/dialects
diff options
context:
space:
mode:
Diffstat (limited to 'tests/dialects')
-rw-r--r--tests/dialects/test_bigquery.py31
-rw-r--r--tests/dialects/test_mysql.py7
2 files changed, 29 insertions, 9 deletions
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
@@ -1575,14 +1575,6 @@ WHERE
},
)
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={
"bigquery": """SELECT JSON_VALUE_ARRAY('{"arr": [1, "a"]}', '$.arr')""",
@@ -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
@@ -119,6 +119,13 @@ class TestMySQL(Validator):
)
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={
"duckdb": "CREATE TABLE t (id UINTEGER)",