laskoviymishka commented on code in PR #2753:
URL: https://github.com/apache/iceberg-go/pull/2753#discussion_r4728274531
##########
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:
Could the v2 branch also check the field ID, like the v1 branch does? With
this assertion added, the v2 subtest passes on the head commit.
```suggestion
assert.Equal(t, iceberg.DayTransform{},
newSpec.Field(0).Transform)
assert.Equal(t, iceberg.PartitionDataIDStart+1,
newSpec.Field(0).FieldID)
```
##########
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:
Could we add a v1 case where `ts_transformed_1000` already exists in the
spec? Today that fails with `partition name has to be unique:
ts_transformed_1000` from both `BuildUpdates()` and `Apply()` via
[`checkAndAddPartitionName`](https://github.com/apache/iceberg-go/blob/5bae7135d05998bd5642744298adecb585c10f90/table/update_spec.go#L543-L555),
which seems right since Java's `addField` doesn't guard it either. A test
would pin that.
--
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]