summaryrefslogtreecommitdiffstats
path: root/tests/dialects/test_bigquery.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2023-07-06 07:28:09 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2023-07-06 07:28:09 +0000
commit52f4a5e2260f3e5b919b4e270339afd670bf0b8a (patch)
tree5ca419af0e2e409018492b82f5b9847f0112b5fb /tests/dialects/test_bigquery.py
parentAdding upstream version 16.7.7. (diff)
downloadsqlglot-52f4a5e2260f3e5b919b4e270339afd670bf0b8a.tar.xz
sqlglot-52f4a5e2260f3e5b919b4e270339afd670bf0b8a.zip
Adding upstream version 17.2.0.upstream/17.2.0
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/dialects/test_bigquery.py')
-rw-r--r--tests/dialects/test_bigquery.py34
1 files changed, 29 insertions, 5 deletions
diff --git a/tests/dialects/test_bigquery.py b/tests/dialects/test_bigquery.py
index e3fc495..eac3cac 100644
--- a/tests/dialects/test_bigquery.py
+++ b/tests/dialects/test_bigquery.py
@@ -29,12 +29,14 @@ class TestBigQuery(Validator):
with self.assertRaises(ParseError):
transpile("SELECT * FROM UNNEST(x) AS x(y)", read="bigquery")
+ self.validate_identity("SELECT PARSE_TIMESTAMP('%c', 'Thu Dec 25 07:30:00 2008', 'UTC')")
self.validate_identity("SELECT ANY_VALUE(fruit HAVING MAX sold) FROM fruits")
self.validate_identity("SELECT ANY_VALUE(fruit HAVING MIN sold) FROM fruits")
self.validate_identity("SELECT `project-id`.udfs.func(call.dir)")
self.validate_identity("SELECT CAST(CURRENT_DATE AS STRING FORMAT 'DAY') AS current_day")
self.validate_identity("SAFE_CAST(encrypted_value AS STRING FORMAT 'BASE64')")
self.validate_identity("CAST(encrypted_value AS STRING FORMAT 'BASE64')")
+ self.validate_identity("CAST(STRUCT<a INT64>(1) AS STRUCT<a INT64>)")
self.validate_identity("STRING_AGG(a)")
self.validate_identity("STRING_AGG(a, ' & ')")
self.validate_identity("STRING_AGG(DISTINCT a, ' & ')")
@@ -106,6 +108,14 @@ class TestBigQuery(Validator):
self.validate_all("CAST(x AS TIMESTAMPTZ)", write={"bigquery": "CAST(x AS TIMESTAMP)"})
self.validate_all("CAST(x AS RECORD)", write={"bigquery": "CAST(x AS STRUCT)"})
self.validate_all(
+ "SELECT CAST('20201225' AS TIMESTAMP FORMAT 'YYYYMMDD' AT TIME ZONE 'America/New_York')",
+ write={"bigquery": "SELECT PARSE_TIMESTAMP('%Y%m%d', '20201225', 'America/New_York')"},
+ )
+ self.validate_all(
+ "SELECT CAST('20201225' AS TIMESTAMP FORMAT 'YYYYMMDD')",
+ write={"bigquery": "SELECT PARSE_TIMESTAMP('%Y%m%d', '20201225')"},
+ )
+ self.validate_all(
"SELECT CAST(TIMESTAMP '2008-12-25 00:00:00+00:00' AS STRING FORMAT 'YYYY-MM-DD HH24:MI:SS TZH:TZM') AS date_time_to_string",
write={
"bigquery": "SELECT CAST(CAST('2008-12-25 00:00:00+00:00' AS TIMESTAMP) AS STRING FORMAT 'YYYY-MM-DD HH24:MI:SS TZH:TZM') AS date_time_to_string",
@@ -191,7 +201,7 @@ class TestBigQuery(Validator):
self.validate_all(
"r'x\\''",
write={
- "bigquery": "r'x\\''",
+ "bigquery": "'x\\''",
"hive": "'x\\''",
},
)
@@ -199,7 +209,7 @@ class TestBigQuery(Validator):
self.validate_all(
"r'x\\y'",
write={
- "bigquery": "r'x\\y'",
+ "bigquery": "'x\\\y'",
"hive": "'x\\\\y'",
},
)
@@ -215,7 +225,7 @@ class TestBigQuery(Validator):
self.validate_all(
r'r"""/\*.*\*/"""',
write={
- "bigquery": r"r'/\*.*\*/'",
+ "bigquery": r"'/\\*.*\\*/'",
"duckdb": r"'/\\*.*\\*/'",
"presto": r"'/\\*.*\\*/'",
"hive": r"'/\\*.*\\*/'",
@@ -225,7 +235,7 @@ class TestBigQuery(Validator):
self.validate_all(
r'R"""/\*.*\*/"""',
write={
- "bigquery": r"r'/\*.*\*/'",
+ "bigquery": r"'/\\*.*\\*/'",
"duckdb": r"'/\\*.*\\*/'",
"presto": r"'/\\*.*\\*/'",
"hive": r"'/\\*.*\\*/'",
@@ -233,6 +243,20 @@ class TestBigQuery(Validator):
},
)
self.validate_all(
+ 'r"""a\n"""',
+ write={
+ "bigquery": "'a\\n'",
+ "duckdb": "'a\n'",
+ },
+ )
+ self.validate_all(
+ '"""a\n"""',
+ write={
+ "bigquery": "'a\\n'",
+ "duckdb": "'a\n'",
+ },
+ )
+ self.validate_all(
"CAST(a AS INT64)",
write={
"bigquery": "CAST(a AS INT64)",
@@ -603,7 +627,7 @@ class TestBigQuery(Validator):
)
@mock.patch("sqlglot.dialects.bigquery.logger")
- def test_pushdown_cte_column_names(self, mock_logger):
+ def test_pushdown_cte_column_names(self, logger):
with self.assertRaises(UnsupportedError):
transpile(
"WITH cte(foo) AS (SELECT * FROM tbl) SELECT foo FROM cte",