Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions pyiceberg/expressions/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
literal,
)
from pyiceberg.schema import Accessor, Schema
from pyiceberg.typedef import L, StructProtocol
from pyiceberg.typedef import IcebergRootModel, L, StructProtocol
from pyiceberg.types import DoubleType, FloatType, NestedField
from pyiceberg.utils.singleton import Singleton

Expand Down Expand Up @@ -361,10 +361,14 @@ def __getnewargs__(self) -> Tuple[BooleanExpression]:
"""Pickle the Not class."""
return (self.child,)

"""TRUE expression."""


class AlwaysTrue(BooleanExpression, Singleton):
class AlwaysTrue(BooleanExpression, Singleton, IcebergRootModel[str]):
"""TRUE expression."""

root: str = "true"

def __invert__(self) -> AlwaysFalse:
"""Transform the Expression into its negated version."""
return AlwaysFalse()
Expand All @@ -378,9 +382,11 @@ def __repr__(self) -> str:
return "AlwaysTrue()"


class AlwaysFalse(BooleanExpression, Singleton):
class AlwaysFalse(BooleanExpression, Singleton, IcebergRootModel[str]):
"""FALSE expression."""

root: str = "false"

def __invert__(self) -> AlwaysTrue:
"""Transform the Expression into its negated version."""
return AlwaysTrue()
Expand Down Expand Up @@ -732,14 +738,14 @@ def bind(self, schema: Schema, case_sensitive: bool = True) -> BoundLiteralPredi

if isinstance(lit, AboveMax):
if isinstance(self, (LessThan, LessThanOrEqual, NotEqualTo)):
return AlwaysTrue() # type: ignore
return AlwaysTrue()
elif isinstance(self, (GreaterThan, GreaterThanOrEqual, EqualTo)):
return AlwaysFalse() # type: ignore
return AlwaysFalse()
elif isinstance(lit, BelowMin):
if isinstance(self, (GreaterThan, GreaterThanOrEqual, NotEqualTo)):
return AlwaysTrue() # type: ignore
return AlwaysTrue()
elif isinstance(self, (LessThan, LessThanOrEqual, EqualTo)):
return AlwaysFalse() # type: ignore
return AlwaysFalse()

return self.as_bound(bound_term, lit)

Expand Down
2 changes: 2 additions & 0 deletions tests/expressions/test_expressions.py
Original file line number Diff line number Diff line change
Expand Up @@ -738,6 +738,7 @@ def test_not() -> None:

def test_always_true() -> None:
always_true = AlwaysTrue()
assert always_true.model_dump_json() == '"true"'
assert str(always_true) == "AlwaysTrue()"
assert repr(always_true) == "AlwaysTrue()"
assert always_true == eval(repr(always_true))
Expand All @@ -746,6 +747,7 @@ def test_always_true() -> None:

def test_always_false() -> None:
always_false = AlwaysFalse()
assert always_false.model_dump_json() == '"false"'
assert str(always_false) == "AlwaysFalse()"
assert repr(always_false) == "AlwaysFalse()"
assert always_false == eval(repr(always_false))
Expand Down