diff --git a/tests/table/test_inspect.py b/tests/table/test_inspect.py index 2404eadc74..306579754a 100644 --- a/tests/table/test_inspect.py +++ b/tests/table/test_inspect.py @@ -29,7 +29,7 @@ from pyiceberg.table.snapshots import Snapshot from pyiceberg.transforms import IdentityTransform from pyiceberg.typedef import Record -from pyiceberg.types import NestedField, StringType +from pyiceberg.types import DoubleType, FloatType, IntegerType, LongType, NestedField, PrimitiveType, StringType from tests.catalog.test_base import InMemoryCatalog @@ -106,3 +106,35 @@ def test_inspect_manifests_preserves_empty_string_bounds(catalog: InMemoryCatalo partition_summary = tbl.inspect.manifests().to_pydict()["partition_summaries"][0][0] assert partition_summary["lower_bound"] == "" assert partition_summary["upper_bound"] == "" + + +def test_inspect_bounds_after_type_promotion(catalog: InMemoryCatalog) -> None: + # Promotion does not rewrite existing files, so their bounds keep the narrower 4-byte encoding + # while the current schema type is the 8-byte one. + cases: list[tuple[str, PrimitiveType, PrimitiveType, pa.DataType, list[float]]] = [ + ("int_to_long", IntegerType(), LongType(), pa.int32(), [1, 2]), + ("float_to_double", FloatType(), DoubleType(), pa.float32(), [1.5, 2.5]), + ] + for name, file_type, promoted_type, arrow_type, values in cases: + schema = Schema(NestedField(1, "v", file_type, required=False)) + spec = PartitionSpec(PartitionField(1, 1000, IdentityTransform(), "v")) + tbl = catalog.create_table(f"default.{name}", schema, partition_spec=spec) + tbl.append(pa.table({"v": values}, schema=pa.schema([pa.field("v", arrow_type, nullable=True)]))) + + with tbl.update_schema() as update: + update.update_column("v", field_type=promoted_type) + + for files_table in [ + tbl.inspect.entries(), + tbl.inspect.files(), + tbl.inspect.data_files(), + tbl.inspect.all_files(), + tbl.inspect.all_data_files(), + ]: + metrics = [m["v"] for m in files_table.to_pydict()["readable_metrics"]] + assert sorted(m["lower_bound"] for m in metrics) == values, name + assert sorted(m["upper_bound"] for m in metrics) == values, name + + partition_summaries = tbl.inspect.manifests().to_pydict()["partition_summaries"][0] + assert partition_summaries[0]["lower_bound"] == str(values[0]), name + assert partition_summaries[0]["upper_bound"] == str(values[-1]), name