Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make IN expr work with multiple items #7449

Merged
merged 3 commits into from
Sep 6, 2023
Merged

Conversation

sarutak
Copy link
Member

@sarutak sarutak commented Aug 30, 2023

Which issue does this PR close?

Closes #7448

Rationale for this change

The failure cases shown in #7448 are apparently valid. So this PR is for bug fix.

What changes are included in this PR?

The cause of the issue is that in_expr doesn't consider the case where the evaluated value of each expr in a list varies per row.
So the issue happens in such a case except for the case IN expr is simplified by the optimizer.
The fix is to care such a case and search the target value from the list sequentially per the given RecordBatch.

Are there any user-facing changes?

Yes. But it's a bug fix.

@github-actions github-actions bot added physical-expr Physical Expressions sqllogictest SQL Logic Tests (.slt) labels Aug 30, 2023
@jonahgao
Copy link
Member

jonahgao commented Sep 6, 2023

LGTM 👍.

Copy link
Contributor

@alamb alamb left a comment

Choose a reason for hiding this comment

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

This looks very nice to me -- well done @sarutak and thank you for the contribution

let list = evaluate_list(&self.list, batch)?;
make_set(list.as_ref())?.contains(value.as_ref(), self.negated)?
let value = value.into_array(batch.num_rows());
let found = self.list.iter().map(|expr| expr.evaluate(batch)).try_fold(
Copy link
Contributor

Choose a reason for hiding this comment

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

this is a very nice formulation

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks!

@alamb alamb merged commit dfd6851 into apache:main Sep 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
physical-expr Physical Expressions sqllogictest SQL Logic Tests (.slt)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

IN expr doesn't work with multiple items under some conditions
3 participants