Skip to content

Commit ebfebb1

Browse files
committed
fixup! Fix NotStartsWith residual evaluation to return correct result
1 parent 7b22b18 commit ebfebb1

2 files changed

Lines changed: 14 additions & 0 deletions

File tree

pyiceberg/expressions/visitors.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1906,6 +1906,7 @@ def visit_starts_with(self, term: BoundTerm, literal: LiteralValue) -> BooleanEx
19061906

19071907
def visit_not_starts_with(self, term: BoundTerm, literal: LiteralValue) -> BooleanExpression:
19081908
starts_with_result = self.visit_starts_with(term, literal)
1909+
# Should return opposite of visit_starts_with
19091910
if isinstance(starts_with_result, AlwaysTrue):
19101911
return AlwaysFalse()
19111912
else:

tests/expressions/test_residual_evaluator.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,19 @@ def test_not_in_timestamp() -> None:
251251
assert residual == AlwaysTrue()
252252

253253

254+
def test_starts_with() -> None:
255+
schema = Schema(NestedField(1, "x", StringType()))
256+
spec = PartitionSpec(PartitionField(1, 1001, IdentityTransform(), "x_part"))
257+
258+
predicate = StartsWith("x", "a")
259+
res_eval = residual_evaluator_of(spec=spec, expr=predicate, case_sensitive=True, schema=schema)
260+
261+
assert res_eval.residual_for(Record("bb")) == AlwaysFalse()
262+
assert res_eval.residual_for(Record("abc")) == AlwaysTrue()
263+
assert res_eval.residual_for(Record("a")) == AlwaysTrue()
264+
assert res_eval.residual_for(Record("zoo")) == AlwaysFalse()
265+
266+
254267
def test_not_starts_with() -> None:
255268
schema = Schema(NestedField(1, "x", StringType()))
256269
spec = PartitionSpec(PartitionField(1, 1001, IdentityTransform(), "x_part"))

0 commit comments

Comments
 (0)