LemonCondor opened a new pull request, #4491:
URL: https://github.com/apache/iceberg-python/pull/4491

   <!--
   Thanks for opening a pull request!
   -->
   
   # Rationale for this change
   
   The row filter parser unescapes `\%` in LIKE patterns but not `\_`. An 
escaped underscore keeps its backslash in the literal:
   
   ```python
   from pyiceberg.expressions.parser import parse
   
   parse(r"name LIKE 'tmp\_%'")
   # StartsWith(term=Reference(name='name'), literal=literal('tmp\\_'))
   ```
   
   `\_` is the usual way to write a literal underscore in SQL LIKE patterns 
(Spark uses `\` as the default escape character), so filters copied from SQL 
match nothing:
   
   ```python
   table.append(pa.table({"name": ["tmp_1", "tmp_2", "prod_1"]}))
   
   table.scan(row_filter=r"name LIKE 'tmp\_%'").to_arrow()  # 0 rows, expected 
tmp_1 and tmp_2
   table.delete(r"name LIKE 'tmp\_%'")                       # deletes nothing
   ```
   
   This PR unescapes `\_` the same way as `\%`, for both the prefix 
(`StartsWith`) and the exact-match (`EqualTo`) forms. An unescaped `_` is still 
matched literally, as before.
   
   ## Are these changes tested?
   
   Yes. `test_like_escaped_underscore` in `tests/expressions/test_parser.py` 
covers `LIKE`, `LIKE ...%` and `NOT LIKE ...%`. It fails without the change and 
passes with it. The rest of `tests/expressions/test_parser.py` passes.
   
   ## Are there any user-facing changes?
   
   Yes. LIKE patterns containing `\_` now match a literal underscore instead of 
a backslash followed by an underscore.
   
   AI disclosure: this issue was found, and the change and test written, with 
an AI coding assistant (Claude).
   


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