-
Notifications
You must be signed in to change notification settings - Fork 1k
feat(duckdb)!: Handle WEEK, WEEK(day), ISOWEEK transpilation for DATE_DIFF & other Date/Time functions #6354
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
Conversation
9996310 to
bd2097a
Compare
ea1b9b4 to
592107b
Compare
georgesittas
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.
Looks good, left a few more comments.
592107b to
17a5b7a
Compare
georgesittas
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.
@fivetran-amrutabhimsenayachit can you add a test that covers the plain WEEK unit, demonstrating how it fixes the issue present in the main branch right now?
So basically, we want to have a test that covers the case where today's transpilation produces different results (e.g. 1 in bigquery, 0 in duckdb or something), and use that as a reference for how this PR fixes it.
@georgesittas , this is a good way to demonstrate the actual difference. |
… adhere to ISO day numbering conventions
17a5b7a to
47360b6
Compare
|
Discussed offline, I'll try to take this to the finish line. Will go ahead and close this PR while I work on it to not confuse the context. This is a very tricky transpilation, thank you for your work thus far @fivetran-amrutabhimsenayachit! |
Issue:
BigQuery's DATE_DIFF with WEEK uses Sunday-start (US convention), while ISOWEEK uses Monday-start (ISO standard). DuckDB only supports 'week' with Monday-start semantics. Direct transpilation produces incorrect results because they count different boundaries.
Before :
After:
Logic:
DATE_TRUNCapproachEdge Cases:
In BigQuery: Saturday -> Sunday crosses week boundary = 1 week
Without fix: DuckDB treats as Monday-start weeks = 0 weeks (both in same week)
With fix: DuckDB = 1 week