DG47 opened a new issue, #4536:
URL: https://github.com/apache/iceberg-python/issues/4536
### Apache Iceberg version
main (7864d4c)
### Please describe the bug 🐞
Appending to a table whose partition spec has more than one field on the
same source column fails with `ValueError: Cannot have redundant partitions`.
Overwrites, and deletes that rewrite part of a data file, fail the same way.
Such specs are valid. Java and Spark accept `bucket(id)` plus
`truncate(id)`, and a format v1 table ends up with one whenever a partition
field on a column is replaced, for example to change the number of buckets,
because the removed field stays in the spec as a `void` transform of that
column.
```python
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 BucketTransform, TruncateTransform
from pyiceberg.types import LongType, NestedField, StringType
warehouse = tempfile.mkdtemp()
catalog = SqlCatalog("default", uri=f"sqlite:///{warehouse}/catalog.db",
warehouse=f"file://{warehouse}")
catalog.create_namespace("default")
schema = Schema(NestedField(1, "id", LongType(), required=False),
NestedField(2, "name", StringType(), required=False))
data = pa.table({"id": pa.array([1, 2, 13], pa.int64()), "name": ["a", "b",
"c"]})
# Two transforms of the same column
tbl = catalog.create_table(
"default.bucket_and_truncate",
schema=schema,
partition_spec=PartitionSpec(
PartitionField(source_id=1, field_id=1000,
transform=BucketTransform(4), name="id_bucket"),
PartitionField(source_id=1, field_id=1001,
transform=TruncateTransform(10), name="id_trunc"),
),
)
tbl.append(data)
# ValueError: Cannot have redundant partitions: [PartitionField(source_id=1,
field_id=1000, transform=BucketTransform(num_buckets=4), name='id_bucket'),
PartitionField(source_id=1, field_id=1001,
transform=TruncateTransform(width=10), name='id_trunc')]
# Format v1 table after changing the bucket count
tbl = catalog.create_table(
"default.replaced_bucket_v1",
schema=schema,
partition_spec=PartitionSpec(PartitionField(source_id=1, field_id=1000,
transform=BucketTransform(4), name="id_bucket")),
properties={"format-version": "1"},
)
tbl.append(data)
with tbl.update_spec() as update:
update.remove_field("id_bucket")
update.add_field("id", BucketTransform(8), "id_bucket_8")
tbl.append(data)
# ValueError: Cannot have redundant partitions: [PartitionField(source_id=1,
field_id=1000, transform=VoidTransform(), name='id_bucket'),
PartitionField(source_id=1, field_id=1001,
transform=BucketTransform(num_buckets=8), name='id_bucket_8')]
```
Expected: both appends succeed and each data file gets one partition value
per partition field, as Java writes them.
Actual: the `ValueError` above, raised from `PartitionKey.partition` in
`pyiceberg/partitioning.py`. The second table can no longer be written by
PyIceberg once its spec has changed.
Environment: PyIceberg main (7864d4c), pyarrow 25.0.1, pyiceberg-core
0.10.1, Python 3.12.13, macOS.
### Willingness to contribute
- [x] 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]