### Is your feature request related to a problem or challenge? DataFusion's `CASE` handling is quite optimized and handles many cases with constants, lazy evaluation, and more Recently, @chenkovsky fixed lazy evaluation for `coalesce` by rewriting it to use `CASE` in PR: - https://github.com/apache/datafusion/pull/17357 This both made the code faster and more correct ### Describe the solution you'd like We can do the same thing for the `nvl2` function, as suggested by @pepijnve in https://github.com/apache/datafusion/pull/17813#issuecomment-3372775137 https://github.com/apache/datafusion/blob/main/datafusion/functions/src/core/nvl2.rs ### Describe alternatives you've considered _No response_ ### Additional context _No response_
Activity
pepijnve commentedon Oct 17, 2025
Some more detail regarding my comment here #18127 (comment)
nvl2will require a slightly different implementation than what was done in #17991.nvlcould be implemented as a kind of alias forcoalescewith a fixed signature rather than a variadic one.For
nvl2it will probably be required to implement a simplification rule similar to the one fromcoalesceat https://github.com/apache/datafusion/blob/main/datafusion/functions/src/core/coalesce.rs#L97Refactor `nvl2` Function to Support Lazy Evaluation and Simplificatio…
Refactor `nvl2` Function to Support Lazy Evaluation and Simplificatio…
alamb commentedon Nov 9, 2025
We merged a fix for this in the 51 release, but we have found as subtle problem so I am planning to revert it for 51 (the fix should appear in 52):
nvlandnvl2simplification #18567Refactor `nvl2` Function to Support Lazy Evaluation and Simplificatio…