yingjianwu98 commented on code in PR #15084:
URL: https://github.com/apache/iceberg/pull/15084#discussion_r2824943046
##########
core/src/main/java/org/apache/iceberg/SchemaUpdate.java:
##########
@@ -200,6 +190,112 @@ 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(
Review Comment:
I think we probably also want to recover the initialDefault and writeDefault.
##########
core/src/main/java/org/apache/iceberg/SchemaUpdate.java:
##########
@@ -200,6 +190,112 @@ 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(
Review Comment:
I think we probably also want to recover the field initialDefault and
writeDefault.
--
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]