From 7f9ac800e92f46af1d2d79a46d263e51873acee8 Mon Sep 17 00:00:00 2001 From: Abanoub Doss Date: Sat, 6 Jun 2026 14:35:12 -0500 Subject: [PATCH] fix(literals): return long bounds for decimal conversion --- pyiceberg/expressions/literals.py | 4 ++-- tests/expressions/test_literals.py | 9 +++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/pyiceberg/expressions/literals.py b/pyiceberg/expressions/literals.py index 50c6d2d614..1ff8008520 100644 --- a/pyiceberg/expressions/literals.py +++ b/pyiceberg/expressions/literals.py @@ -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) diff --git a/tests/expressions/test_literals.py b/tests/expressions/test_literals.py index b37c94762d..de9d390775 100644 --- a/tests/expressions/test_literals.py +++ b/tests/expressions/test_literals.py @@ -40,6 +40,7 @@ IntBelowMin, Literal, LongAboveMax, + LongBelowMin, LongLiteral, StringLiteral, TimeLiteral, @@ -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())