rdblue commented on code in PR #8147:
URL: https://github.com/apache/iceberg/pull/8147#discussion_r1276780924
##########
core/src/main/java/org/apache/iceberg/view/ViewMetadata.java:
##########
@@ -121,9 +128,178 @@ default ViewMetadata checkAndNormalize() {
versions().subList(versions().size() - versionHistorySizeToKeep,
versions().size());
List<ViewHistoryEntry> history =
history().subList(history().size() - versionHistorySizeToKeep,
history().size());
- return
ImmutableViewMetadata.builder().from(this).versions(versions).history(history).build();
+ return ViewMetadata.buildFrom(this)
+ .discardChanges()
+ .versions(versions)
+ .history(history)
+ .build();
}
return this;
}
+
+ static Builder builder() {
+ return new Builder();
+ }
+
+ static Builder buildFrom(ViewMetadata base) {
+ return new Builder(base);
+ }
+
+ class Builder {
+ private int formatVersion = 1;
+ private String location;
+ private Integer currentSchemaId;
+ private List<Schema> schemas = Lists.newArrayList();
+ private int currentVersionId = 1;
+ private List<ViewVersion> versions = Lists.newArrayList();
+ private List<ViewHistoryEntry> history = Lists.newArrayList();
+ private Map<String, String> properties = Maps.newHashMap();
+ private List<MetadataUpdate> changes = Lists.newArrayList();
+
+ private Builder() {}
+
+ private Builder(ViewMetadata base) {
+ this.formatVersion = base.formatVersion();
+ this.location = base.location();
+ this.currentSchemaId = base.currentSchemaId();
+ this.schemas = Lists.newArrayList(base.schemas());
+ this.currentVersionId = base.currentVersionId();
+ this.versions = Lists.newArrayList(base.versions());
+ this.history = Lists.newArrayList(base.history());
+ this.properties = Maps.newHashMap(base.properties());
+ this.changes = Lists.newArrayList(base.changes());
+ }
+
+ public Builder formatVersion(int newFormatVersion) {
+ this.formatVersion = newFormatVersion;
+ this.changes.add(new
MetadataUpdate.UpgradeFormatVersion(newFormatVersion));
+ return this;
+ }
+
+ public Builder location(String newLocation) {
+ this.location = newLocation;
+ this.changes.add(new MetadataUpdate.SetLocation(newLocation));
+ return this;
+ }
+
+ public Builder currentVersionId(int versionId) {
+ this.currentVersionId = versionId;
+ this.changes.add(new MetadataUpdate.SetCurrentViewVersion(versionId));
+ return this;
+ }
+
+ public Builder currentSchemaId(Integer schemaId) {
+ this.currentSchemaId = schemaId;
+ this.changes.add(new MetadataUpdate.SetCurrentSchema(schemaId));
+ return this;
+ }
+
+ public Builder addSchema(Schema schema) {
+ this.schemas.add(schema);
+ this.changes.add(new MetadataUpdate.AddSchema(schema,
schema.highestFieldId()));
+ return this;
+ }
+
+ public Builder addAllSchemas(Iterable<Schema> schemaEntries) {
+ for (Schema schema : schemaEntries) {
+ this.schemas.add(schema);
+ this.changes.add(new MetadataUpdate.AddSchema(schema,
schema.highestFieldId()));
+ }
+ return this;
+ }
+
+ public Builder schemas(Iterable<Schema> newSchemas) {
Review Comment:
What does this do differently than `addAllSchemas`? Do we need a method that
adds multiple schemas?
--
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]