From 32c28143991c5623ac772bb6bc6ba54745463f70 Mon Sep 17 00:00:00 2001 From: Rahul-cs50 Date: Fri, 30 Oct 2026 13:18:22 +0530 Subject: [PATCH 1/4] Fix inspect.entries() for data files without column_sizes column_sizes is optional in a data file, but entries() built it with dict(entry.data_file.column_sizes), which raises TypeError when it is missing. DuckDB writes data files without it. Use the `or {}` that Closes #4186 --- pyiceberg/table/inspect.py | 2 +- tests/table/test_inspect.py | 34 +++++++++++++++++++++++++++++++++- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/pyiceberg/table/inspect.py b/pyiceberg/table/inspect.py index 6ccc6a500d..4feba3d532 100644 --- a/pyiceberg/table/inspect.py +++ b/pyiceberg/table/inspect.py @@ -272,7 +272,7 @@ def _readable_metrics_struct(bound_type: PrimitiveType) -> pa.StructType: "partition": partition_record_dict, "record_count": entry.data_file.record_count, "file_size_in_bytes": entry.data_file.file_size_in_bytes, - "column_sizes": dict(entry.data_file.column_sizes), + "column_sizes": dict(entry.data_file.column_sizes or {}), "value_counts": dict(entry.data_file.value_counts or {}), "null_value_counts": dict(entry.data_file.null_value_counts or {}), "nan_value_counts": dict(entry.data_file.nan_value_counts or {}), diff --git a/tests/table/test_inspect.py b/tests/table/test_inspect.py index 306579754a..f9658d7c1e 100644 --- a/tests/table/test_inspect.py +++ b/tests/table/test_inspect.py @@ -15,14 +15,16 @@ # specific language governing permissions and limitations # under the License. +import os from pathlib import PosixPath from typing import Any import pyarrow as pa +import pyarrow.parquet as pq import pytest from pyiceberg.conversions import to_bytes -from pyiceberg.manifest import DataFile, DataFileContent +from pyiceberg.manifest import DataFile, DataFileContent, FileFormat from pyiceberg.partitioning import PartitionField, PartitionSpec from pyiceberg.schema import Schema from pyiceberg.table.inspect import InspectTable, _readable_bound @@ -76,6 +78,36 @@ def test_inspect_entries_and_files_render_null_bound(catalog: InMemoryCatalog) - assert files_metrics["upper_bound"] is None +def test_inspect_entries_and_files_with_data_file_without_metrics(catalog: InMemoryCatalog, tmp_path: PosixPath) -> None: + # column_sizes and the other metric maps are optional in a data file; DuckDB, for one, + # writes data files without column_sizes. + schema = Schema(NestedField(1, "x", LongType(), required=False)) + tbl = catalog.create_table("default.no_metrics", schema) + file_path = f"{tmp_path.absolute().as_posix()}/a.parquet" + pq.write_table(pa.table({"x": [1]}), file_path) + data_file = DataFile.from_args( + content=DataFileContent.DATA, + file_path=file_path, + file_format=FileFormat.PARQUET, + partition=Record(), + record_count=1, + file_size_in_bytes=os.path.getsize(file_path), + ) + with tbl.transaction() as tx: + with tx.update_snapshot().fast_append() as fast_append: + fast_append.append_data_file(data_file) + + entries = tbl.inspect.entries().to_pylist() + assert len(entries) == 1 + for metric in ("column_sizes", "value_counts", "null_value_counts", "nan_value_counts"): + assert entries[0]["data_file"][metric] == [] + assert entries[0]["readable_metrics"]["x"]["column_size"] is None + + files = tbl.inspect.files().to_pylist() + assert len(files) == 1 + assert files[0]["column_sizes"] is None + + @pytest.mark.parametrize("newest_first", [False, True]) def test_partitions_last_updated_uses_latest_snapshot_regardless_of_order(newest_first: bool) -> None: # Manifest entries are visited in manifest order, which is not chronological, so the From 0ca60c31ff739e666f6885135e6afb6366e71a41 Mon Sep 17 00:00:00 2001 From: Rahul-cs50 Date: Fri, 30 Oct 2026 16:04:47 +0530 Subject: [PATCH 2/4] Shorten the comment in the missing-metrics test --- tests/table/test_inspect.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/table/test_inspect.py b/tests/table/test_inspect.py index f9658d7c1e..a70d79d83c 100644 --- a/tests/table/test_inspect.py +++ b/tests/table/test_inspect.py @@ -79,8 +79,7 @@ def test_inspect_entries_and_files_render_null_bound(catalog: InMemoryCatalog) - def test_inspect_entries_and_files_with_data_file_without_metrics(catalog: InMemoryCatalog, tmp_path: PosixPath) -> None: - # column_sizes and the other metric maps are optional in a data file; DuckDB, for one, - # writes data files without column_sizes. + # column_sizes and the other metric maps are optional in a data file schema = Schema(NestedField(1, "x", LongType(), required=False)) tbl = catalog.create_table("default.no_metrics", schema) file_path = f"{tmp_path.absolute().as_posix()}/a.parquet" From f6eadf17b697a390f5af58ab6838850c05b9de23 Mon Sep 17 00:00:00 2001 From: Kevin Liu Date: Thu, 19 Nov 2026 12:23:10 -0800 Subject: [PATCH 3/4] Set spec_id on the test DataFile The snapshot producer now reads DataFile.spec_id, so the test failed after rebasing onto main. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- tests/table/test_inspect.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/table/test_inspect.py b/tests/table/test_inspect.py index a70d79d83c..73196bed07 100644 --- a/tests/table/test_inspect.py +++ b/tests/table/test_inspect.py @@ -91,6 +91,7 @@ def test_inspect_entries_and_files_with_data_file_without_metrics(catalog: InMem partition=Record(), record_count=1, file_size_in_bytes=os.path.getsize(file_path), + spec_id=tbl.metadata.default_spec_id, ) with tbl.transaction() as tx: with tx.update_snapshot().fast_append() as fast_append: From f712a04180cd8c23af5ac1725f5644f36b1f133d Mon Sep 17 00:00:00 2001 From: Kevin Liu Date: Thu, 19 Nov 2026 12:23:35 -0800 Subject: [PATCH 4/4] Drop the Parquet write from the missing-metrics test inspect only reads manifests, so the data file doesn't need to exist. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- tests/table/test_inspect.py | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/tests/table/test_inspect.py b/tests/table/test_inspect.py index 73196bed07..e507b62f71 100644 --- a/tests/table/test_inspect.py +++ b/tests/table/test_inspect.py @@ -15,12 +15,10 @@ # specific language governing permissions and limitations # under the License. -import os from pathlib import PosixPath from typing import Any import pyarrow as pa -import pyarrow.parquet as pq import pytest from pyiceberg.conversions import to_bytes @@ -78,19 +76,17 @@ def test_inspect_entries_and_files_render_null_bound(catalog: InMemoryCatalog) - assert files_metrics["upper_bound"] is None -def test_inspect_entries_and_files_with_data_file_without_metrics(catalog: InMemoryCatalog, tmp_path: PosixPath) -> None: +def test_inspect_entries_and_files_with_data_file_without_metrics(catalog: InMemoryCatalog) -> None: # column_sizes and the other metric maps are optional in a data file schema = Schema(NestedField(1, "x", LongType(), required=False)) tbl = catalog.create_table("default.no_metrics", schema) - file_path = f"{tmp_path.absolute().as_posix()}/a.parquet" - pq.write_table(pa.table({"x": [1]}), file_path) data_file = DataFile.from_args( content=DataFileContent.DATA, - file_path=file_path, + file_path=f"{tbl.location()}/data/a.parquet", file_format=FileFormat.PARQUET, partition=Record(), record_count=1, - file_size_in_bytes=os.path.getsize(file_path), + file_size_in_bytes=1, spec_id=tbl.metadata.default_spec_id, ) with tbl.transaction() as tx: