Skip to content

dynamic_partition_overwrite after an in-transaction update_spec loses rows #4192

Open

Description

@RyanLin5967

Apache Iceberg version

0.12.0 (latest release)

Please describe the bug 🐞

Currently, Transaction.dynamic_partition_overwrite partitions its files with the committed spec but builds its delete filter with the transaction's, so the new row's a = 1 is read as b = 1 and the row with b = 1 is deleted. Committing update_spec first gives the right rows.

import tempfile
import pyarrow as pa
from pyiceberg.catalog.sql import SqlCatalog
from pyiceberg.partitioning import PartitionField, PartitionSpec
from pyiceberg.schema import Schema
from pyiceberg.transforms import IdentityTransform
from pyiceberg.types import LongType, NestedField

cat = SqlCatalog("c", uri="sqlite:///:memory:", warehouse=f"file://{tempfile.mkdtemp()}")
cat.create_namespace("ns")
schema = Schema(NestedField(1, "a", LongType()), NestedField(2, "b", LongType()))
t = cat.create_table("ns.t", schema=schema, partition_spec=PartitionSpec(PartitionField(1, 1000, IdentityTransform(), "a")))
df = lambda *rs: pa.Table.from_pylist([{"a": a, "b": b} for a, b in rs], schema=schema.as_arrow())
t.append(df((1, 9), (2, 1)))

with t.transaction() as tx:
    with tx.update_spec() as u:
        u.remove_field("a")
        u.add_identity("b")
    tx.dynamic_partition_overwrite(df((1, 2)))

rows = lambda f="True": sorted((r["a"], r["b"]) for r in t.scan(row_filter=f).to_arrow().to_pylist())
print(rows())
# [(1, 2), (1, 9)], should be [(1, 2), (1, 9), (2, 1)]
print(rows("b == 2"))
# [], should be [(1, 2)]
# the new file is recorded under b = 1, its a value

After an in-transaction add_column it raises ValueError: Could not find field with name: w.

tested on pyiceberg 0.12.0 and main

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions