Skip to content

Conversation

@alamb
Copy link
Contributor

@alamb alamb commented Jan 23, 2024

Which issue does this PR close?

Follow on to #8949

Rationale for this change

During review I noticed another test that would be good as well as a few places we could avoid a clone (see https://github.com/apache/arrow-datafusion/pull/8949/files#r1462605147 )

What changes are included in this PR?

  1. Add a test
  2. Avoid cloning exprs

Are these changes tested?

Yes, by existing tests

Are there any user-facing changes?

No

@github-actions github-actions bot added the optimizer Optimizer rules label Jan 23, 2024
@alamb alamb changed the title Alamb/inlist simplify Improve InListSImplifier -- add test, commend and avoid clones Jan 23, 2024
if l1.expr == l2.expr && l1.negated && l2.negated {
return inlist_intersection(l1, l2, true);
}
if let Expr::BinaryExpr(BinaryExpr { left, op, right }) = expr {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This pattern allows getting an owned left and right and avoiding the clone

Ok(Expr::InList(merged_inlist))
/// Return the union of two inlist expressions
/// maintaining the order of the elements in the two lists
fn inlist_union(mut l1: InList, l2: InList, negated: bool) -> Result<Expr> {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

These functions now take owned InList and modify l1 in place

@alamb
Copy link
Contributor Author

alamb commented Jan 23, 2024

Clippy failure is due to #8972

@alamb
Copy link
Contributor Author

alamb commented Jan 31, 2024

@waynexia do you possibly have time to review this PR?

Copy link
Member

@waynexia waynexia left a comment

Choose a reason for hiding this comment

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

LGTM 👍 These changes are great @alamb

);
assert_eq!(simplify(expr.clone()), lit(true));

// 3.5 c1 NOT IN (1, 2, 3, 4) OR c1 NOT IN (4, 5, 6, 7) -> c1 != 4 (4 overlaps)
Copy link
Member

Choose a reason for hiding this comment

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

💯 This case shocks me (again) on how powerful this rule is

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jayzhan211 gets all the credit for implementing it in #8949 (🏆)

@alamb
Copy link
Contributor Author

alamb commented Feb 2, 2024

Thank you for the review @waynexia 🙏

@alamb alamb merged commit f203d86 into apache:main Feb 2, 2024
@alamb alamb deleted the alamb/inlist_simplify branch February 2, 2024 14:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

optimizer Optimizer rules

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants