-
Notifications
You must be signed in to change notification settings - Fork 1k
feat(snowflake)!: Transpilation of TO_BINARY from snowflake to duckdb #6504
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
Merged
Conversation
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
toriwei
reviewed
Dec 8, 2025
geooo109
reviewed
Dec 9, 2025
georgesittas
reviewed
Dec 9, 2025
geooo109
reviewed
Dec 9, 2025
georgesittas
approved these changes
Dec 10, 2025
Collaborator
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.
Nice
georgesittas
added a commit
that referenced
this pull request
Dec 10, 2025
…#6504) * support TO_BINARY transpilation from snowflake to duckdb * add default format for snowflake * fix tests * address comments * small fix * use type inference for transpilation * small update * Remove unnecessary `FUNCTIONS` entry. --------- Co-authored-by: Jo <[email protected]>
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.
https://docs.snowflake.com/en/sql-reference/functions/to_binary
In Snowflake, TO_BINARY takes an input string with an optional format argument (like 'BASE64'), reads this string according to the format (default is HEX), and converts it to binary. But in DuckDB, the TO_BINARY function takes a UTF-8 string coverts it to binary but returns it as string (like '0101').
So we need to take care of the input format and the return type.
if the return_type is BINARY (like snowflake):
(Snowflake -> DuckDB)
- TO_BINARY('48454C50', 'HEX') → UNHEX('48454C50')
- TO_BINARY('TEST', 'UTF-8') → ENCODE('TEST')
- TO_BINARY('SEVMUA==', 'BASE64') → FROM_BASE64('SEVMUA==')
If the return_type is VARCHAR (like DuckDB), we can use DuckDB's native TO_BINARY.
For this PR only transpilation from Snowflake to DuckDB is supported.