From fd0fc971393eaa9a61f48aead04eeea11d74c897 Mon Sep 17 00:00:00 2001 From: tobymao Date: Wed, 14 Jun 2023 19:39:24 -0700 Subject: [PATCH] Fix: bigquery timestamp -> timestamptz --- sqlglot/dialects/bigquery.py | 2 ++ tests/dialects/test_bigquery.py | 1 + 2 files changed, 3 insertions(+) diff --git a/sqlglot/dialects/bigquery.py b/sqlglot/dialects/bigquery.py index a550babc90..2166e65ea5 100644 --- a/sqlglot/dialects/bigquery.py +++ b/sqlglot/dialects/bigquery.py @@ -153,6 +153,7 @@ class Tokenizer(tokens.Tokenizer): "FLOAT64": TokenType.DOUBLE, "INT64": TokenType.BIGINT, "RECORD": TokenType.STRUCT, + "TIMESTAMP": TokenType.TIMESTAMPTZ, "NOT DETERMINISTIC": TokenType.VOLATILE, "UNKNOWN": TokenType.NULL, } @@ -340,6 +341,7 @@ class Generator(generator.Generator): exp.DataType.Type.NVARCHAR: "STRING", exp.DataType.Type.SMALLINT: "INT64", exp.DataType.Type.TEXT: "STRING", + exp.DataType.Type.TIMESTAMP: "DATETIME", exp.DataType.Type.TIMESTAMPTZ: "TIMESTAMP", exp.DataType.Type.TIMESTAMPLTZ: "TIMESTAMP", exp.DataType.Type.TINYINT: "INT64", diff --git a/tests/dialects/test_bigquery.py b/tests/dialects/test_bigquery.py index 67c38b6a6f..1c8aa51ffd 100644 --- a/tests/dialects/test_bigquery.py +++ b/tests/dialects/test_bigquery.py @@ -74,6 +74,7 @@ def test_bigquery(self): "SELECT * FROM `my-project.my-dataset.my-table`", write={"bigquery": "SELECT * FROM `my-project`.`my-dataset`.`my-table`"}, ) + self.validate_all("CAST(x AS DATETIME)", read={"": "x::timestamp"}) self.validate_identity("CAST(x AS TIMESTAMP)") self.validate_all("LEAST(x, y)", read={"sqlite": "MIN(x, y)"}) self.validate_all("CAST(x AS CHAR)", write={"bigquery": "CAST(x AS STRING)"})