Skip to content

Commit a0db070

Browse files
Expression: Fix for when multiple and/or expressions are specified via row filter string
1 parent 88cfe6d commit a0db070

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

pyiceberg/expressions/parser.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,10 +233,14 @@ def handle_not(result: ParseResults) -> Not:
233233

234234

235235
def handle_and(result: ParseResults) -> And:
236+
if len(result[0]) > 2:
237+
return And(result[0][0], result[0][1], *result[0][2:])
236238
return And(result[0][0], result[0][1])
237239

238240

239241
def handle_or(result: ParseResults) -> Or:
242+
if len(result[0]) > 2:
243+
return Or(result[0][0], result[0][1], *result[0][2:])
240244
return Or(result[0][0], result[0][1])
241245

242246

tests/expressions/test_parser.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,14 @@ def test_and_or_with_parens() -> None:
160160
)
161161

162162

163+
def test_multiple_and_or() -> None:
164+
assert And(EqualTo("foo", 1), EqualTo("bar", 2), EqualTo("baz", 3)) == parser.parse("foo = 1 and bar = 2 and baz = 3")
165+
assert Or(EqualTo("foo", 1), EqualTo("foo", 2), EqualTo("foo", 3)) == parser.parse("foo = 1 or foo = 2 or foo = 3")
166+
assert Or(
167+
And(NotNull("foo"), LessThan("foo", 5)), And(GreaterThan("foo", 10), LessThan("foo", 100), IsNull("bar"))
168+
) == parser.parse("foo is not null and foo < 5 or (foo > 10 and foo < 100 and bar is null)")
169+
170+
163171
def test_starts_with() -> None:
164172
assert StartsWith("foo", "data") == parser.parse("foo LIKE 'data'")
165173

0 commit comments

Comments
 (0)