Repository navigation
fix(duckdb): align Snowflake TIME_SLICE transpilation to epoch origin - #8899
Merged
Merged
Conversation
Contributor
SQLGlot Integration Test Results✅ All tests passedComparing:
By Dialect
Overallmain: 182929 total, 166022 passed (pass rate: 90.8%) sqlglot:fix/transpile-duckdb-time-slice: 182929 total, 166024 passed (pass rate: 90.8%) Transitions: ✅ All tests passed |
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The DuckDB TIME_SLICE change incorrectly converts DATE results to TIMESTAMP and misaligns buckets for StarRocks inputs and Snowflake’s lowercase 'w' alias.
3 open issues
What changed in this PR
This PR updates SQLGlot’s DuckDB generation for TIME_SLICE to match Snowflake’s epoch-based slice boundaries instead of DuckDB’s default origin.
Changes:
- Adds an explicit
1970-01-01origin, using1969-12-29for Monday-aligned weekly slices. - Preserves existing end-of-slice handling and DATE casts.
- Adds multi-day and multi-week regression cases and updates transpilation expectations.
| File | Description |
|---|---|
tests/dialects/test_starrocks.py |
Updates DuckDB expectations to include explicit origins. |
tests/dialects/test_snowflake.py |
Adds epoch-alignment cases and updates existing expectations. |
sqlglot/generators/duckdb.py |
Supplies typed origins when generating TIME_BUCKET. |
Review effort: Balanced
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.

Snowflake's
TIME_SLICEanchors slices to the1970-01-01epoch, but the DuckDB transpilation emittedTIME_BUCKETwith no origin, so DuckDB used its own default origin and returned the wrong slice for any multi-unit length.Added an explicit origin to
TIME_BUCKETas an extra argument fortimeslice_sql: