rdblue commented on a change in pull request #922:
URL: https://github.com/apache/iceberg/pull/922#discussion_r435431020
##########
File path: api/src/main/java/org/apache/iceberg/PartitionSpec.java
##########
@@ -476,11 +482,52 @@ Builder add(int sourceId, int fieldId, String name,
String transform) {
Types.NestedField column = schema.findField(sourceId);
checkAndAddPartitionName(name, column.fieldId());
Preconditions.checkNotNull(column, "Cannot find source column: %s",
sourceId);
+ checkDuplicateFieldId(fieldId);
fields.add(new PartitionField(sourceId, fieldId, name,
Transforms.fromString(column.type(), transform)));
lastAssignedFieldId.getAndAccumulate(fieldId, Math::max);
return this;
}
+ Builder rename(String name, String newName) {
+ Preconditions.checkArgument(partitionNames.contains(name),
+ "Cannot find an existing partition field with the name: %s", name);
+ Preconditions.checkArgument(newName != null && !newName.isEmpty(),
+ "Cannot use empty or null partition name: %s", newName);
+ Preconditions.checkArgument(!partitionNames.contains(newName),
+ "Cannot use partition name more than once: %s", newName);
+
+ for (int i = 0; i < fields.size(); ++i) {
+ PartitionField field = fields.get(i);
+ if (field.name().equals(name)) {
+ fields.set(i, new PartitionField(field.sourceId(), field.fieldId(),
newName, field.transform()));
+ partitionNames.remove(name);
+ partitionNames.add(newName);
+ break;
+ }
+ }
+ return this;
+ }
+
+ int remove(String name, boolean softDelete) {
Review comment:
I don't think that we need to change this API. This is for creating new
partition specs, so it doesn't make much sense to create a field and then
remove or rename it.
Changing a partition spec should be handled by the update operation and it
is cleaner to keep that logic separate.
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]