Skip to content

fix(duckdb): align Snowflake TIME_SLICE transpilation to epoch origin - #8899

Merged
georgesittas merged 2 commits into
mainfrom
fix/transpile-duckdb-time-slice
Nov 5, 2026
Merged

georgesittas merged 2 commits into
mainfrom
fix/transpile-duckdb-time-slice

Conversation

@fivetran-kwoodbeck

@fivetran-kwoodbeck fivetran-kwoodbeck commented Nov 4, 2026 •

Copy link
Copy Markdown
Collaborator

Snowflake's TIME_SLICE anchors slices to the 1970-01-01 epoch, but the DuckDB transpilation emitted TIME_BUCKET with 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_BUCKET as an extra argument for timeslice_sql:

unit origin note
all units 1970-01-01 Snowflake epoch alignment
WEEK 1969-12-29 Monday of the epoch week (WEEK_START=0)
-- Snowflake (source)
SELECT TIME_SLICE(CAST('2021-03-18' AS DATE), 8, 'DAY');  -- 2021-03-18

-- DuckDB (previous transpilation) -> 2021-03-17  (wrong)
SELECT TIME_BUCKET(INTERVAL 8 DAY, CAST('2021-03-18' AS DATE));

-- DuckDB (fixed transpilation) -> 2021-03-18  (correct)
SELECT TIME_BUCKET(INTERVAL 8 DAY, CAST('2021-03-18' AS DATE), CAST('1970-01-01' AS DATE));

@github-actions

github-actions Bot commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

SQLGlot Integration Test Results

✅ All tests passed

Comparing:

  • this branch (sqlglot:fix/transpile-duckdb-time-slice @ sqlglot 5a952df)
  • baseline (main @ sqlglot c177946)

By Dialect

dialect main feature branch transitions links
snowflake -> duckdb 1138/1857 passed (61.3%) 1140/1857 passed (61.4%) 2 fail -> pass full result / delta

Overall

main: 182929 total, 166022 passed (pass rate: 90.8%)

sqlglot:fix/transpile-duckdb-time-slice: 182929 total, 166024 passed (pass rate: 90.8%)

Transitions:
2 fail -> pass

✅ All tests passed

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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-01 origin, using 1969-12-29 for 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

Comment thread sqlglot/generators/duckdb.py Resolved
Comment thread sqlglot/generators/duckdb.py Resolved
Comment thread sqlglot/generators/duckdb.py Resolved
@georgesittas
georgesittas merged commit b33976b into main Nov 5, 2026
9 checks passed
@georgesittas
georgesittas deleted the fix/transpile-duckdb-time-slice branch November 5, 2026 13:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants