feat(snowflake)!: Transpile BQ's TIMESTAMP() function #4309
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
BigQuery supports
TIMESTAMP(<expr>[, zone])
function forTIMESTAMP
construction. Today, this is parsed in BQ and transpiled to other dialects (DuckDB, Presto/Trino) through theno_timestamp_sql
helper which generates either a cast (1-arg version) or anAT TIME ZONE
expression if azone
is present (2-arg version).However, the 2-arg version transpilation does not seem correct; BigQuery's
TIMESTAMP
s are always stored at UTC which is not the case for other dialects. In main branch, these are the transpilations & their results today:This PR:
exp.AtTimeZone
toexp.ConvertTimezone
, which will first evaluate the timestamp at the user-inputtedzone
and then convert it to UTCno_timestamp_sql
to Snowflake to enable the transpilation pathThe new transpilations and their results on this branch are the following:
Note that although DuckDB & Snowflake now match BQ's results, Presto/Trino are still off; The reason for that is that the first
AT_TIMEZONE
does a<session zone> -> <zone>
conversion instead of pushing thezone
into the timestamp which would allow for theUTC
conversion to work.Docs
BigQuery TIMESTAMP | Snowflake CONVERT_TIMEZONE