Skip to content

Add support for the LIKE ANY and ILIKE ANY pattern-matching condition #1456

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

Merged
merged 2 commits into from
Oct 4, 2024

Conversation

yoavcloud
Copy link
Contributor

Snowflake supports pattern matching over a list of patterns with the use of the case-sensitive LIKE ANY and case-insensitive ILIKE ANY functions. Added support for the ANY option in the Expr::Like and Expr::ILike variants.

@@ -2162,6 +2162,19 @@ fn test_select_wildcard_with_ilike_replace() {
);
}

#[test]
Copy link
Contributor

Choose a reason for hiding this comment

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

Since the syntax support was added for all dialects (I think seems reasonable), can we move the test to sqlparser_common.rs so that they run against all dialects?

expr: Box<Expr>,
pattern: Box<Expr>,
escape_char: Option<String>,
},
/// `ILIKE` (case-insensitive `LIKE`)
ILike {
negated: bool,
any: bool,
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we add a link to the snowflake doc where the syntax is mentioned? It would help with context for someone that comes across it in the codebase

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Addressed in the latest commit

Comment on lines 2737 to 2740
if self.parse_keyword(Keyword::ANY) {
self.prev_token();
return self.expected("pattern after RLIKE or REGEXP", self.peek_token());
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Ah not sure I followed this part, we don't seem to take any action for when parsing ANY is successful?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The only point of this condition was to add a meaningful error message when parsing incorrect syntax, for example: RLIKE ANY. See the last check of the unit test. Can be removed, I debated this one.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed in the latest commit.

@yoavcloud yoavcloud requested a review from iffyio October 4, 2024 13:52
Copy link
Contributor

@iffyio iffyio left a comment

Choose a reason for hiding this comment

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

LGTM! cc @alamb

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.

Thank you @yoavcloud and @iffyio

@alamb alamb merged commit e849f7f into apache:main Oct 4, 2024
10 checks passed
@coveralls
Copy link

Pull Request Test Coverage Report for Build 11180959841

Details

  • 14 of 14 (100.0%) changed or added relevant lines in 3 files are covered.
  • 10 unchanged lines in 2 files lost coverage.
  • Overall coverage increased (+0.004%) to 89.307%

Files with Coverage Reduction New Missed Lines %
src/ast/mod.rs 2 82.44%
tests/sqlparser_common.rs 8 89.58%
Totals Coverage Status
Change from base Build 11111316639: 0.004%
Covered Lines: 29951
Relevant Lines: 33537

💛 - Coveralls

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants