From 304e13b380b4c122f617704c67b6fb767aa2e93f Mon Sep 17 00:00:00 2001 From: Daniel Weeks Date: Sat, 21 Oct 2023 15:12:33 -0700 Subject: [PATCH 1/3] Fix literal predicate equality check --- pyiceberg/expressions/__init__.py | 2 +- tests/expressions/test_parser.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pyiceberg/expressions/__init__.py b/pyiceberg/expressions/__init__.py index f3dc6dcb36..568b0dd843 100644 --- a/pyiceberg/expressions/__init__.py +++ b/pyiceberg/expressions/__init__.py @@ -701,7 +701,7 @@ def bind(self, schema: Schema, case_sensitive: bool = True) -> BoundLiteralPredi def __eq__(self, other: Any) -> bool: """Return the equality of two instances of the LiteralPredicate class.""" - if isinstance(other, LiteralPredicate): + if isinstance(other, self.__class__): return self.term == other.term and self.literal == other.literal return False diff --git a/tests/expressions/test_parser.py b/tests/expressions/test_parser.py index 65415f2e9a..98f1096db4 100644 --- a/tests/expressions/test_parser.py +++ b/tests/expressions/test_parser.py @@ -86,8 +86,8 @@ def test_greater_than() -> None: def test_greater_than_or_equal() -> None: - assert GreaterThanOrEqual("foo", 5) == parser.parse("foo <= 5") - assert GreaterThanOrEqual("foo", "a") == parser.parse("'a' >= foo") + assert GreaterThanOrEqual("foo", 5) == parser.parse("foo >= 5") + assert GreaterThanOrEqual("foo", "a") == parser.parse("'a' <= foo") def test_equal_to() -> None: From fc133a23323722b3ad9792bbddb841d4d58a0519 Mon Sep 17 00:00:00 2001 From: Fokko Driesprong Date: Sun, 22 Oct 2023 10:15:47 +0200 Subject: [PATCH 2/3] Fix the tests --- tests/test_transforms.py | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/tests/test_transforms.py b/tests/test_transforms.py index d8a2151752..81a322c65b 100644 --- a/tests/test_transforms.py +++ b/tests/test_transforms.py @@ -830,15 +830,27 @@ def test_projection_truncate_string_literal_eq(bound_reference_str: BoundReferen def test_projection_truncate_string_literal_gt(bound_reference_str: BoundReference[str]) -> None: - assert TruncateTransform(2).project("name", BoundGreaterThan(term=bound_reference_str, literal=literal("data"))) == EqualTo( - term="name", literal=literal("da") - ) + assert TruncateTransform(2).project( + "name", BoundGreaterThan(term=bound_reference_str, literal=literal("data")) + ) == GreaterThanOrEqual(term="name", literal=literal("da")) def test_projection_truncate_string_literal_gte(bound_reference_str: BoundReference[str]) -> None: assert TruncateTransform(2).project( "name", BoundGreaterThanOrEqual(term=bound_reference_str, literal=literal("data")) - ) == EqualTo(term="name", literal=literal("da")) + ) == GreaterThanOrEqual(term="name", literal=literal("da")) + + +def test_projection_truncate_string_literal_lt(bound_reference_str: BoundReference[str]) -> None: + assert TruncateTransform(2).project( + "name", BoundLessThan(term=bound_reference_str, literal=literal("data")) + ) == LessThanOrEqual(term="name", literal=literal("da")) + + +def test_projection_truncate_string_literal_lte(bound_reference_str: BoundReference[str]) -> None: + assert TruncateTransform(2).project( + "name", BoundLessThanOrEqual(term=bound_reference_str, literal=literal("data")) + ) == LessThanOrEqual(term="name", literal=literal("da")) def test_projection_truncate_string_set_same_result(bound_reference_str: BoundReference[str]) -> None: From a8d873eb7ad3b67b81ac8a983f03482e15de869e Mon Sep 17 00:00:00 2001 From: Fokko Driesprong Date: Tue, 24 Oct 2023 08:21:43 -0400 Subject: [PATCH 3/3] Some more fixes --- pyiceberg/expressions/__init__.py | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/pyiceberg/expressions/__init__.py b/pyiceberg/expressions/__init__.py index 568b0dd843..0f66a5d3b3 100644 --- a/pyiceberg/expressions/__init__.py +++ b/pyiceberg/expressions/__init__.py @@ -364,7 +364,7 @@ def __init__(self, term: Union[str, UnboundTerm[Any]]): def __eq__(self, other: Any) -> bool: """Return the equality of two instances of the UnboundPredicate class.""" - return self.term == other.term if isinstance(other, UnboundPredicate) else False + return self.term == other.term if isinstance(other, self.__class__) else False @abstractmethod def bind(self, schema: Schema, case_sensitive: bool = True) -> BooleanExpression: @@ -531,7 +531,7 @@ def __repr__(self) -> str: def __eq__(self, other: Any) -> bool: """Return the equality of two instances of the SetPredicate class.""" - return self.term == other.term and self.literals == other.literals if isinstance(other, SetPredicate) else False + return self.term == other.term and self.literals == other.literals if isinstance(other, self.__class__) else False def __getnewargs__(self) -> Tuple[UnboundTerm[L], Set[Literal[L]]]: """Pickle the SetPredicate class.""" @@ -664,12 +664,6 @@ def __invert__(self) -> In[L]: """Transform the Expression into its negated version.""" return In[L](self.term, self.literals) - def __eq__(self, other: Any) -> bool: - """Return the equality of two instances of the NotIn class.""" - if isinstance(other, NotIn): - return self.term == other.term and self.literals == other.literals - return False - @property def as_bound(self) -> Type[BoundNotIn[L]]: return BoundNotIn[L]