lonless9 opened a new issue, #27120:
URL: https://github.com/apache/datafusion/issues/27120

   ### Describe the bug
   
   A regex matching a literal backslash is rewritten to a LIKE pattern with 
different escaping semantics, producing both false positives and false 
negatives.
   
   Reproduced in 55.2.0 and 56.0.0-dev (1635ed947).
   
   ### To Reproduce
   
   Create regex.csv:
   
   ```csv
   id,s,p
   1,a\b,a\\b
   2,ab,a\\b
   ```
   
   Run:
   
   ```sql
   CREATE EXTERNAL TABLE regex_input (
    id BIGINT, s VARCHAR, p VARCHAR
   )
   STORED AS CSV LOCATION 'regex.csv'
   OPTIONS ('has_header' 'true');
   
   SELECT
    id,
    s ~ ('a' || chr(92) || chr(92) || 'b') AS constant_pattern,
    s ~ p AS dynamic_pattern
   FROM regex_input
   ORDER BY id;
   ```
   Expected:
   
   ```text
   id | constant_pattern | dynamic_pattern
   1  | true             | true
   2  | false            | false
   ```
   
   Actual:
   
   ```text
   id | constant_pattern | dynamic_pattern
   1  | false            | true
   2  | true             | false
   ```
   
   The constant pattern is optimized into LIKE '%a\b%', where the backslash is 
consumed as a LIKE escape. The dynamic pattern retains the correct regex 
behavior.
   
   ### Expected behavior
   
   _No response_
   
   ### Additional context
   
   _No response_
   
   ### Willingness to contribute
   
   None


-- 
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]

Reply via email to