Repository navigation
MySQL: Fix REGEXP and RLIKE parsing when pattern is NULL - #2791
slopgobblercobbler wants to merge 1 commit into
Conversation
|
Thank you for the contribution. The change may well be correct, but I am closing this PR under the DataFusion AI policy, which also applies to sqlparser-rs: https://datafusion.apache.org/contributor-guide/ai-policy.html#what-is-an-ai-dump-and-why-it-is-not-helpful Maintainer review time is the scarcest resource in this project. This account has recently opened many AI-generated PRs across many repositories. That suggests the changes aren't coming from someone who uses sqlparser-rs, and that no human will be around to discuss review feedback and maintain the code. Reviewing PRs like this costs us more time than it saves. If you do use sqlparser-rs and this fix matters to you, please pick the one change you care most about. Then open a focused PR with a short description in your own words, one you have reviewed and understand, and we'd be happy to help with review. |
Dialects: mysql, generic
Description
Fixes #2760.
In
Parser::parse_subexpr, when matching infix operators (NOT,IN,BETWEEN,LIKE,ILIKE,SIMILAR,REGEXP,RLIKE), the parser previously parsedKeyword::NULLeagerly into anullboolean before checking if aREGEXPorRLIKEoperator matched:When an expression contained
REGEXP NULLorRLIKE NULL(with or withoutNOT),self.parse_keyword(Keyword::REGEXP)(orRLIKE) consumed the operator token, placing the parser cursor directly atNULL. The subsequentself.parse_keyword(Keyword::NULL)call then consumed theNULLtoken under the assumption that it was part of aNOT NULLexpression.Consequently, when
Expr::RLikewent to parse itspatternoperand withself.parse_subexpr(Precedence::Like), theNULLtoken was already consumed:SELECT 'abc' REGEXP NULLfailed withParserError("Expected: an expression, found: EOF").SELECT a RLIKE NULL FROM tconsumedFROMas the pattern identifier.SELECT a NOT REGEXP NULL OR b FROM tconsumedORas the pattern identifier.This PR defers the
Keyword::NULLcheck so it is only evaluated when checking forNOT NULLin theelse if negated && !self.in_column_definition_state() && self.parse_keyword(Keyword::NULL)branch, ensuringREGEXPandRLIKEpattern expressions retain access toNULLliterals.Tests
parse_rlike_and_regexpintests/sqlparser_mysql.rswith:SELECT 'abc' REGEXP NULLSELECT a RLIKE NULL FROM tSELECT a NOT REGEXP NULL OR b FROM tSELECT a NOT RLIKE NULL FROM tExpr::RLikepattern containsValue(Null).cargo test --test sqlparser_mysql,cargo test --test sqlparser_common, andcargo test --liball pass.cargo fmt --checkandcargo clippy --all-targets -- -D warningspass with 0 warnings.