Skip to content

Implement expression simplification for filtering (vs generically) #6179

@alamb

Description

@alamb

Is your feature request related to a problem or challenge?

When simplifying expressions in general, care must be taken with nulls. For example it seems like this expression can be simplified to false:

A AND !A

however, if A is null then the expression actually evaluates to null and not false

The existing simplification code handles these cases by checking is_nullable:

https://github.com/apache/arrow-datafusion/blob/71efcf5ee8900a1efe12fb812e210e6941060733/datafusion/optimizer/src/simplify_expressions/expr_simplifier.rs#L575-L582

However, if we are using A AND !A as a filter, we can actually simplify the whole thing to false because for filtering:

  • true --> row is kept
  • false --> row is not kept
  • null --> row is not kept (same as false)

Describe the solution you'd like

I would like someone to figure out how to take advantage of the above observation to apply more simplification rules when simplifying predicates

Describe alternatives you've considered

No response

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions