Bases: IcebergRootModel[L]
, Generic[L]
, ABC
Literal which has a value and can be converted between types.
Source code in pyiceberg/expressions/literals.py
| class Literal(IcebergRootModel[L], Generic[L], ABC): # type: ignore
"""Literal which has a value and can be converted between types."""
root: L = Field()
def __init__(self, value: L, value_type: Type[L], /, **data): # type: ignore
if value is None:
raise TypeError("Invalid literal value: None")
super().__init__(value)
if value is None or not isinstance(value, value_type):
raise TypeError(f"Invalid literal value: {value!r} (not a {value_type})")
if isinstance(value, float) and isnan(value):
raise ValueError("Cannot create expression literal from NaN.")
@property
def value(self) -> L:
return self.root
@singledispatchmethod
@abstractmethod
def to(self, type_var: IcebergType) -> Literal[L]: ... # pragma: no cover
def __repr__(self) -> str:
"""Return the string representation of the Literal class."""
return f"{type(self).__name__}({self.value!r})"
def __str__(self) -> str:
"""Return the string representation of the Literal class."""
return str(self.value)
def __hash__(self) -> int:
"""Return a hashed representation of the Literal class."""
return hash(self.value)
def __eq__(self, other: Any) -> bool:
"""Return the equality of two instances of the Literal class."""
if not isinstance(other, Literal):
return False
return self.value == other.value
def __ne__(self, other: Any) -> bool:
"""Return the inequality of two instances of the Literal class."""
return not self.__eq__(other)
def __lt__(self, other: Any) -> bool:
"""Return if one instance of the Literal class is less than another instance."""
return self.value < other.value
def __gt__(self, other: Any) -> bool:
"""Return if one instance of the Literal class is greater than another instance."""
return self.value > other.value
def __le__(self, other: Any) -> bool:
"""Return if one instance of the Literal class is less than or equal to another instance."""
return self.value <= other.value
def __ge__(self, other: Any) -> bool:
"""Return if one instance of the Literal class is greater than or equal to another instance."""
return self.value >= other.value
|
__eq__(other)
Return the equality of two instances of the Literal class.
Source code in pyiceberg/expressions/literals.py
| def __eq__(self, other: Any) -> bool:
"""Return the equality of two instances of the Literal class."""
if not isinstance(other, Literal):
return False
return self.value == other.value
|
__ge__(other)
Return if one instance of the Literal class is greater than or equal to another instance.
Source code in pyiceberg/expressions/literals.py
| def __ge__(self, other: Any) -> bool:
"""Return if one instance of the Literal class is greater than or equal to another instance."""
return self.value >= other.value
|
__gt__(other)
Return if one instance of the Literal class is greater than another instance.
Source code in pyiceberg/expressions/literals.py
| def __gt__(self, other: Any) -> bool:
"""Return if one instance of the Literal class is greater than another instance."""
return self.value > other.value
|
__hash__()
Return a hashed representation of the Literal class.
Source code in pyiceberg/expressions/literals.py
| def __hash__(self) -> int:
"""Return a hashed representation of the Literal class."""
return hash(self.value)
|
__le__(other)
Return if one instance of the Literal class is less than or equal to another instance.
Source code in pyiceberg/expressions/literals.py
| def __le__(self, other: Any) -> bool:
"""Return if one instance of the Literal class is less than or equal to another instance."""
return self.value <= other.value
|
__lt__(other)
Return if one instance of the Literal class is less than another instance.
Source code in pyiceberg/expressions/literals.py
| def __lt__(self, other: Any) -> bool:
"""Return if one instance of the Literal class is less than another instance."""
return self.value < other.value
|
__ne__(other)
Return the inequality of two instances of the Literal class.
Source code in pyiceberg/expressions/literals.py
| def __ne__(self, other: Any) -> bool:
"""Return the inequality of two instances of the Literal class."""
return not self.__eq__(other)
|
__repr__()
Return the string representation of the Literal class.
Source code in pyiceberg/expressions/literals.py
| def __repr__(self) -> str:
"""Return the string representation of the Literal class."""
return f"{type(self).__name__}({self.value!r})"
|
__str__()
Return the string representation of the Literal class.
Source code in pyiceberg/expressions/literals.py
| def __str__(self) -> str:
"""Return the string representation of the Literal class."""
return str(self.value)
|