fix(databricks)!: transpile TRY_DIVIDE to/from other dialects [CLAUDE]#7489
Merged
georgesittas merged 1 commit intotobymao:mainfrom Apr 14, 2026
Merged
Conversation
c444b88 to
4934a87
Compare
geooo109
reviewed
Apr 14, 2026
0cfe5c2 to
b9b2cb9
Compare
Databricks' TRY_DIVIDE(a, b) returns NULL on division by zero. It is now mapped to exp.SafeDivide, which already has the correct semantics and generates appropriate SQL for all target dialects. Closes tobymao#7312
b9b2cb9 to
2b37400
Compare
Contributor
Author
|
@geooo109 handled the comments, please take another look |
georgesittas
approved these changes
Apr 14, 2026
Collaborator
georgesittas
left a comment
There was a problem hiding this comment.
Thanks for the contribution, @baruchoxman.
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.
Summary
Databricks'
TRY_DIVIDE(a, b)returnsNULLwhen the divisor is0(instead of raising an error). Previously it was left asexp.Anonymous, so it passed through untranspiled.TRY_DIVIDEalso exists in Spark (https://spark.apache.org/docs/latest/api/sql/index.html#try_divide), so this fix places the parsing and generation logic in the Spark dialect — Databricks inherits it automatically.The fix maps
TRY_DIVIDEto the existingexp.SafeDivide, which already encodes the exact same semantics. The base generator'ssafedivide_sqlthen handles transpilation to all target dialects correctly.Changes:
parsers/spark.py: parseTRY_DIVIDE(a, b)→exp.SafeDivide.from_arg_list(alongsideTRY_ADD,TRY_MULTIPLY,TRY_SUBTRACT)generators/spark.py: emit nativeTRY_DIVIDEwhen targeting Spark/DatabricksTranspilation examples:
TRY_DIVIDE(a, b)IFF(b <> 0, a / b, NULL)CASE WHEN b <> 0 THEN a / b ELSE NULL ENDFixes #7312
Test plan
test_try_divideintests/dialects/test_spark.py— verifies parsing from bothsparkanddatabricksand cross-dialect transpilation