Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyiceberg/table/inspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks, this should be optional.

spec reference: https://iceberg.apache.org/spec/#manifest-schema

Screenshot 2026-11-19 at 12 19 42 PM

"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 {}),
Expand Down
30 changes: 29 additions & 1 deletion tests/table/test_inspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
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
Expand Down Expand Up @@ -76,6 +76,34 @@ 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) -> 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)
data_file = DataFile.from_args(
content=DataFileContent.DATA,
file_path=f"{tbl.location()}/data/a.parquet",
file_format=FileFormat.PARQUET,
partition=Record(),
record_count=1,
file_size_in_bytes=1,
spec_id=tbl.metadata.default_spec_id,
)
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
Expand Down
Loading