diff --git a/pyiceberg/expressions/parser.py b/pyiceberg/expressions/parser.py index d6d5bdb794..a5452f5001 100644 --- a/pyiceberg/expressions/parser.py +++ b/pyiceberg/expressions/parser.py @@ -233,11 +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( diff --git a/tests/expressions/test_parser.py b/tests/expressions/test_parser.py index f4bebca066..3b21835dae 100644 --- a/tests/expressions/test_parser.py +++ b/tests/expressions/test_parser.py @@ -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'")