Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pyiceberg/expressions/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Copy link
Contributor

@rdblue rdblue Oct 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does the parser produce more than 2 child expressions?

Is this a result of using infix_notation that I didn't realize at the time?



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


boolean_expression = infix_notation(
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