Skip to content

binary expression should simplify when either operant is null - #1257

Closed
jimexist wants to merge 1 commit into
apache:masterfrom
jimexist:binary-null
Closed

jimexist wants to merge 1 commit into
apache:masterfrom
jimexist:binary-null

Conversation

@jimexist

@jimexist jimexist commented Nov 6, 2021

Copy link
Copy Markdown
Member

Which issue does this PR close?

Closes #.

Rationale for this change

binary expression should simplify when either operant is null

What changes are included in this PR?

Are there any user-facing changes?

@houqp houqp added the bug Something isn't working label Nov 6, 2021
houqp
houqp previously approved these changes Nov 6, 2021

fn simplify(expr: &Expr) -> Expr {
match expr {
Expr::BinaryExpr { left, .. } if is_literal_null(left) => *left.clone(),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @jimexist

I don't think this is true for Operator::IsDistinctFrom and Operator::IsNotDistinctFrom , Operator::And and Operator::Or, so I think we should special case those Operators

Or perhaps to be more conservative make a whitelist of the arithmetic operators.

https://github.com/apache/arrow-datafusion/blob/81fae230b81b97e93bbb95b284cfda6f4d59552e/datafusion/src/logical_plan/operators.rs#L56-L58

examples

null IS DISTINCT FROM null --> false (but this PR would rewrite to null I think)

true OR null --> true (but this PR would rewrite it to null I think)

let expr =
binary_expr(lit(ScalarValue::Boolean(None)), Operator::And, lit(false));
let expr_eq = lit(false);
let expr_eq = null;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the original answer of false is correct. Here is the result in postgres:

alamb=# select null and false;
 ?column? 
----------
 f
(1 row)

alamb=# 

@houqp
houqp dismissed their stale review November 15, 2021 07:26

agree with issue pointed out by Andrew

@alamb

alamb commented Dec 29, 2021

Copy link
Copy Markdown
Contributor

I am trying to clean up the list of PRs to review in DataFusion so marking old ones as stale. Please let us know if you plan to work on this soon. Otherwise we will close it down and reopen it when the time is right.

@alamb alamb added the stale-pr label Dec 29, 2021
@alamb

alamb commented Jan 18, 2022

Copy link
Copy Markdown
Contributor

Closing stale PRs, please reopen if this was a mistake and you plan to keep working on this one

@alamb alamb closed this Jan 18, 2022
unkloud pushed a commit to unkloud/datafusion that referenced this pull request Mar 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants