Skip to content
Open
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
4 changes: 2 additions & 2 deletions pyiceberg/expressions/literals.py
Original file line number Diff line number Diff line change
Expand Up @@ -526,9 +526,9 @@ def _(self, _: IntegerType) -> Literal[int]:
def _(self, _: LongType) -> Literal[int]:
value_int = int(self.value.to_integral_value())
if value_int > LongType.max:
return IntAboveMax()
return LongAboveMax()
elif value_int < LongType.min:
return IntBelowMin()
return LongBelowMin()
else:
return LongLiteral(value_int)

Expand Down
9 changes: 9 additions & 0 deletions tests/expressions/test_literals.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
IntBelowMin,
Literal,
LongAboveMax,
LongBelowMin,
LongLiteral,
StringLiteral,
TimeLiteral,
Expand Down Expand Up @@ -878,6 +879,14 @@ def test_string_to_long_large_scientific_notation_above_max() -> None:
assert isinstance(literal("1e1000000").to(LongType()), LongAboveMax)


def test_decimal_to_long_above_max() -> None:
assert isinstance(DecimalLiteral(Decimal(LongType.max + 1)).to(LongType()), LongAboveMax)


def test_decimal_to_long_below_min() -> None:
assert isinstance(DecimalLiteral(Decimal(LongType.min - 1)).to(LongType()), LongBelowMin)


def test_string_to_integer_type_invalid_value() -> None:
with pytest.raises(ValueError) as e:
_ = literal("abc").to(IntegerType())
Expand Down