RyanLin5967 opened a new issue, #4190:
URL: https://github.com/apache/iceberg-python/issues/4190

   ### Apache Iceberg version
   
   0.12.0 (latest release)
   
   ### Please describe the bug 🐞
   
   Currently, `UpdateSchema` commits with only `AssertCurrentSchemaId`, so 
after another writer adds and drops a column, a stale handle's `add_column` 
passes the check and reuses the dropped column's field id and schema id. A 
handle loaded after the drop gives `y` field id 3.
   
   ```python
   import tempfile
   import pyarrow as pa
   from pyiceberg.catalog.sql import SqlCatalog
   from pyiceberg.types import StringType
   
   cat = SqlCatalog("c", uri="sqlite:///:memory:", 
warehouse=f"file://{tempfile.mkdtemp()}")
   cat.create_namespace("ns")
   cat.create_table("ns.t", schema=pa.schema([("k", pa.int64())]))
   
   a = cat.load_table("ns.t")
   b = cat.load_table("ns.t")
   with b.update_schema() as u:
       u.add_column("x", StringType())
   b.append(pa.table({"k": [1], "x": ["a"]}))
   with b.update_schema() as u:
       u.delete_column("x")
   
   with a.update_schema() as u:
       u.add_column("y", StringType())
   # commits, should raise CommitFailedException as the last assigned field id 
changed
   
   t = cat.load_table("ns.t")
   print(t.scan().to_arrow().to_pylist())
   # [{'k': 1, 'x': 'a'}]: the dropped column is back with its data, and y is 
gone
   print([(s.schema_id, [(f.field_id, f.name) for f in s.fields]) for s in 
t.metadata.schemas])
   # [(0, [(1, 'k')]), (1, [(1, 'k'), (2, 'x')]), (1, [(1, 'k'), (2, 'y')])]
   # y took field id 2 and schema id 1, both already x's
   ```
   
   Iceberg Java 1.12.0 then cannot load the table: `IllegalArgumentException: 
Multiple entries with same key: 1=table {`. Java's `UpdateRequirements` adds 
`AssertLastAssignedFieldId` whenever a commit adds a schema; pyiceberg defines 
it but never sends it.
   
   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


-- 
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]

Reply via email to