RyanLin5967 opened a new issue, #4187:
URL: https://github.com/apache/iceberg-python/issues/4187
### Apache Iceberg version
0.12.0 (latest release)
### Please describe the bug 🐞
Currently, `create_branch` and `create_tag` set the ref without checking
whether it exists, so an existing branch is reset and loses its commits, and a
tag moves. Java refuses an existing name with `Ref dev already exists`.
```python
import tempfile
import pyarrow as pa
from pyiceberg.catalog.sql import SqlCatalog
cat = SqlCatalog("c", uri="sqlite:///:memory:",
warehouse=f"file://{tempfile.mkdtemp()}")
cat.create_namespace("ns")
t = cat.create_table("ns.t", schema=pa.schema([("x", pa.int64())]))
t.append(pa.table({"x": [1]}))
s1 = t.current_snapshot().snapshot_id
t.manage_snapshots().create_branch(s1, "dev").create_tag(s1, "v1").commit()
t.append(pa.table({"x": [2]}), branch="dev")
t.append(pa.table({"x": [3]}))
t.manage_snapshots().create_branch(s1, "dev").commit()
print(t.scan().use_ref("dev").to_arrow()["x"].to_pylist())
# [1], should raise; the commit holding 2 is now on no ref
t.manage_snapshots().create_tag(t.current_snapshot().snapshot_id,
"v1").commit()
print(sorted(t.scan().use_ref("v1").to_arrow()["x"].to_pylist()))
# [1, 3], should raise and leave v1 at [1]
```
`remove_branch` and `remove_tag` check nothing either:
`remove_branch("main")` is accepted and the table then reads as empty.
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]