ShivamSharma43 opened a new issue, #2752:
URL: https://github.com/apache/iceberg-go/issues/2752
### Apache Iceberg version
main (development)
### Please describe the bug 🐞
On a format v1 table, `UpdateSpec` cannot remove a partition field and add a
new one with the same name in one update.
A v1 spec keeps a removed field as a `void` transform under its old name, so
the new field collides with it. Reproduced on main (9304132), with a v1 table
partitioned by `month(ts)` as `ts_transformed`:
```go
_, _, err := table.NewUpdateSpec(tbl.NewTransaction(), false).
RemoveField("ts_transformed").
AddField("ts", iceberg.DayTransform{}, "ts_transformed").
BuildUpdates()
// invalid partition spec: duplicate partition name: ts_transformed
```
The same update works on a v2 table, where the removed field is dropped from
the spec.
Java renames the removed field out of the way. In
[`BaseUpdatePartitionSpec.addField`](https://github.com/apache/iceberg/blob/ce1ce419f90354a86ea7a8d7552f8418e4da7a1a/core/src/main/java/org/apache/iceberg/BaseUpdatePartitionSpec.java#L223-L234),
when the new name belongs to a field deleted in the same update, it adds a
rename to `<name>_<field-id>`:
```java
} else if (existingField != null &&
deletes.contains(existingField.fieldId())) {
renames.put(existingField.name(), existingField.name() + "_" +
existingField.fieldId());
}
```
[`TestUpdatePartitionSpec.testRemoveAndUpdateWithDifferentTransformation`](https://github.com/apache/iceberg/blob/ce1ce419f90354a86ea7a8d7552f8418e4da7a1a/core/src/test/java/org/apache/iceberg/TestUpdatePartitionSpec.java#L638-L659)
covers this exact case: on v1 the result is `ts_transformed_1000: void(ts)`
followed by `ts_transformed: day(ts)`.
iceberg-go's `addField` (`table/update_spec.go`) only handles a name that
matches a field which is not being deleted. `Apply` already applies renames to
v1 void fields, so the missing piece is recording the rename.
I'd like to work on this. I have a fix and tests ready.
--
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]