Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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
209 changes: 190 additions & 19 deletions api/src/main/java/org/apache/iceberg/UpdateSchema.java

Large diffs are not rendered by default.

30 changes: 28 additions & 2 deletions api/src/main/java/org/apache/iceberg/types/Types.java
Original file line number Diff line number Diff line change
Expand Up @@ -559,15 +559,21 @@ public static Builder optional(String name) {
return new Builder(true, name);
}

public static Builder builder() {
return new Builder();
}

public static class Builder {
private final boolean isOptional;
private final String name;
private boolean isOptional = true;
private String name = null;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These changes enable the builder to handle all updates, even to whether the field is optional and the field name. That way the builder is always used to copy instead of needing to support specific fields when changing the name.

private Integer id = null;
private Type type = null;
private String doc = null;
private Object initialDefault = null;
private Object writeDefault = null;

private Builder() {}

private Builder(boolean isFieldOptional, String fieldName) {
isOptional = isFieldOptional;
name = fieldName;
Expand All @@ -583,6 +589,26 @@ private Builder(NestedField toCopy) {
this.writeDefault = toCopy.writeDefault;
}

public Builder asRequired() {
this.isOptional = false;
return this;
}

public Builder asOptional() {
this.isOptional = true;
return this;
}

public Builder isOptional(boolean fieldIsOptional) {
this.isOptional = fieldIsOptional;
return this;
}

public Builder withName(String fieldName) {
this.name = fieldName;
return this;
}

public Builder withId(int fieldId) {
id = fieldId;
return this;
Expand Down
Loading