-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Add table metadata builder #3664
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
671dcb3
Add TableMetadata builder and implement schema updates.
rdblue 83eb825
Support version, location, and current snapshot updates.
rdblue ef88a2d
Add spec and sort order to metadata builder.
rdblue d3fb65e
Add remove snapshots to builder.
rdblue b9eadcb
Add set and remove properties.
rdblue 88ecebd
Fix remaining tests.
rdblue e356332
Add changes to TableMetadata and fix up snapshot log.
rdblue b0ac44f
Move UUID assignment to TableMetadata builder.
rdblue 32795bf
Move MetadataUpdate to top level.
rdblue 65f506b
Use Immutable collections in TableMetadata produced by the builder.
rdblue 5dd0039
Remove duplicate call to addSnapshot.
rdblue 72e9e04
Update NessieTableOperations to use TableMetadata builder.
rdblue 9cbc19e
Fix build checks.
rdblue 8a19674
Fix replace table snapshot history.
rdblue File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -240,13 +240,10 @@ public void commitTransaction() { | |
| } | ||
|
|
||
| private void commitCreateTransaction() { | ||
| // fix up the snapshot log, which should not contain intermediate snapshots | ||
| TableMetadata createMetadata = current.removeSnapshotLogEntries(intermediateSnapshotIds); | ||
|
|
||
| // this operation creates the table. if the commit fails, this cannot retry because another | ||
| // process has created the same table. | ||
| try { | ||
| ops.commit(null, createMetadata); | ||
| ops.commit(null, current); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Transactions no longer need to clean up the snapshot log. That cleanup is done in |
||
|
|
||
| } catch (RuntimeException e) { | ||
| // the commit failed and no files were committed. clean up each update. | ||
|
|
@@ -271,9 +268,7 @@ private void commitCreateTransaction() { | |
| } | ||
|
|
||
| private void commitReplaceTransaction(boolean orCreate) { | ||
| // fix up the snapshot log, which should not contain intermediate snapshots | ||
| TableMetadata replaceMetadata = current.removeSnapshotLogEntries(intermediateSnapshotIds); | ||
| Map<String, String> props = base != null ? base.properties() : replaceMetadata.properties(); | ||
| Map<String, String> props = base != null ? base.properties() : current.properties(); | ||
|
|
||
| try { | ||
| Tasks.foreach(ops) | ||
|
|
@@ -300,7 +295,7 @@ private void commitReplaceTransaction(boolean orCreate) { | |
| this.base = underlyingOps.current(); // just refreshed | ||
| } | ||
|
|
||
| underlyingOps.commit(base, replaceMetadata); | ||
| underlyingOps.commit(base, current); | ||
| }); | ||
|
|
||
| } catch (RuntimeException e) { | ||
|
|
@@ -358,7 +353,7 @@ private void commitSimpleTransaction() { | |
| } | ||
|
|
||
| // fix up the snapshot log, which should not contain intermediate snapshots | ||
| underlyingOps.commit(base, current.removeSnapshotLogEntries(intermediateSnapshotIds)); | ||
| underlyingOps.commit(base, current); | ||
| }); | ||
|
|
||
| } catch (RuntimeException e) { | ||
|
|
||
203 changes: 203 additions & 0 deletions
203
core/src/main/java/org/apache/iceberg/MetadataUpdate.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,203 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
|
|
||
| package org.apache.iceberg; | ||
|
|
||
| import java.io.Serializable; | ||
| import java.util.Map; | ||
| import java.util.Set; | ||
|
|
||
| /** | ||
| * Represents a change to table metadata. | ||
| */ | ||
| public interface MetadataUpdate extends Serializable { | ||
| class AssignUUID implements MetadataUpdate { | ||
| private final String uuid; | ||
|
|
||
| public AssignUUID(String uuid) { | ||
| this.uuid = uuid; | ||
| } | ||
|
|
||
| public String uuid() { | ||
| return uuid; | ||
| } | ||
| } | ||
|
|
||
| class UpgradeFormatVersion implements MetadataUpdate { | ||
| private final int formatVersion; | ||
|
|
||
| public UpgradeFormatVersion(int formatVersion) { | ||
| this.formatVersion = formatVersion; | ||
| } | ||
|
|
||
| public int formatVersion() { | ||
| return formatVersion; | ||
| } | ||
| } | ||
|
|
||
| class AddSchema implements MetadataUpdate { | ||
| private final Schema schema; | ||
| private final int lastColumnId; | ||
|
|
||
| public AddSchema(Schema schema, int lastColumnId) { | ||
| this.schema = schema; | ||
| this.lastColumnId = lastColumnId; | ||
| } | ||
|
|
||
| public Schema schema() { | ||
| return schema; | ||
| } | ||
|
|
||
| public int lastColumnId() { | ||
| return lastColumnId; | ||
| } | ||
| } | ||
|
|
||
| class SetCurrentSchema implements MetadataUpdate { | ||
| private final int schemaId; | ||
|
|
||
| public SetCurrentSchema(int schemaId) { | ||
| this.schemaId = schemaId; | ||
| } | ||
|
|
||
| public int schemaId() { | ||
| return schemaId; | ||
| } | ||
| } | ||
|
|
||
| class AddPartitionSpec implements MetadataUpdate { | ||
| private final PartitionSpec spec; | ||
|
|
||
| public AddPartitionSpec(PartitionSpec spec) { | ||
| this.spec = spec; | ||
| } | ||
|
|
||
| public PartitionSpec spec() { | ||
| return spec; | ||
| } | ||
| } | ||
|
|
||
| class SetDefaultPartitionSpec implements MetadataUpdate { | ||
| private final int specId; | ||
|
|
||
| public SetDefaultPartitionSpec(int schemaId) { | ||
| this.specId = schemaId; | ||
| } | ||
|
|
||
| public int specId() { | ||
| return specId; | ||
| } | ||
| } | ||
|
|
||
| class AddSortOrder implements MetadataUpdate { | ||
| private final SortOrder sortOrder; | ||
|
|
||
| public AddSortOrder(SortOrder sortOrder) { | ||
| this.sortOrder = sortOrder; | ||
| } | ||
|
|
||
| public SortOrder spec() { | ||
| return sortOrder; | ||
| } | ||
| } | ||
|
|
||
| class SetDefaultSortOrder implements MetadataUpdate { | ||
| private final int sortOrderId; | ||
|
|
||
| public SetDefaultSortOrder(int sortOrderId) { | ||
| this.sortOrderId = sortOrderId; | ||
| } | ||
|
|
||
| public int sortOrderId() { | ||
| return sortOrderId; | ||
| } | ||
| } | ||
|
|
||
| class AddSnapshot implements MetadataUpdate { | ||
| private final Snapshot snapshot; | ||
|
|
||
| public AddSnapshot(Snapshot snapshot) { | ||
| this.snapshot = snapshot; | ||
| } | ||
|
|
||
| public Snapshot snapshot() { | ||
| return snapshot; | ||
| } | ||
| } | ||
|
|
||
| class RemoveSnapshot implements MetadataUpdate { | ||
| private final long snapshotId; | ||
|
|
||
| public RemoveSnapshot(long snapshotId) { | ||
| this.snapshotId = snapshotId; | ||
| } | ||
|
|
||
| public long snapshotId() { | ||
| return snapshotId; | ||
| } | ||
| } | ||
|
|
||
| class SetCurrentSnapshot implements MetadataUpdate { | ||
| private final Long snapshotId; | ||
|
|
||
| public SetCurrentSnapshot(Long snapshotId) { | ||
| this.snapshotId = snapshotId; | ||
| } | ||
|
|
||
| public Long snapshotId() { | ||
| return snapshotId; | ||
| } | ||
| } | ||
|
|
||
| class SetProperties implements MetadataUpdate { | ||
| private final Map<String, String> updated; | ||
|
|
||
| public SetProperties(Map<String, String> updated) { | ||
| this.updated = updated; | ||
| } | ||
|
|
||
| public Map<String, String> updated() { | ||
| return updated; | ||
| } | ||
| } | ||
|
|
||
| class RemoveProperties implements MetadataUpdate { | ||
| private final Set<String> removed; | ||
|
|
||
| public RemoveProperties(Set<String> removed) { | ||
| this.removed = removed; | ||
| } | ||
|
|
||
| public Set<String> removed() { | ||
| return removed; | ||
| } | ||
| } | ||
|
|
||
| class SetLocation implements MetadataUpdate { | ||
| private final String location; | ||
|
|
||
| public SetLocation(String location) { | ||
| this.location = location; | ||
| } | ||
|
|
||
| public String location() { | ||
| return location; | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is needed for table replacement. Previously, building the replacement table metadata carried through partition specs and sort orders unchanged. Now that replace table goes through the same method to update the schema,
setCurrentSchema, the specs and orders are now rebuilt to reference the current schema.When replacing a table, its schema, partition spec, and sort order only need to be consistent with one another, not the older specs and sort orders. This relaxes the check so that tests that have incompatible changes don't fail.
Relaxing checks is the correct thing to do because consistency is now checked in the
buildmethod. It allows the current schema, spec, and order to be changed as long as they are consistent with one another. Older specs and orders are still kept because they may be referenced by data files in existing manifests.