rdblue commented on code in PR #5258:
URL: https://github.com/apache/iceberg/pull/5258#discussion_r929231501


##########
python/pyiceberg/expressions/base.py:
##########
@@ -282,49 +338,239 @@ def __repr__(self) -> str:
         return f"Not({repr(self.child)})"
 
     def __str__(self) -> str:
-        return f"(not {self.child})"
+        return f"Not({str(self.child)})"
 
 
+@dataclass(frozen=True)
 class AlwaysTrue(BooleanExpression, ABC, Singleton):
     """TRUE expression"""
 
-    def __invert__(self) -> "AlwaysFalse":
+    def __invert__(self) -> AlwaysFalse:
         return AlwaysFalse()
 
-    def __repr__(self) -> str:
-        return "AlwaysTrue()"
-
-    def __str__(self) -> str:
-        return "true"
-
 
+@dataclass(frozen=True)
 class AlwaysFalse(BooleanExpression, ABC, Singleton):
     """FALSE expression"""
 
-    def __invert__(self) -> "AlwaysTrue":
+    def __invert__(self) -> AlwaysTrue:
         return AlwaysTrue()
 
-    def __repr__(self) -> str:
-        return "AlwaysFalse()"
 
-    def __str__(self) -> str:
-        return "false"
+class IsNull(UnboundPredicate[T]):
+    def __invert__(self) -> NotNull:
+        return NotNull(self.term)
+
+    def _validate_literals(self):  # pylint: disable=W0238
+        if self.literals is not None:
+            raise AttributeError("Null is a unary predicate and takes no 
Literals.")
+
+    def bind(self, schema: Schema, case_sensitive: bool) -> BoundIsNull[T]:
+        bound_ref = self.term.bind(schema, case_sensitive)
+        return BoundIsNull(bound_ref)
+
+
+class BoundIsNull(BoundPredicate[T]):
+    def __invert__(self) -> BoundNotNull:
+        return BoundNotNull(self.term)
+
+    def _validate_literals(self):  # pylint: disable=W0238
+        if self.literals:
+            raise AttributeError("Null is a unary predicate and takes no 
Literals.")
+
+
+class NotNull(UnboundPredicate[T]):
+    def __invert__(self) -> IsNull:
+        return IsNull(self.term)
+
+    def _validate_literals(self):  # pylint: disable=W0238
+        if self.literals:
+            raise AttributeError("NotNull is a unary predicate and takes no 
Literals.")
+
+    def bind(self, schema: Schema, case_sensitive: bool) -> BoundNotNull[T]:
+        bound_ref = self.term.bind(schema, case_sensitive)
+        return BoundNotNull(bound_ref)
+
+
+class BoundNotNull(BoundPredicate[T]):
+    def __invert__(self) -> BoundIsNull:
+        return BoundIsNull(self.term)
+
+    def _validate_literals(self):  # pylint: disable=W0238
+        if self.literals:
+            raise AttributeError("NotNull is a unary predicate and takes no 
Literals.")
+
+
+class IsNaN(UnboundPredicate[T]):
+    def __invert__(self) -> NotNaN:
+        return NotNaN(self.term)
+
+    def _validate_literals(self):  # pylint: disable=W0238
+        if self.literals:
+            raise AttributeError("IsNaN is a unary predicate and takes no 
Literals.")
+
+    def bind(self, schema: Schema, case_sensitive: bool) -> BoundIsNaN[T]:
+        bound_ref = self.term.bind(schema, case_sensitive)
+        return BoundIsNaN(bound_ref)
+
+
+class BoundIsNaN(BoundPredicate[T]):
+    def __invert__(self) -> BoundNotNaN:
+        return BoundNotNaN(self.term)
+
+    def _validate_literals(self):  # pylint: disable=W0238
+        if self.literals:
+            raise AttributeError("IsNaN is a unary predicate and takes no 
Literals.")
+
+
+class NotNaN(UnboundPredicate[T]):
+    def __invert__(self) -> IsNaN:
+        return IsNaN(self.term)
+
+    def _validate_literals(self):  # pylint: disable=W0238
+        if self.literals:
+            raise AttributeError("NotNaN is a unary predicate and takes no 
Literals.")
+
+    def bind(self, schema: Schema, case_sensitive: bool) -> BoundNotNaN[T]:
+        bound_ref = self.term.bind(schema, case_sensitive)
+        return BoundNotNaN(bound_ref)
+
+
+class BoundNotNaN(BoundPredicate[T]):
+    def __invert__(self) -> BoundIsNaN:
+        return BoundIsNaN(self.term)
+
+    def _validate_literals(self):  # pylint: disable=W0238
+        if self.literals:
+            raise AttributeError("NotNaN is a unary predicate and takes no 
Literals.")
 
 
-@dataclass(frozen=True)
 class BoundIn(BoundPredicate[T]):
-    def __invert__(self):
-        raise TypeError("In expressions do not support negation.")
+    def _validate_literals(self):  # pylint: disable=W0238
+        if not self.literals:
+            raise AttributeError("BoundIn must contain at least 1 literal.")
+
+    def __invert__(self) -> BoundNotIn[T]:
+        return BoundNotIn(self.term, *self.literals)
 
 
-@dataclass(frozen=True)
 class In(UnboundPredicate[T]):
-    def __invert__(self):
-        raise TypeError("In expressions do not support negation.")
+    def _validate_literals(self):  # pylint: disable=W0238
+        if not self.literals:
+            raise AttributeError("In must contain at least 1 literal.")
+
+    def __invert__(self) -> NotIn[T]:
+        return NotIn(self.term, *self.literals)
 
     def bind(self, schema: Schema, case_sensitive: bool) -> BoundIn[T]:
         bound_ref = self.term.bind(schema, case_sensitive)
-        return BoundIn(bound_ref, tuple(lit.to(bound_ref.field.field_type) for 
lit in self.literals))  # type: ignore
+        return BoundIn(bound_ref, *tuple(lit.to(bound_ref.field.field_type) 
for lit in self.literals))  # type: ignore
+
+
+class BoundNotIn(BoundPredicate[T]):
+    def _validate_literals(self):  # pylint: disable=W0238
+        if not self.literals:
+            raise AttributeError("BoundNotIn must contain at least 1 literal.")
+
+    def __invert__(self) -> BoundIn[T]:
+        return BoundIn(self.term, *self.literals)
+
+
+class NotIn(UnboundPredicate[T]):
+    def _validate_literals(self):  # pylint: disable=W0238
+        if not self.literals:
+            raise AttributeError("NotIn must contain at least 1 literal.")
+
+    def __invert__(self) -> In[T]:
+        return In(self.term, *self.literals)
+
+    def bind(self, schema: Schema, case_sensitive: bool) -> BoundNotIn[T]:
+        bound_ref = self.term.bind(schema, case_sensitive)
+        return BoundNotIn(bound_ref, *tuple(lit.to(bound_ref.field.field_type) 
for lit in self.literals))  # type: ignore
+
+
+class BoundEq(BoundPredicate[T]):
+    def __invert__(self) -> BoundNotEq[T]:
+        return BoundNotEq(self.term, *self.literals)
+
+
+class Eq(UnboundPredicate[T]):

Review Comment:
   Since we are using expression classes directly, rather than using factory 
methods, I think that these classes should use full names, like `Equals` and 
`LessThan` (or `BoundEqual` and `BoundLessThan`).



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to