Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ class BaseUpdatePartitionSpec implements UpdatePartitionSpec {
this.schema = spec.schema();
this.nameToField = indexSpecByName(spec);
this.transformToField = indexSpecByTransform(spec);
this.lastAssignedPartitionId = spec.fields().stream().mapToInt(PartitionField::fieldId).max().orElse(999);
this.lastAssignedPartitionId =
base.specs().stream().mapToInt(PartitionSpec::lastAssignedFieldId).max().orElse(999);

spec.fields().stream()
.filter(field -> field.transform() instanceof UnknownTransform)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,4 +196,26 @@ public void testAddAndRemoveField() {
.build(), table.spec());
Assert.assertEquals(1001, table.spec().lastAssignedFieldId());
}

@Test
public void testAddAfterLastFieldRemoved() {
table.updateSpec()
.removeField("data_bucket")
.commit();

table.updateSpec()
.addField(bucket("id", 8))
.commit();

V1Assert.assertEquals("Should add a new id bucket", PartitionSpec.builderFor(table.schema())
.withSpecId(2)
.alwaysNull("data", "data_bucket")
.bucket("id", 8, "id_bucket_8")
.build(), table.spec());
V2Assert.assertEquals("Should add a new id bucket", PartitionSpec.builderFor(table.schema())
.withSpecId(2)
.add(1, 1001, "id_bucket_8", "bucket[8]")
.build(), table.spec());
Assert.assertEquals(1001, table.spec().lastAssignedFieldId());
}
}