Anurag-S1ngh commented on code in PR #19275:
URL: https://github.com/apache/iceberg/pull/19275#discussion_r4811331222
##########
core/src/main/java/org/apache/iceberg/BaseUpdatePartitionSpec.java:
##########
@@ -143,6 +143,20 @@ private PartitionField recycleOrCreatePartitionField(
sourceTransform.first(), assignFieldId(), name,
sourceTransform.second());
}
+ private boolean canRecycle(PartitionField field) {
+ for (PartitionField current : spec.fields()) {
+ if (deletes.contains(current.fieldId())) {
+ continue;
+ }
+
+ if (current.fieldId() == field.fieldId() ||
current.name().equals(field.name())) {
Review Comment:
Exempted void fields from the name check in `canRecycle`, since `addField`
already renames them, and added a test that re-adds a dropped field and asserts
the same id, name, and transform are reused.
##########
core/src/main/java/org/apache/iceberg/BaseUpdatePartitionSpec.java:
##########
@@ -143,6 +143,20 @@ private PartitionField recycleOrCreatePartitionField(
sourceTransform.first(), assignFieldId(), name,
sourceTransform.second());
}
+ private boolean canRecycle(PartitionField field) {
+ for (PartitionField current : spec.fields()) {
+ if (deletes.contains(current.fieldId())) {
+ continue;
+ }
+
+ if (current.fieldId() == field.fieldId() ||
current.name().equals(field.name())) {
+ return false;
+ }
+ }
+
+ return !nameToAddedField.containsKey(field.name());
Review Comment:
`canRecycle` now also checks `adds` for a field id that is already pending
in the same update.
##########
core/src/test/java/org/apache/iceberg/TestUpdatePartitionSpec.java:
##########
@@ -656,6 +657,55 @@ public void
testRemoveAndUpdateWithDifferentTransformation() {
}
}
+ @Test
+ public void testAddDroppedPartitionFieldWithConflictingId() {
+ assumeThat(formatVersion).isEqualTo(1);
+
+ Schema schema =
+ new Schema(
+ Types.NestedField.required(1, "id", Types.IntegerType.get()),
+ Types.NestedField.optional(2, "p", Types.IntegerType.get()));
+ TestTables.clearTables();
+ TestTables.TestTable table =
+ create(schema, PartitionSpec.builderFor(schema).identity("p").build());
+
+ table.updateSpec().removeField("p").commit();
+ table.updateProperties().set(TableProperties.FORMAT_VERSION, "2").commit();
+ table.updateSpec().addField("p").commit();
+
+ PartitionSpec spec = table.spec();
+ assertThat(spec.fields()).hasSize(2);
+
assertThat(spec.fields().stream().map(PartitionField::fieldId).distinct().count()).isEqualTo(2);
Review Comment:
Added `testReAddDroppedPartitionFieldReusesId`, which checks the actual
field id, name, and transform after a drop and re-add.
--
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]