fbertsch commented on code in PR #15084:
URL: https://github.com/apache/iceberg/pull/15084#discussion_r2706704944
##########
core/src/main/java/org/apache/iceberg/SchemaUpdate.java:
##########
@@ -200,6 +200,117 @@ public UpdateSchema deleteColumn(String name) {
return this;
}
+ @Override
+ public UpdateSchema undeleteColumn(String name) {
+ Types.NestedField existingField = findField(name);
+ Preconditions.checkArgument(
+ existingField == null,
+ "Cannot undelete column '%s': a column with this name already exists
in the current schema",
+ name);
+
+ Preconditions.checkArgument(
+ base != null,
+ "Cannot undelete column: table metadata is required to access
historical schemas");
+
+ DeletedColumnInfo deletedInfo = findDeletedColumn(name);
+ Preconditions.checkArgument(
+ deletedInfo != null,
+ "Cannot undelete column '%s': column not found in any historical
schema",
+ name);
+
+ int parentId = deletedInfo.parentId;
+ Types.NestedField originalField = deletedInfo.field;
+
+ // undeleted columns are always optional since new data may not have values
+ Types.NestedField field =
+ Types.NestedField.optional(
+ originalField.fieldId(),
+ originalField.name(),
+ originalField.type(),
+ originalField.doc());
+
+ if (parentId != TABLE_ROOT_ID) {
+ idToParent.put(field.fieldId(), parentId);
+ }
+
+ updates.put(field.fieldId(), field);
+ parentToAddedIds.put(parentId, field.fieldId());
+ addedNameToId.put(name, field.fieldId());
+
+ return this;
+ }
+
+ private static class DeletedColumnInfo {
Review Comment:
This class feels unnecessary - I'll remove it tomorrow in favor of a record
--
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]