1fanwang opened a new pull request, #4475: URL: https://github.com/apache/iceberg-python/pull/4475
# Rationale for this change Requesting dictionary encoding on a streaming scan dropped the Iceberg field ID for that column. Saving the result to Parquet preserved the values but lost the column's identity. The same export without dictionary encoding kept the ID. The reader now takes the dictionary type from the first batch and retains the field from the projected schema. The encoding fix in https://github.com/apache/iceberg-python/pull/3595 still applies. ## Are these changes tested? ### End-to-end testing With the PyArrow and SQLite extras installed, run the reproducer from the checkout: ``` PYTHONPATH=. python -B repro.py ``` Before, the dictionary-enabled column could not be converted back to an Iceberg field. Output and final exception: ``` dictionary=False, field ID=b'2' round-trip field ID=2, rows=2 dictionary=True, field ID=None ValueError: Parquet file does not have field-ids and the Iceberg table does not have 'schema.name-mapping.default' defined ``` After: ``` dictionary=False, field ID=b'2' round-trip field ID=2, rows=2 dictionary=True, field ID=b'2' round-trip field ID=2, rows=2 ``` <details><summary>Reproducer source: repro.py</summary> ```python from pathlib import Path from tempfile import TemporaryDirectory import pyarrow as pa import pyarrow.parquet as pq from pyiceberg.catalog.sql import SqlCatalog from pyiceberg.io.pyarrow import PYARROW_PARQUET_FIELD_ID_KEY, pyarrow_to_schema from pyiceberg.schema import Schema from pyiceberg.types import IntegerType, NestedField, StringType with TemporaryDirectory() as tmp: directory = Path(tmp) catalog = SqlCatalog("demo", uri="sqlite://", warehouse=directory.as_uri()) catalog.create_namespace("demo") table = catalog.create_table( identifier="demo.samples", schema=Schema(NestedField(1, "id", IntegerType()), NestedField(2, "kind", StringType())), ) table.append(pa.table({"id": pa.array([1, 2], type=pa.int32()), "kind": ["a", "b"]})) for columns in [(), ("kind",)]: rows = table.scan().to_arrow_batch_reader(dictionary_columns=columns).read_all() field = rows.schema.field("kind") print(f"dictionary={pa.types.is_dictionary(field.type)}, field ID={(field.metadata or {}).get(PYARROW_PARQUET_FIELD_ID_KEY)}") path = directory / "scan.parquet" pq.write_table(table=rows, where=path) converted = pyarrow_to_schema(pq.read_schema(path)) print(f"round-trip field ID={converted.find_field('kind').field_id}, rows={rows.num_rows}") ``` </details> ## Are there any user-facing changes? Parquet exports from dictionary-enabled batch scans keep the same field IDs as plain scans. AI disclosure: GitHub Copilot CLI drafted the fix and regression assertion. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
