samredai commented on code in PR #5362:
URL: https://github.com/apache/iceberg/pull/5362#discussion_r932817543
##########
python/pyiceberg/expressions/base.py:
##########
@@ -342,235 +243,321 @@ def __str__(self) -> str:
@dataclass(frozen=True)
-class AlwaysTrue(BooleanExpression, ABC, Singleton):
+class AlwaysTrue(BooleanExpression, Singleton):
"""TRUE expression"""
def __invert__(self) -> AlwaysFalse:
return AlwaysFalse()
@dataclass(frozen=True)
-class AlwaysFalse(BooleanExpression, ABC, Singleton):
+class AlwaysFalse(BooleanExpression, Singleton):
"""FALSE expression"""
def __invert__(self) -> AlwaysTrue:
return AlwaysTrue()
-class IsNull(UnboundPredicate[T]):
- def __invert__(self) -> NotNull:
- return NotNull(self.term)
+@dataclass(frozen=True)
+class BoundPredicate(Bound[T], BooleanExpression):
+ term: BoundTerm[T]
- 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 __invert__(self) -> BoundPredicate[T]:
+ raise NotImplementedError
- def bind(self, schema: Schema, case_sensitive: bool) -> BoundIsNull[T]:
- bound_ref = self.term.bind(schema, case_sensitive)
- return BoundIsNull(bound_ref)
+@dataclass(frozen=True)
+class UnboundPredicate(Unbound[T, BooleanExpression], BooleanExpression):
+ as_bound: ClassVar[type]
+ term: UnboundTerm[T]
-class BoundIsNull(BoundPredicate[T]):
- def __invert__(self) -> BoundNotNull:
- return BoundNotNull(self.term)
+ def __invert__(self) -> UnboundPredicate[T]:
+ raise NotImplementedError
- def _validate_literals(self): # pylint: disable=W0238
- if self.literals:
- raise AttributeError("Null is a unary predicate and takes no
Literals.")
+ def bind(self, schema: Schema, case_sensitive: bool = True) ->
BooleanExpression:
+ raise NotImplementedError
-class NotNull(UnboundPredicate[T]):
- def __invert__(self) -> IsNull:
- return IsNull(self.term)
+@dataclass(frozen=True)
+class UnaryPredicate(UnboundPredicate[T]):
+ def bind(self, schema: Schema, case_sensitive: bool = True) ->
BooleanExpression:
+ bound_term = self.term.bind(schema, case_sensitive)
+ return self.as_bound(bound_term)
+
+ def __invert__(self) -> UnaryPredicate[T]:
+ raise NotImplementedError
+
- def _validate_literals(self): # pylint: disable=W0238
- if self.literals:
- raise AttributeError("NotNull is a unary predicate and takes no
Literals.")
+@dataclass(frozen=True)
+class BoundUnaryPredicate(BoundPredicate[T]):
+ def __invert__(self) -> BoundUnaryPredicate[T]:
+ raise NotImplementedError
+
+
+@dataclass(frozen=True)
+class BoundIsNull(BoundUnaryPredicate[T]):
+ def __new__(cls, term: BoundTerm[T]):
+ if term.ref().field.required:
+ return AlwaysFalse()
+ return super().__new__(cls)
+
+ def __invert__(self) -> BoundNotNull[T]:
+ return BoundNotNull(self.term)
- def bind(self, schema: Schema, case_sensitive: bool) -> BoundNotNull[T]:
- bound_ref = self.term.bind(schema, case_sensitive)
- return BoundNotNull(bound_ref)
+@dataclass(frozen=True)
+class BoundNotNull(BoundUnaryPredicate[T]):
+ def __new__(cls, term: BoundTerm[T]):
Review Comment:
pylint for the 3.8 CI seems to not like that the argument signature is
different between this and the default `super().__new__`. You can change this
to match the `*args, **kwargs` from super, but then you'd have to pull out the
kwargs and it won't look as clean plus won't allow positional arguments.
```py
@dataclass(frozen=True)
class BoundNotNull(BoundUnaryPredicate[T]):
def __new__(cls, *args, **kwargs):
term: BoundTerm[T] = kwargs["term"]
if term.ref().field.required:
return AlwaysTrue()
return super().__new__(cls)
```
This is just a linting error though and the assumptions made when using the
super type hold well so I think it'd be better to just ignore it for these
lines.
```py
@dataclass(frozen=True)
class BoundNotNull(BoundUnaryPredicate[T]):
def __new__(cls, term: BoundTerm[T]): # pylint: disable=W0221
```
--
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]