ShivamSharma43 commented on code in PR #2753:
URL: https://github.com/apache/iceberg-go/pull/2753#discussion_r4731084834


##########
table/update_spec.go:
##########
@@ -373,6 +375,12 @@ func (us *UpdateSpec) addField(sourceColName string, 
transform iceberg.Transform
                        } else {
                                return fmt.Errorf("cannot add duplicate 
partition field name: %s", existingPartitionField.Name)
                        }
+               case exists && inDelete:
+                       // The new field reuses the name of a field removed in 
this update.
+                       // A v1 spec keeps the removed field as a void 
transform, so move it
+                       // out of the way, as Java's 
BaseUpdatePartitionSpec.addField does.
+                       us.renames[existingPartitionField.Name] = 
fmt.Sprintf("%s_%d",

Review Comment:
   Added in 92d34a1: `TestUpdateSpecRemoveAndAddWithSameNameRenameTargetTaken` 
starts from a v1 spec that already has `ts_transformed_1000`, and checks that 
both `BuildUpdates()` and a following `Apply()` fail with `partition name has 
to be unique: ts_transformed_1000`.



##########
table/update_spec_test.go:
##########
@@ -244,6 +246,48 @@ func 
TestUpdateSpecReplacesTimeTransformOverV1VoidTombstone(t *testing.T) {
        assert.Equal(t, 3, newSpec.Field(1).FirstSourceID())
 }
 
+// Mirrors Java's 
TestUpdatePartitionSpec.testRemoveAndUpdateWithDifferentTransformation.
+func TestUpdateSpecRemoveAndAddWithSameName(t *testing.T) {
+       for _, formatVersion := range []int{1, 2} {
+               t.Run(fmt.Sprintf("v%d", formatVersion), func(t *testing.T) {
+                       baseSpec := 
iceberg.NewPartitionSpec(iceberg.PartitionField{
+                               SourceIDs: []int{3},
+                               FieldID:   iceberg.PartitionDataIDStart,
+                               Name:      "ts_transformed",
+                               Transform: iceberg.MonthTransform{},
+                       })
+                       meta, err := table.NewMetadata(testSchema, &baseSpec, 
table.UnsortedSortOrder, "",
+                               iceberg.Properties{"format-version": 
strconv.Itoa(formatVersion)})
+                       require.NoError(t, err)
+                       require.Equal(t, formatVersion, meta.FormatVersion())
+                       tbl := table.New([]string{"month_partitioned"}, meta, 
"", nil, nil)
+
+                       specUpdate := table.NewUpdateSpec(tbl.NewTransaction(), 
false).
+                               RemoveField("ts_transformed").
+                               AddField("ts", iceberg.DayTransform{}, 
"ts_transformed")
+                       _, _, err = specUpdate.BuildUpdates()
+                       require.NoError(t, err)
+
+                       newSpec, err := specUpdate.Apply()
+                       require.NoError(t, err)
+
+                       if formatVersion == 1 {
+                               require.Equal(t, 2, newSpec.NumFields())
+                               assert.Equal(t, "ts_transformed_1000", 
newSpec.Field(0).Name)
+                               assert.Equal(t, iceberg.PartitionDataIDStart, 
newSpec.Field(0).FieldID)
+                               assert.Equal(t, iceberg.VoidTransform{}, 
newSpec.Field(0).Transform)
+                               assert.Equal(t, "ts_transformed", 
newSpec.Field(1).Name)
+                               assert.Equal(t, iceberg.PartitionDataIDStart+1, 
newSpec.Field(1).FieldID)
+                               assert.Equal(t, iceberg.DayTransform{}, 
newSpec.Field(1).Transform)
+                       } else {
+                               require.Equal(t, 1, newSpec.NumFields())
+                               assert.Equal(t, "ts_transformed", 
newSpec.Field(0).Name)
+                               assert.Equal(t, iceberg.DayTransform{}, 
newSpec.Field(0).Transform)

Review Comment:
   Done in 92d34a1: the v2 branch now also checks that the new field gets ID 
`PartitionDataIDStart+1`.



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