pederbe opened a new pull request, #26927: URL: https://github.com/apache/datafusion/pull/26927
## Which issue does this PR close? - Closes #26924. ## Rationale for this change A regex match with an escaped backslash in the pattern returns rows that have no backslash. For example, `room ~ '\\Kitchen'` also matches `Kitchen` and `/Kitchen`. `regexp_like(room, '\\Kitchen')` is affected too, because it simplifies to `~`. This was first reported downstream in influxdata/influxdb#27087. The expression simplifier rewrites simple literal regex patterns to `LIKE`. It refused literals containing `%` or `_`, but copied `\` unchanged. `\` is the implicit escape character of `LIKE`, so `\\Kitchen` became `LIKE '%\Kitchen%'`, which means `%Kitchen%`. ## What changes are included in this PR? - `is_safe_for_like` now also rejects `\`. A literal with a backslash keeps the original regex match instead of being rewritten to `LIKE` or `ILIKE`. - A fully anchored, case-sensitive literal such as `^a\\b$` is still rewritten to `=`, because `=` has no wildcards or escapes. It now uses the literal as is, as the anchored alternation rewrite (`^(a|b)$`) already does. As a side effect, `^a%b$` and `^a_b$` are now also rewritten to `=`. ## What is the testing strategy for this PR? The new `predicates.slt` cases cover unanchored (`~` and `~*`), prefix, suffix, fully anchored, negated and alternation patterns with a backslash, and check `regexp_like` against `~`. Six of them return wrong rows without the fix. The unit tests in `test_simplify_regex` check which patterns are still rewritten. ## Are there any user-facing changes? Queries with a backslash in a regex literal now return correct results. These patterns are evaluated as regex instead of `LIKE`, unless they are fully anchored and case-sensitive. I used Claude Code to assist coding and testing. I personally reviewed all work and verified testing. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
