ShivamSharma43 opened a new pull request, #2753:
URL: https://github.com/apache/iceberg-go/pull/2753

   On a format v1 table, `UpdateSpec` failed when one update removed a 
partition field and added a new one with the same name:
   
   ```go
   table.NewUpdateSpec(txn, false).
        RemoveField("ts_transformed").
        AddField("ts", iceberg.DayTransform{}, "ts_transformed")
   // invalid partition spec: duplicate partition name: ts_transformed
   ```
   
   ### Cause
   
   A v1 spec keeps a removed field as a `void` transform under its old name. 
`addField` only checked for a name clash with a field that is *not* being 
deleted, so the void tombstone and the new field ended up with the same name 
and `Apply` rejected the spec.
   
   ### Fix
   
   When the new field's name belongs to a field removed in the same update, 
`addField` now records a rename of the removed field to `<name>_<field-id>`. 
`Apply` already applies renames to v1 void fields, so the result is 
`ts_transformed_1000: void(ts)` followed by `ts_transformed: day(ts)`. On v2 
the removed field is dropped, so the rename has no effect.
   
   This matches Java's 
[`BaseUpdatePartitionSpec.addField`](https://github.com/apache/iceberg/blob/ce1ce419f90354a86ea7a8d7552f8418e4da7a1a/core/src/main/java/org/apache/iceberg/BaseUpdatePartitionSpec.java#L223-L234):
   
   ```java
   } else if (existingField != null && 
deletes.contains(existingField.fieldId())) {
     renames.put(existingField.name(), existingField.name() + "_" + 
existingField.fieldId());
   }
   ```
   
   ### Testing
   
   - `TestUpdateSpecRemoveAndAddWithSameName` in `table/update_spec_test.go` 
ports Java's 
[`testRemoveAndUpdateWithDifferentTransformation`](https://github.com/apache/iceberg/blob/ce1ce419f90354a86ea7a8d7552f8418e4da7a1a/core/src/test/java/org/apache/iceberg/TestUpdatePartitionSpec.java#L638-L659)
 for v1 and v2. On v1 it checks the void field `ts_transformed_1000` (field ID 
1000) and the new `ts_transformed: day` (field ID 1001); on v2 it checks the 
single `day` field. The v1 case fails on main with the error above and passes 
with the fix.
   - `go test ./table/ -run 'TestUpdateSpec|TestUpdatePartition|Spec'` passes. 
On a full `go test ./table/` run, 32 tests fail on Windows with `parse 
"file://D:\..."`: invalid port` errors from the temp-dir path; none are 
partition spec tests, and they are unrelated to this change.
   - `gofmt`, `go vet ./table/` and `golangci-lint run ./table/` are clean.
   
   Closes #2752
   
   This PR was prepared with AI assistance (Claude Code).
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)
   


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