You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iceberg.apache.org by dr...@apache.org on 2026/06/21 23:47:48 UTC
(iceberg-python) branch main updated: Return bounds sentinels for long date literals (#3546)
This is an automated email from the ASF dual-hosted git repository.
geruh pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/iceberg-python.git
The following commit(s) were added to refs/heads/main by this push:
new fb96df117 Return bounds sentinels for long date literals (#3546)
fb96df117 is described below
commit fb96df117677a47cf75e8e86f7b88bf47dc0e674
Author: Kevin Liu <ke...@users.noreply.github.com>
AuthorDate: Sun Jun 21 19:47:43 2026 -0400
Return bounds sentinels for long date literals (#3546)
---
pyiceberg/expressions/literals.py | 4 ++++
tests/expressions/test_expressions.py | 21 +++++++++++++++++++++
tests/expressions/test_literals.py | 10 ++++++++++
3 files changed, 35 insertions(+)
diff --git a/pyiceberg/expressions/literals.py b/pyiceberg/expressions/literals.py
index fec06aa79..20be711c0 100644
--- a/pyiceberg/expressions/literals.py
+++ b/pyiceberg/expressions/literals.py
@@ -329,6 +329,10 @@ class LongLiteral(Literal[int]):
@to.register(DateType)
def _(self, _: DateType) -> Literal[int]:
+ if IntegerType.max < self.value:
+ return IntAboveMax()
+ elif IntegerType.min > self.value:
+ return IntBelowMin()
return DateLiteral(self.value)
@to.register(TimeType)
diff --git a/tests/expressions/test_expressions.py b/tests/expressions/test_expressions.py
index d6c0ce1f5..8ce48a689 100644
--- a/tests/expressions/test_expressions.py
+++ b/tests/expressions/test_expressions.py
@@ -67,6 +67,7 @@ from pyiceberg.expressions.visitors import _from_byte_buffer
from pyiceberg.schema import Accessor, Schema
from pyiceberg.typedef import Record
from pyiceberg.types import (
+ DateType,
DecimalType,
DoubleType,
FloatType,
@@ -1150,6 +1151,26 @@ def test_above_int_bounds_greater_than_or_equal(
assert GreaterThanOrEqual("a", below_int_min).bind(int_schema) is AlwaysTrue()
+@pytest.fixture
+def date_schema() -> Schema:
+ return Schema(NestedField(field_id=1, name="a", field_type=DateType(), required=False))
+
+
+def test_above_date_bounds_equal_to(date_schema: Schema, above_int_max: Literal[int], below_int_min: Literal[int]) -> None:
+ assert EqualTo("a", above_int_max).bind(date_schema) is AlwaysFalse()
+ assert EqualTo("a", below_int_min).bind(date_schema) is AlwaysFalse()
+
+
+def test_above_date_bounds_less_than(date_schema: Schema, above_int_max: Literal[int], below_int_min: Literal[int]) -> None:
+ assert LessThan("a", above_int_max).bind(date_schema) is AlwaysTrue()
+ assert LessThan("a", below_int_min).bind(date_schema) is AlwaysFalse()
+
+
+def test_above_date_bounds_greater_than(date_schema: Schema, above_int_max: Literal[int], below_int_min: Literal[int]) -> None:
+ assert GreaterThan("a", above_int_max).bind(date_schema) is AlwaysFalse()
+ assert GreaterThan("a", below_int_min).bind(date_schema) is AlwaysTrue()
+
+
@pytest.fixture
def float_schema() -> Schema:
return Schema(NestedField(field_id=1, name="a", field_type=FloatType(), required=False))
diff --git a/tests/expressions/test_literals.py b/tests/expressions/test_literals.py
index 1b88ef207..33b41d5e4 100644
--- a/tests/expressions/test_literals.py
+++ b/tests/expressions/test_literals.py
@@ -160,6 +160,16 @@ def test_integer_to_date_conversion() -> None:
assert date_lit.value == date_delta
+def test_long_to_date_outside_bound() -> None:
+ big_lit = literal(IntegerType.max + 1).to(LongType())
+ above_max_lit = big_lit.to(DateType())
+ assert above_max_lit == IntAboveMax()
+
+ small_lit = literal(IntegerType.min - 1).to(LongType())
+ below_min_lit = small_lit.to(DateType())
+ assert below_min_lit == IntBelowMin()
+
+
def test_long_to_integer_within_bound() -> None:
lit = literal(34).to(LongType())
int_lit = lit.to(IntegerType())