|
29 | 29 | from pyiceberg.table.snapshots import Snapshot |
30 | 30 | from pyiceberg.transforms import IdentityTransform |
31 | 31 | from pyiceberg.typedef import Record |
32 | | -from pyiceberg.types import NestedField, StringType |
| 32 | +from pyiceberg.types import DoubleType, FloatType, IntegerType, LongType, NestedField, PrimitiveType, StringType |
33 | 33 | from tests.catalog.test_base import InMemoryCatalog |
34 | 34 |
|
35 | 35 |
|
@@ -106,3 +106,35 @@ def test_inspect_manifests_preserves_empty_string_bounds(catalog: InMemoryCatalo |
106 | 106 | partition_summary = tbl.inspect.manifests().to_pydict()["partition_summaries"][0][0] |
107 | 107 | assert partition_summary["lower_bound"] == "" |
108 | 108 | 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