feat(duckdb): Add transpilation support for TRUNC date/time function in snowflake#6935
Closed
fivetran-amrutabhimsenayachit wants to merge 2 commits intomainfrom
Closed
feat(duckdb): Add transpilation support for TRUNC date/time function in snowflake#6935fivetran-amrutabhimsenayachit wants to merge 2 commits intomainfrom
fivetran-amrutabhimsenayachit wants to merge 2 commits intomainfrom
Conversation
- Handle TRUNC(NULL, 'YEAR') edge case by checking for explicit NULL - Handle TRUNC(timestamp, NULL) edge case for date/time types with NULL unit - Preserve ambiguous cases like TRUNC(col, 'YEAR') where type is unknown - Fixes integration test failures in DuckDB execution
c434ed4 to
90bb91c
Compare
Collaborator
|
As discussed offline, Amruta was working on the Snowflake aspect before #6923. Closing this in favor of the other PR as it attempts to solve all dialects at once. We can keep this as reference for now or if need be (1) merge the other PR and (2) reopen this one to address any additional Snowflake -> DuckDB shortcomings. |
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 TRUNC function is overloaded to handle both numeric truncation and date/time truncation. When transpiling from Snowflake to DuckDB, SQLGlot does not recognize TRUNC as a date/time operation and leaves it as-is. DuckDB's TRUNC function only supports numeric types, causing date/time queries to fail. The correct DuckDB function for date/time truncation is DATE_TRUNC, which also uses reversed parameter order.
To fix this, created a custom parser function that inspects the second argument as a string literal to determine if TRUNC is numeric or date/time.
Additional tests: