Skip to content

Commit

Permalink
fix(python): Handle boolean comparisons in Iceberg predicate pushdown
Browse files Browse the repository at this point in the history
Filtering columns on boolean literals failed trying to parse
`pa.compute.scalar(True)`. This updates the Call predicate parser to
handle the `scalar` type.
  • Loading branch information
dimfeld committed Aug 27, 2024
1 parent d12131a commit 69fc732
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
2 changes: 2 additions & 0 deletions py-polars/polars/io/iceberg.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,8 @@ def _(a: Call) -> Any:
f = _convert_predicate(a.func)
if f == "field":
return args
elif f == "scalar":
return args[0]
elif f in _temporal_conversions:
# convert from polars-native i64 to ISO8601 string
return _temporal_conversions[f](*args).isoformat()
Expand Down
9 changes: 9 additions & 0 deletions py-polars/tests/unit/io/test_iceberg.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,3 +163,12 @@ def test_parse_lteq(self) -> None:

expr = _to_ast("(pa.compute.field('ts') <= '2023-08-08')")
assert _convert_predicate(expr) == LessThanOrEqual("ts", "2023-08-08")

def test_compare_boolean(self) -> None:
from pyiceberg.expressions import EqualTo

expr = _to_ast("(pa.compute.field('ts') == pa.compute.scalar(True))")
assert _convert_predicate(expr) == EqualTo("ts", True)

expr = _to_ast("(pa.compute.field('ts') == pa.compute.scalar(False))")
assert _convert_predicate(expr) == EqualTo("ts", False)

0 comments on commit 69fc732

Please sign in to comment.