-
Notifications
You must be signed in to change notification settings - Fork 1.7k
#17982 Make nvl
a thin wrapper for coalesce
#17991
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
Conversation
PR #17997 is an alternative implementation for lazy argument evaluation along with an implementation for |
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.
Thanks @pepijnve I think it makes a lot of sense.
Couple of thoughts though: NVL
is a specific case of COALESCE
with 2 args, however NVL should not be short circuited like COALESCE.
Short circuit looks a nice feature for me to avoid side effects, thus it is more safe to use.
Major engines btw doesn't support NVL, preferring COALESCE.
I check Spark which supports NVL but they also use safer version with short circuit
The only thing the plan maybe confusing perhaps we can document it
The issue this PR is intended to solve requests lazy argument evaluation (i.e. short circuiting). The implementation across engines varies it seems. See #17982 (comment) If we want to stick to eager evaluation for nvl, then we should probably reject the #17982. Regarding the plan change, the alternative in #17997 avoids the plan change by letting the |
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.
Which issue does this PR close?
nvl
#17982Rationale for this change
By making
NVLFunc
a wrapper forCoalesceFunc
with a more restrictive signature the implementation automatically benefits from any optimisation work related tocoalesce
.What changes are included in this PR?
NVLFunc
a thin wrapper ofCoalesceFunc
. This seemed like the simplest way to reuse the coalesce logic, but keep the stricter signature ofnvl
.ScalarUDF::conditional_arguments
as a more precise complement toScalarUDF::short_circuits
. By letting each function expose which arguments are eager and which are lazy, we provide more precise information to the optimizer which may enable better optimisation.Are these changes tested?
Assumed to be covered by sql logic tests.
Unit tests for the custom implementation were removed since those are no longer relevant.
Are there any user-facing changes?
The rewriting of
nvl
tocase when ... then ... else ... end
is visible in the physical query plan.