-
Notifications
You must be signed in to change notification settings - Fork 1k
feat(snowflake)!: updates for Snowflake to DuckDB transpilation of TO_TIMESTAMP functions #6622
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
SQLGlot Integration Test ResultsComparing:
By Dialect
Overallmain: 6173 total, 5610 passed (pass rate: 90.9%), sqlglot version: sqlglot:feature/transpile-to_timestamp: 6173 total, 5612 passed (pass rate: 90.9%), sqlglot version: Difference: No change |
VaggelisD
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work @fivetran-kwoodbeck! Leaving a few comments from my first pass:
f1331df to
cc79016
Compare
This fixes a variety of issues in transpilation of Snowflake's
TO_TIMESTAMPandTRY_TO_TIMESTAMPfamily of functions to DuckDB, fixing several edge cases and adding support for missing variants.Snowflake Parser (
snowflake.py)TO_TIMESTAMP('20240115103045', 'YYYYMMDDHH24MISS')was incorrectly parsed as unix timestamp instead of using the format stringexp.Neghandling soTO_TIMESTAMP(-86400)parses correctlyAM/PM→%pin TIME_MAPPING for 12-hour time parsingDuckDB Generator (
duckdb.py)TO_TIMESTAMP(n)returns TIMESTAMPTZ, but Snowflake's returns TIMESTAMP (NTZ interpreted as UTC). Now usesAT TIME ZONE 'UTC'to extract UTC time as naive timestampstrtotime_sqlnow casts to TIMESTAMPTZ for LTZ/TZ variants (both TRY and non-TRY)Expressions (
expressions.py)target_typetoUnixToTime.arg_typesto track desired output typeTest Queries
Note: See the Jira ticket for the full suite of tests.
TO_TIMESTAMP(1704067200)TO_TIMESTAMP(1704067200) AT TIME ZONE 'UTC'TO_TIMESTAMP('20240115', 'YYYYMMDD')STRPTIME('20240115', '%Y%m%d')TO_TIMESTAMP('10:30 PM', 'HH12:MI AM')STRPTIME('10:30 PM', '%I:%M %p')TRY_TO_TIMESTAMP_LTZ('2024-01-15')TRY_CAST('2024-01-15' AS TIMESTAMPTZ)TO_TIMESTAMP_LTZ('...', 'fmt')CAST(STRPTIME('...', '%fmt') AS TIMESTAMPTZ)