Skip to content

Expand LIKE simplification: cover NULL pattern/expression and constant - #13260

Merged
alamb merged 4 commits into
apache:mainfrom
findepi:findepi/expand-like-simplification-e96eca
Nov 8, 2024
Merged

Expand LIKE simplification: cover NULL pattern/expression and constant#13260
alamb merged 4 commits into
apache:mainfrom
findepi:findepi/expand-like-simplification-e96eca

Conversation

@findepi

@findepifindepi commented Nov 5, 2024

Copy link
Copy Markdown
Member

@github-actionsgithub-actionsBot added optimizer Optimizer rules sqllogictest SQL Logic Tests (.slt) labels Nov 5, 2024
@findepi
findepiforce-pushed the findepi/expand-like-simplification-e96eca branch from c6285bf to be26107CompareNovember 5, 2024 13:39
@findepi

Copy link
Copy Markdown
MemberAuthor

currently depends on #13259

@findepi

Copy link
Copy Markdown
MemberAuthor

CI is green, so ready to review
but this will conflict with @adriangb's #13061, because this changes code structure a little bit
conflict resolution will be trivial though.
@adriangb if you want, i can do this, adding your changes to this PR

@findepi

Copy link
Copy Markdown
MemberAuthor

seemed easy enough, done.

@findepi
findepiforce-pushed the findepi/expand-like-simplification-e96eca branch from 88d6df1 to 6c57af7CompareNovember 5, 2024 15:14
@adriangb

Copy link
Copy Markdown
Contributor

I’m happy with my changes being included in this PR :)

@findepi
findepi marked this pull request as draft November 5, 2024 15:21
@findepi

Copy link
Copy Markdown
MemberAuthor

draft - to be rebased after #13259 lands

still ready to review
cc @crepererum@goldmedal

@goldmedalgoldmedal left a comment

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.

Just roughly review now. Overall looks to me. I will check the test cases tomorrow.

Comment threaddatafusion/optimizer/Cargo.toml Outdated
@goldmedal

Copy link
Copy Markdown
Contributor

draft - to be rebased after #13259 lands

still ready to review cc @crepererum@goldmedal

#13259 has been merged. 👍

@findepi
findepiforce-pushed the findepi/expand-like-simplification-e96eca branch from e4eae46 to 520ad2bCompareNovember 6, 2024 07:31
@findepi
findepi marked this pull request as ready for review November 6, 2024 07:31
@findepi

Copy link
Copy Markdown
MemberAuthor

@goldmedal rebased, thanks!

@alambalamb left a comment

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 @findepi and @goldmedal

This looks like a great change to me except for the handling of %% which I am not sure about. Otherwise 👍

}

fn like(expr: Expr, pattern: &str) -> Expr {
fn like(expr: Expr, pattern: impl Into<Expr>) -> Expr {

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 we could use Expr::like https://docs.rs/datafusion/latest/datafusion/logical_expr/enum.Expr.html#method.like and similar here instead of these functions

This is likely left over from when the Expr API was less expressive

Comment threaddatafusion/sqllogictest/test_files/string/string_view.slt Outdated
@alambalamb changed the title Expand LIKE simplification Expand LIKE simplification: cover NULL pattern/expression and constantNov 6, 2024
Comment threaddatafusion/sqllogictest/test_files/string/string_view.slt Outdated
@crepererum

Copy link
Copy Markdown
Contributor

since there are already two reviewers on it, I'll gonna skip this PR. However if you need my input, ping me.

@alambalamb left a comment

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 @findepi and @goldmedal

I had some small testing suggestions but I think we can add that coverage as a follow on PR as well

Comment threaddatafusion/sqllogictest/test_files/string/string_query.slt.part Outdated
@findepi

Copy link
Copy Markdown
MemberAuthor

FYI, when testing LIKE patterns with potential escapes, beware of difference between sqllogictests and CLI when it comes to backslash (like implicit escape) -- #13286

Comment threaddatafusion/sqllogictest/test_files/string/string_query.slt.part Outdated
@alamb

alamb commented Nov 7, 2024

Copy link
Copy Markdown
Contributor

Looks like this branch has some conflicts now to resolve but then I think it will be ready to go

findepiand others added 2 commits November 8, 2024 15:57
- cover expression known not to be null
- cover NULL pattern
- cover repeated '%%' in pattern
@findepi

Copy link
Copy Markdown
MemberAuthor

The conflicts are because #13288 is now merged. Let me rebase.

@findepi
findepiforce-pushed the findepi/expand-like-simplification-e96eca branch from e05417a to 5a03823CompareNovember 8, 2024 14:58
@findepi

Copy link
Copy Markdown
MemberAuthor

(just rebased)

@findepi

Copy link
Copy Markdown
MemberAuthor

Applied comments and fixed handling of implicit escape.

@alambalamb left a comment

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.

🚀

@alamb

alamb commented Nov 8, 2024

Copy link
Copy Markdown
Contributor

Thanks @findepi@adriangb and @goldmedal for this PR and the reviews

@alamb
alamb merged commit 667b302 into apache:mainNov 8, 2024
@findepi
findepi deleted the findepi/expand-like-simplification-e96eca branch November 8, 2024 18:54
jayzhan211 pushed a commit to jayzhan211/datafusion that referenced this pull request Nov 12, 2024
…ant (apache#13260)
* Expand LIKE simplification
- cover expression known not to be null
- cover NULL pattern
- cover repeated '%%' in pattern
* Simplify `EXPR LIKE 'constant'` to `expr = 'constant'`
* Correctness and style fixes
* fix typo
---------
Co-authored-by: Adrian Garcia Badaracco <1755071+adriangb@users.noreply.github.com>
@alambalamb mentioned this pull request Nov 20, 2024
3 tasks
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

optimizerOptimizer rulessqllogictestSQL Logic Tests (.slt)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants

@findepi@adriangb@goldmedal@crepererum@alamb