feat: simplify regex wildcard pattern#15299
Merged
waynexia merged 6 commits intoapache:mainfrom Mar 21, 2025
Merged
Conversation
Signed-off-by: Ruihang Xia <[email protected]>
jayzhan211
reviewed
Mar 19, 2025
|
|
||
| if let Expr::Literal(ScalarValue::Utf8(Some(pattern))) = right.as_ref() { | ||
| // Handle the special case for ".*" pattern | ||
| if pattern == ".*" { |
Contributor
There was a problem hiding this comment.
We can make this a const similar to COUNT_STAR_EXPANSION
Signed-off-by: Ruihang Xia <[email protected]>
Signed-off-by: Ruihang Xia <[email protected]>
Signed-off-by: Ruihang Xia <[email protected]>
alamb
reviewed
Mar 19, 2025
| right: empty_lit, | ||
| }) | ||
| } else { | ||
| // always true |
Contributor
There was a problem hiding this comment.
I think this needs to handle nulls too as null ~ '.*' is not true (it is null)
> create or replace table foo(x varchar) as values (1), (2), (null);
0 row(s) fetched.
Elapsed 0.004 seconds.
> select x ~ '.*' from foo;
+--------------------+
| foo.x ~ Utf8(".*") |
+--------------------+
| true |
| true |
| NULL |
+--------------------+
3 row(s) fetched.
Elapsed 0.016 seconds.So maybe instead of lit(true) it is x.is_not_null() 🤔
Member
Author
There was a problem hiding this comment.
Good catch! I added two cases about null in simplify_expr.slt, it should work as expected now.
Signed-off-by: Ruihang Xia <[email protected]>
jayzhan211
reviewed
Mar 20, 2025
| @@ -910,8 +910,8 @@ SELECT * FROM (SELECT y FROM u1 UNION ALL SELECT y FROM u2) ORDER BY y; | |||
| query I | |||
| SELECT * FROM v1; | |||
Contributor
There was a problem hiding this comment.
If this result is not deterministic, we need rowsort for it
Signed-off-by: Ruihang Xia <[email protected]>
Member
Author
|
Thank you for reviewing @jayzhan211 @alamb ❤️ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Which issue does this PR close?
Rationale for this change
Simplify dump regex cases like
~ '.*'or!~ '.*'.What changes are included in this PR?
Handle special wildcard regex pattern in expr_simplifier rule
Are these changes tested?
Yes, via sqllogictests and unit tests
Are there any user-facing changes?
no