Skip to content

Commit

Permalink
Expression: Fix for when multiple and/or expressions are specified vi…
Browse files Browse the repository at this point in the history
…a row filter string
  • Loading branch information
amogh-jahagirdar committed Oct 13, 2023
1 parent 88cfe6d commit 4c2c1af
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
5 changes: 2 additions & 3 deletions pyiceberg/expressions/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,12 +233,11 @@ def handle_not(result: ParseResults) -> Not:


def handle_and(result: ParseResults) -> And:
return And(result[0][0], result[0][1])
return And(*result[0])


def handle_or(result: ParseResults) -> Or:
return Or(result[0][0], result[0][1])

return Or(*result[0])

boolean_expression = infix_notation(
predicate,
Expand Down
8 changes: 8 additions & 0 deletions tests/expressions/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,14 @@ def test_and_or_with_parens() -> None:
)


def test_multiple_and_or() -> None:
assert And(EqualTo("foo", 1), EqualTo("bar", 2), EqualTo("baz", 3)) == parser.parse("foo = 1 and bar = 2 and baz = 3")
assert Or(EqualTo("foo", 1), EqualTo("foo", 2), EqualTo("foo", 3)) == parser.parse("foo = 1 or foo = 2 or foo = 3")
assert Or(
And(NotNull("foo"), LessThan("foo", 5)), And(GreaterThan("foo", 10), LessThan("foo", 100), IsNull("bar"))
) == parser.parse("foo is not null and foo < 5 or (foo > 10 and foo < 100 and bar is null)")


def test_starts_with() -> None:
assert StartsWith("foo", "data") == parser.parse("foo LIKE 'data'")

Expand Down

0 comments on commit 4c2c1af

Please sign in to comment.