feat(duckdb): Add transpilation support for BOOLEAN and TEXT cases of TRY_CAST function#7681
Open
fivetran-amrutabhimsenayachit wants to merge 1 commit into
Open
feat(duckdb): Add transpilation support for BOOLEAN and TEXT cases of TRY_CAST function#7681fivetran-amrutabhimsenayachit wants to merge 1 commit into
fivetran-amrutabhimsenayachit wants to merge 1 commit into
Conversation
… TRY_CAST function
georgesittas
requested changes
May 27, 2026
Comment on lines
+4330
to
+4332
| if not expression.args.get("requires_string"): | ||
| return super().trycast_sql(expression) | ||
|
|
Collaborator
There was a problem hiding this comment.
This is unnecessary and irrelevant to DuckDB, it's only used for Snowflake roundtrip.
| if not expression.args.get("requires_string"): | ||
| return super().trycast_sql(expression) | ||
|
|
||
| src, to, to_type = expression.this, expression.to, expression.to.this |
Collaborator
There was a problem hiding this comment.
Nit (style): let's split these across three lines, we don't use the multi-assignment syntax as much.
| src, to, to_type = expression.this, expression.to, expression.to.this | ||
|
|
||
| if to_type == exp.DType.BOOLEAN: | ||
| return _to_boolean_sql(self, exp.ToBoolean(this=src.copy(), safe=True)) |
Comment on lines
+4337
to
+4345
| elif to_type in exp.DataType.TEXT_TYPES and to.expressions: | ||
| return self.sql( | ||
| exp.case() | ||
| .when( | ||
| exp.LTE(this=exp.func("LENGTH", src.copy()), expression=to.expressions[0].this), | ||
| exp.cast(src.copy(), "TEXT"), | ||
| ) | ||
| .else_(exp.Null()) | ||
| ) |
Collaborator
There was a problem hiding this comment.
This messes up DuckDB's roundtrip, right? This behavior needs to be controlled with a new arg in TryCast.
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.
PR#1
Refer #7672 for comments.
BOOLEAN: Snowflake's
TRY_CAST(x AS BOOLEAN)accepts'on'/'off'and returnsTRUE/FALSE, but DuckDB's nativeTRY_CAST(x AS BOOLEAN)returnsNULLfor those two values silently.TEXT(n): Snowflake's
TRY_CAST(x AS VARCHAR(n))returnsNULLif the string exceeds length n, but DuckDB's nativeTRY_CAST(x AS VARCHAR(n))silently ignores the length constraint and returns the full string.After fixing the above,
Boolean:
Text: