Skip to content

Commit

Permalink
feat(snowflake): Transpile BQ's TIMESTAMP() function (#4309)
Browse files Browse the repository at this point in the history
  • Loading branch information
VaggelisD authored Oct 30, 2024
1 parent b4ea602 commit 2af4936
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 7 deletions.
1 change: 1 addition & 0 deletions sqlglot/dialects/presto.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,7 @@ class Generator(generator.Generator):
exp.DataType.Type.STRUCT: "ROW",
exp.DataType.Type.TEXT: "VARCHAR",
exp.DataType.Type.TIMESTAMPTZ: "TIMESTAMP",
exp.DataType.Type.TIMESTAMPNTZ: "TIMESTAMP",
exp.DataType.Type.TIMETZ: "TIME",
}

Expand Down
2 changes: 2 additions & 0 deletions sqlglot/dialects/snowflake.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
var_map_sql,
map_date_part,
no_safe_divide_sql,
no_timestamp_sql,
)
from sqlglot.helper import flatten, is_float, is_int, seq_get
from sqlglot.tokens import TokenType
Expand Down Expand Up @@ -840,6 +841,7 @@ class Generator(generator.Generator):
),
exp.Stuff: rename_func("INSERT"),
exp.TimeAdd: date_delta_sql("TIMEADD"),
exp.Timestamp: no_timestamp_sql,
exp.TimestampDiff: lambda self, e: self.func(
"TIMESTAMPDIFF", e.unit, e.expression, e.this
),
Expand Down
9 changes: 9 additions & 0 deletions tests/dialects/test_bigquery.py
Original file line number Diff line number Diff line change
Expand Up @@ -371,9 +371,18 @@ def test_bigquery(self):
write={
"bigquery": "TIMESTAMP(x)",
"duckdb": "CAST(x AS TIMESTAMPTZ)",
"snowflake": "CAST(x AS TIMESTAMPTZ)",
"presto": "CAST(x AS TIMESTAMP WITH TIME ZONE)",
},
)
self.validate_all(
"SELECT TIMESTAMP('2008-12-25 15:30:00', 'America/Los_Angeles')",
write={
"bigquery": "SELECT TIMESTAMP('2008-12-25 15:30:00', 'America/Los_Angeles')",
"duckdb": "SELECT CAST('2008-12-25 15:30:00' AS TIMESTAMP) AT TIME ZONE 'America/Los_Angeles'",
"snowflake": "SELECT CONVERT_TIMEZONE('America/Los_Angeles', CAST('2008-12-25 15:30:00' AS TIMESTAMP))",
},
)
self.validate_all(
"SELECT SUM(x IGNORE NULLS) AS x",
read={
Expand Down
7 changes: 0 additions & 7 deletions tests/dialects/test_presto.py
Original file line number Diff line number Diff line change
Expand Up @@ -414,13 +414,6 @@ def test_time(self):
"CAST(x AS TIMESTAMP)",
read={"mysql": "TIMESTAMP(x)"},
)
self.validate_all(
"TIMESTAMP(x, 'America/Los_Angeles')",
write={
"duckdb": "CAST(x AS TIMESTAMP) AT TIME ZONE 'America/Los_Angeles'",
"presto": "AT_TIMEZONE(CAST(x AS TIMESTAMP), 'America/Los_Angeles')",
},
)
# this case isn't really correct, but it's a fall back for mysql's version
self.validate_all(
"TIMESTAMP(x, '12:00:00')",
Expand Down

0 comments on commit 2af4936

Please sign in to comment.