Fix GREATEST with single argument simplified in Databricks SQL output#2328
Open
moomindani wants to merge 1 commit intodatabrickslabs:mainfrom
Open
Fix GREATEST with single argument simplified in Databricks SQL output#2328moomindani wants to merge 1 commit intodatabrickslabs:mainfrom
moomindani wants to merge 1 commit intodatabrickslabs:mainfrom
Conversation
databrickslabs#2308) Spark SQL requires GREATEST to have more than one argument, but Oracle (and other dialects) allow a single-argument form as a no-op wrapper. Add a custom `_greatest_sql` transform in the Databricks generator that unwraps `GREATEST(expr)` → `expr` when only one argument is present, while keeping the normal `GREATEST(a, b, ...)` behaviour for multiple arguments. Add three oracle functional test cases covering single-column, single NVL expression, and multi-argument GREATEST to prevent regressions. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2328 +/- ##
==========================================
+ Coverage 66.41% 66.43% +0.01%
==========================================
Files 99 99
Lines 9094 9098 +4
Branches 974 975 +1
==========================================
+ Hits 6040 6044 +4
Misses 2878 2878
Partials 176 176 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
asnare
requested changes
Mar 10, 2026
Contributor
asnare
left a comment
There was a problem hiding this comment.
I'm afraid this PR doesn't address #2308 as intended: the reported issue reports a problem in the Switch transpiler/component, and that's not part of this repository.
The files that have been modified are part of a legacy transpiler that is not in use; it's currently dead code and scheduled for removal.
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
Fixes #2308
Spark SQL requires
GREATESTto have more than one argument:Oracle (and other dialects) allow
GREATEST(single_expr)as a redundant no-op wrapper. This PR adds a custom_greatest_sqltransform in lakebridge'sDatabricksgenerator that:GREATEST(expr)→exprGREATEST(a, b, ...)behaviour unchangedExample
GREATEST(NVL(col, TO_DATE('1000-01-01', 'YYYY-MM-DD')))GREATEST(COALESCE(col, TO_DATE('1000-01-01')))❌COALESCE(col, TO_DATE('1000-01-01'))✅GREATEST(col1)GREATEST(col1)❌col1✅GREATEST(a, b)GREATEST(a, b)✅GREATEST(a, b)✅Changes
src/databricks/labs/lakebridge/transpiler/sqlglot/generator/databricks.py: Add_greatest_sqlfunction and register it inTRANSFORMStests/resources/functional/oracle/functions/test_greatest_1.sql: Multi-arg GREATEST (no change)tests/resources/functional/oracle/functions/test_greatest_2.sql: Single-arg GREATEST with NVL → simplifiestests/resources/functional/oracle/functions/test_greatest_3.sql: Single-arg GREATEST with column → simplifiesTest plan
tests/unit/transpiler/test_oracle.py— all 4 cases pass (including 3 new)tests/unit/transpiler/test_snowflake.py::test_snowflake[test_greatest_1]— multi-arg case unchanged🤖 Generated with Claude Code