Skip to content

Commit 2ed79b6

Browse files
authored
Add inspect regression test for bounds after type promotion (apache#4314)
Bounds written before an int->long or float->double promotion keep their 4-byte encoding. apache#3293 fixed decoding them, but only covered the metrics evaluators. Cover the inspect metadata tables too, so the crash reported in apache#3744 can't regress. Closes apache#3744
1 parent 2549061 commit 2ed79b6

1 file changed

Lines changed: 33 additions & 1 deletion

File tree

‎tests/table/test_inspect.py‎

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
from pyiceberg.table.snapshots import Snapshot
3030
from pyiceberg.transforms import IdentityTransform
3131
from pyiceberg.typedef import Record
32-
from pyiceberg.types import NestedField, StringType
32+
from pyiceberg.types import DoubleType, FloatType, IntegerType, LongType, NestedField, PrimitiveType, StringType
3333
from tests.catalog.test_base import InMemoryCatalog
3434

3535

@@ -106,3 +106,35 @@ def test_inspect_manifests_preserves_empty_string_bounds(catalog: InMemoryCatalo
106106
partition_summary = tbl.inspect.manifests().to_pydict()["partition_summaries"][0][0]
107107
assert partition_summary["lower_bound"] == ""
108108
assert partition_summary["upper_bound"] == ""
109+
110+
111+
def test_inspect_bounds_after_type_promotion(catalog: InMemoryCatalog) -> None:
112+
# Promotion does not rewrite existing files, so their bounds keep the narrower 4-byte encoding
113+
# while the current schema type is the 8-byte one.
114+
cases: list[tuple[str, PrimitiveType, PrimitiveType, pa.DataType, list[float]]] = [
115+
("int_to_long", IntegerType(), LongType(), pa.int32(), [1, 2]),
116+
("float_to_double", FloatType(), DoubleType(), pa.float32(), [1.5, 2.5]),
117+
]
118+
for name, file_type, promoted_type, arrow_type, values in cases:
119+
schema = Schema(NestedField(1, "v", file_type, required=False))
120+
spec = PartitionSpec(PartitionField(1, 1000, IdentityTransform(), "v"))
121+
tbl = catalog.create_table(f"default.{name}", schema, partition_spec=spec)
122+
tbl.append(pa.table({"v": values}, schema=pa.schema([pa.field("v", arrow_type, nullable=True)])))
123+
124+
with tbl.update_schema() as update:
125+
update.update_column("v", field_type=promoted_type)
126+
127+
for files_table in [
128+
tbl.inspect.entries(),
129+
tbl.inspect.files(),
130+
tbl.inspect.data_files(),
131+
tbl.inspect.all_files(),
132+
tbl.inspect.all_data_files(),
133+
]:
134+
metrics = [m["v"] for m in files_table.to_pydict()["readable_metrics"]]
135+
assert sorted(m["lower_bound"] for m in metrics) == values, name
136+
assert sorted(m["upper_bound"] for m in metrics) == values, name
137+
138+
partition_summaries = tbl.inspect.manifests().to_pydict()["partition_summaries"][0]
139+
assert partition_summaries[0]["lower_bound"] == str(values[0]), name
140+
assert partition_summaries[0]["upper_bound"] == str(values[-1]), name

0 commit comments

Comments
 (0)