-
Notifications
You must be signed in to change notification settings - Fork 1.2k
feat(duckdb): Add transpilation support for BOOLEAN and TEXT cases of TRY_CAST function #7681
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4326,6 +4326,26 @@ def round_sql(self, expression: exp.Round) -> str: | |
|
|
||
| return self.func(func, this, decimals, truncate) | ||
|
|
||
| def trycast_sql(self, expression: exp.TryCast) -> str: | ||
| 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. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit (style): let's split these across three lines, we don't use the multi-assignment syntax as much. |
||
|
|
||
| if to_type == exp.DType.BOOLEAN: | ||
| return _to_boolean_sql(self, exp.ToBoolean(this=src.copy(), safe=True)) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why are we copying? |
||
| 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()) | ||
| ) | ||
|
Comment on lines
+4337
to
+4345
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This messes up DuckDB's roundtrip, right? This behavior needs to be controlled with a new arg in |
||
|
|
||
| return super().trycast_sql(expression) | ||
|
|
||
| def strtok_sql(self, expression: exp.Strtok) -> str: | ||
| string_arg = expression.this | ||
| delimiter_arg = expression.args.get("delimiter") | ||
|
|
||
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.
This is unnecessary and irrelevant to DuckDB, it's only used for Snowflake roundtrip.