You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@iceberg.apache.org by GitBox <gi...@apache.org> on 2019/10/30 21:04:04 UTC

[GitHub] [incubator-iceberg] rdblue commented on a change in pull request #574: Add incompatible changes to UpdateSchema API

rdblue commented on a change in pull request #574: Add incompatible changes to UpdateSchema API
URL: https://github.com/apache/incubator-iceberg/pull/574#discussion_r340857143
 
 

 ##########
 File path: core/src/main/java/org/apache/iceberg/SchemaUpdate.java
 ##########
 @@ -144,30 +167,71 @@ public UpdateSchema renameColumn(String name, String newName) {
     int fieldId = field.fieldId();
     Types.NestedField update = updates.get(fieldId);
     if (update != null) {
-      updates.put(fieldId, required(fieldId, newName, update.type(), update.doc()));
+      updates.put(fieldId, Types.NestedField.of(fieldId, update.isOptional(), newName, update.type(), update.doc()));
     } else {
-      updates.put(fieldId, required(fieldId, newName, field.type(), field.doc()));
+      updates.put(fieldId, Types.NestedField.of(fieldId, field.isOptional(), newName, field.type(), field.doc()));
     }
 
     return this;
   }
 
+  @Override
+  public UpdateSchema requireColumn(String name) {
+    internalUpdateColumnRequirement(name, false);
+    return this;
+  }
+
+  @Override
+  public UpdateSchema makeColumnOptional(String name) {
+    internalUpdateColumnRequirement(name, true);
+    return this;
+  }
+
+  private void internalUpdateColumnRequirement(String name, boolean isOptional) {
+    Types.NestedField field = schema.findField(name);
+    Preconditions.checkArgument(field != null, "Cannot update missing column: %s", name);
+
+    if ((!isOptional && field.isRequired()) || (isOptional && field.isOptional())) {
+      // if the change is a noop, avoid failing if it updating to required is not allowed
 
 Review comment:
   Updated to "If the change is a noop, allow it even if allowIncompatibleChanges is false".

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org