Skip to content

Commit cb9b4f1

Browse files
Expression: Fix multiple and/or expressions (#65)
1 parent 0a584a4 commit cb9b4f1

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

pyiceberg/expressions/parser.py

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

234234

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

238238

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

242242

243243
boolean_expression = infix_notation(

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)