1
0
Fork 0

Merging upstream version 18.11.2.

Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
Daniel Baumann 2025-02-13 21:04:58 +01:00
parent 15b8b39545
commit c37998973e
Signed by: daniel
GPG key ID: FBB4F0E80A80222F
88 changed files with 52059 additions and 46960 deletions

View file

@ -5,6 +5,7 @@ from sqlglot import (
Dialects,
ErrorLevel,
ParseError,
TokenError,
UnsupportedError,
parse_one,
)
@ -308,6 +309,44 @@ class TestDialect(Validator):
read={"postgres": "INET '127.0.0.1/32'"},
)
def test_heredoc_strings(self):
for dialect in ("clickhouse", "postgres", "redshift"):
# Invalid matching tag
with self.assertRaises(TokenError):
parse_one("SELECT $tag1$invalid heredoc string$tag2$", dialect=dialect)
# Unmatched tag
with self.assertRaises(TokenError):
parse_one("SELECT $tag1$invalid heredoc string", dialect=dialect)
# Without tag
self.validate_all(
"SELECT 'this is a heredoc string'",
read={
dialect: "SELECT $$this is a heredoc string$$",
},
)
self.validate_all(
"SELECT ''",
read={
dialect: "SELECT $$$$",
},
)
# With tag
self.validate_all(
"SELECT 'this is also a heredoc string'",
read={
dialect: "SELECT $foo$this is also a heredoc string$foo$",
},
)
self.validate_all(
"SELECT ''",
read={
dialect: "SELECT $foo$$foo$",
},
)
def test_decode(self):
self.validate_identity("DECODE(bin, charset)")
@ -568,6 +607,7 @@ class TestDialect(Validator):
"presto": "CAST(CAST(x AS TIMESTAMP) AS DATE)",
"snowflake": "CAST(x AS DATE)",
"doris": "TO_DATE(x)",
"mysql": "DATE(x)",
},
)
self.validate_all(
@ -648,9 +688,7 @@ class TestDialect(Validator):
self.validate_all(
"DATE_ADD(x, 1, 'DAY')",
read={
"mysql": "DATE_ADD(x, INTERVAL 1 DAY)",
"snowflake": "DATEADD('DAY', 1, x)",
"starrocks": "DATE_ADD(x, INTERVAL 1 DAY)",
},
write={
"bigquery": "DATE_ADD(x, INTERVAL 1 DAY)",
@ -842,6 +880,7 @@ class TestDialect(Validator):
"hive": "DATE_ADD('2021-02-01', 1)",
"presto": "DATE_ADD('DAY', 1, CAST(CAST('2021-02-01' AS TIMESTAMP) AS DATE))",
"spark": "DATE_ADD('2021-02-01', 1)",
"mysql": "DATE_ADD('2021-02-01', INTERVAL 1 DAY)",
},
)
self.validate_all(
@ -897,10 +936,7 @@ class TestDialect(Validator):
"bigquery",
"drill",
"duckdb",
"mysql",
"presto",
"starrocks",
"doris",
)
},
write={
@ -913,8 +949,25 @@ class TestDialect(Validator):
"presto",
"hive",
"spark",
"starrocks",
)
},
)
self.validate_all(
f"{unit}(TS_OR_DS_TO_DATE(x))",
read={
dialect: f"{unit}(x)"
for dialect in (
"mysql",
"doris",
"starrocks",
)
},
write={
dialect: f"{unit}(x)"
for dialect in (
"mysql",
"doris",
"starrocks",
)
},
)
@ -1790,3 +1843,17 @@ SELECT
with self.assertRaises(ParseError):
parse_one("CAST(x AS some_udt)", read="bigquery")
def test_qualify(self):
self.validate_all(
"SELECT * FROM t QUALIFY COUNT(*) OVER () > 1",
write={
"duckdb": "SELECT * FROM t QUALIFY COUNT(*) OVER () > 1",
"snowflake": "SELECT * FROM t QUALIFY COUNT(*) OVER () > 1",
"clickhouse": "SELECT * FROM (SELECT *, COUNT(*) OVER () AS _w FROM t) AS _t WHERE _w > 1",
"mysql": "SELECT * FROM (SELECT *, COUNT(*) OVER () AS _w FROM t) AS _t WHERE _w > 1",
"oracle": "SELECT * FROM (SELECT *, COUNT(*) OVER () AS _w FROM t) _t WHERE _w > 1",
"postgres": "SELECT * FROM (SELECT *, COUNT(*) OVER () AS _w FROM t) AS _t WHERE _w > 1",
"tsql": "SELECT * FROM (SELECT *, COUNT(*) OVER () AS _w FROM t) AS _t WHERE _w > 1",
},
)