Repository navigation
SQLite: Group LIKE, GLOB, MATCH and REGEXP with = - #3070
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #3070 +/- ##
=======================================
Coverage 83.64% 83.64%
=======================================
Files 42 42
Lines 35833 35833
Branches 35833 35833
=======================================
Hits 29974 29974
Misses 2418 2418
Partials 3441 3441 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
c35201a to
b2f9fa5
Compare
There was a problem hiding this comment.
sent my concerns in private and luca fixed them, lgtm.
for documentation sake, my concerns were:
1. A trailing ESCAPE after a regrouped pattern becomes a column alias. Once LIKE stops before = or IN, the LIKE parser never sees the trailing ESCAPE, so it falls through to SQLiteDialect::is_column_alias, which accepts it:
SELECT 'a' LIKE 'b' = 0 ESCAPE -- main: parse error; this PR: alias "ESCAPE"
SELECT 'a' LIKE 'b' IN (0) ESCAPE -- samesqlite3 rejects both with near "ESCAPE": syntax error. Accepting ESCAPE as an alias is older (item 7); this PR makes it reachable after a pattern. Adding Keyword::ESCAPE to the reject list in is_column_alias should fix both while keeping AS "ESCAPE" working.
2. A few groupings this PR changes aren't pinned by the matrix. On main, each of these parses with the trailing operator folded into the pattern; here they group left:
a LIKE b IN (c)a LIKE b BETWEEN c AND da NOT REGEXP b = c(NOT REGEXPbuildsExpr::RLikethrough the genericNOTpath, not the SQLiteREGEXPhook)a NOT LIKE b ESCAPE c <> d
The test below also asserts the mirrored a = b NOT REGEXP c as a control; it groups as (a = b) NOT REGEXP c on main too.
|
Thanks @zommiommy for the review, I will be merging this now, and later #@3043 after most likely rebasing it. cc @alamb |
Under
SQLiteDialect,a GLOB 'p' = 1parsed asa GLOB ('p' = 1). SQLite's grammar putsLIKE,GLOB,MATCHandREGEXPon the same left-associative level as=and<>(parse.y,%left IS MATCH LIKE_KW BETWEEN IN ISNULL NOTNULL NE EQ), andsqlite3returns 1 forSELECT 'a' GLOB 'a' = 1, which only the left-grouped reading gives. This came up in review on #3043 (comment).The dialect ranked
Precedence::Likeone step belowPrecedence::Eq, so the pattern operand absorbed a following=,<>,BETWEENorIN. MovingPrecedence::Liketo the level ofPrecedence::EqinSQLiteDialect::prec_valueregroups every operator that takes its level from that lookup, theNOTforms and theESCAPEoperand included. Other dialects keep their own tables.