Skip to content

Implement lazy evaluation for nvl2 #17983

Closed

Description

@alamb

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:

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 #17813 (comment)

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

  1. self-assigned this
    on Oct 15, 2025
  2. pepijnve commented on Oct 17, 2025

    @pepijnve
    Contributor

    Some more detail regarding my comment here #18127 (comment)

    nvl2 will require a slightly different implementation than what was done in #17991. nvl could be implemented as a kind of alias for coalesce with a fixed signature rather than a variadic one.
    For nvl2 it will probably be required to implement a simplification rule similar to the one from coalesce at https://github.com/apache/datafusion/blob/main/datafusion/functions/src/core/coalesce.rs#L97

  3. added a commit that references this issue on Oct 24, 2025
    22c4214
  4. added a commit that references this issue on Nov 2, 2025
    19090f4
  5. alamb commented on Nov 9, 2025

    @alamb
    ContributorAuthor

    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):

  6. added a commit that references this issue on Nov 24, 2025
    5cfbc6a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions