`add_column` changes the values of an existing column for files without field IDs

Offen
#4,318 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Maintainer antworten meist innerhalb von 1 Tag

@Anurag-S1ngh arbeitet bereits daran.

Seit 10.11.2026.

  • #4332 von @Anurag-S1ngh — offen

Bewertung

Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Anfängerfreundlichkeit
57/100
Issue-Typ
Bug
Klarheit
Größtenteils klar
Aktivitätsstatus
Aktiv
Tech-Stack
postgresql, python
Bereich
database

Rechercherichtung

Start with _remove_reassigned_names in pyiceberg/table/name_mapping.py and trace how schema updates change name mappings for files without field IDs. Reproduce the report using the supplied add_files, rename, and add_column sequence, then check both scan results and IsNull("b") filtering. Done means the existing column keeps its values and the filter returns the matching rows after adding the reused name.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

Apache Iceberg version

0.12.0 (latest release); the same logic is on main

Please describe the bug 🐞

Adding a column changes what an existing column reads. Files added with add_files have no field IDs and are read through the name mapping. After a rename, the renamed column reads correctly. Adding a column that reuses the old name then moves that name to the new field in the mapping (_remove_reassigned_names in pyiceberg/table/name_mapping.py). From then on, the renamed column reads as null for those files, and the new column gets its values.

The manifest statistics of those files still describe the original field, so planning also prunes with statistics that no longer match what is read: below, IsNull("b") skips the file although both rows read b as null.

import tempfile

import pyarrow as pa
import pyarrow.parquet as pq
from pyiceberg.catalog.sql import SqlCatalog
from pyiceberg.expressions import IsNull
from pyiceberg.schema import Schema
from pyiceberg.types import LongType, NestedField

d = tempfile.mkdtemp()
catalog = SqlCatalog("c", uri=f"sqlite:///{d}/c.db", warehouse=f"file://{d}")
catalog.create_namespace("ns")
table = catalog.create_table("ns.t", Schema(NestedField(1, "a", LongType())))

# a Parquet file without field IDs, read through the name mapping
pq.write_table(pa.table({"a": [1, 3]}), f"{d}/imported.parquet")
table.add_files([f"file://{d}/imported.parquet"])

with table.update_schema() as update:
    update.rename_column("a", "b")
print(table.scan().to_arrow().to_pydict())
# {'b': [1, 3]}

with table.update_schema() as update:
    update.add_column("a", LongType())
print(table.scan().to_arrow().to_pydict())
# {'b': [None, None], 'a': [1, 3]}: expected {'b': [1, 3], 'a': [None, None]}

print(table.scan(row_filter=IsNull("b")).to_arrow().num_rows)
# 0: the file is pruned by the statistics of `b`, which hold its original values

Expected: adding a column leaves the values of existing columns unchanged, as it does for files with field IDs. The name was written for the original field in those files, so either the mapping keeps it there, or adding a column whose name files without field IDs still use is refused.

Willingness to contribute
  • I can contribute a fix for this bug independently
  • I would be willing to contribute a fix for this bug with guidance from the Iceberg community
  • I cannot contribute a fix for this bug at this time
Vorherrschende Sprache
Python
Sterne
1.2k
Forks
654
Ø Merge
2 T. 11 Std.
Gemergte PRs (30 T.)
122

Entwicklungsumgebung

  • Kein Dockerfile und keine Docker-Compose-Datei
  • Hat eine Pull-Request-Vorlage
  • Kein Beitragsleitfaden

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus apache/iceberg-python

Alle Issues in apache/iceberg-python

Ähnliche Issues

Weitere Issues zu Python

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.