-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Core: view version update requirements #14334
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ | |
*/ | ||
package org.apache.iceberg; | ||
|
||
import java.util.Optional; | ||
import org.apache.iceberg.exceptions.CommitFailedException; | ||
import org.apache.iceberg.exceptions.ValidationException; | ||
import org.apache.iceberg.relocated.com.google.common.base.Preconditions; | ||
|
@@ -230,4 +231,54 @@ public void validate(TableMetadata base) { | |
} | ||
} | ||
} | ||
|
||
class AssertCurrentViewVersionID implements UpdateRequirement { | ||
private final int viewVersionId; | ||
|
||
public AssertCurrentViewVersionID(int viewVersionId) { | ||
this.viewVersionId = viewVersionId; | ||
} | ||
|
||
public int viewVersionId() { | ||
return viewVersionId; | ||
} | ||
|
||
@Override | ||
public void validate(ViewMetadata base) { | ||
if (viewVersionId != base.currentVersionId()) { | ||
throw new CommitFailedException( | ||
"Requirement failed: current view version changed: expected version %s != %s", | ||
viewVersionId, base.currentVersionId()); | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Assuming that view ID is incrementing integers, so the last assigned view version ID is always | ||
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. this isn't something that holds true. View versions are not guaranteed to be monotonically increasing and the spec doesn't say anything about this |
||
* the max ID that has been assigned. | ||
*/ | ||
class AssertLastAssignedViewVersionID implements UpdateRequirement { | ||
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. here's some historical context on why I didn't add it back then when introducing views: #8147 (comment) |
||
private final int lastAssignedViewVersionId; | ||
|
||
public AssertLastAssignedViewVersionID(int lastAssignedViewVersionId) { | ||
this.lastAssignedViewVersionId = lastAssignedViewVersionId; | ||
} | ||
|
||
public int lastAssignedViewId() { | ||
return lastAssignedViewVersionId; | ||
} | ||
|
||
@Override | ||
public void validate(ViewMetadata base) { | ||
Optional<Integer> maxAssignedViewVersionID = | ||
base.versionsById().keySet().stream().max(Integer::compareTo); | ||
if (base != null | ||
&& maxAssignedViewVersionID.isPresent() | ||
&& maxAssignedViewVersionID.get() != lastAssignedViewVersionId) { | ||
throw new CommitFailedException( | ||
"Requirement failed: last assigned view id changed: expected id %s != %s", | ||
lastAssignedViewVersionId, maxAssignedViewVersionID.get()); | ||
} | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -108,7 +108,7 @@ public void commit(ViewMetadata base, ViewMetadata metadata) { | |
// if the metadata is already out of date, reject it | ||
if (base != current()) { | ||
if (base != null) { | ||
throw new CommitFailedException("Cannot commit: stale view metadata"); | ||
throw new CommitFailedException("Commit failed: stale view metadata"); | ||
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. this and the other one seem like unrelated changes? |
||
} else { | ||
// when current is non-null, the view exists. but when base is null, the commit is trying | ||
// to create the view | ||
|
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.
here's some historical context on why I didn't add it back then when views were introduced: #8147 (comment)
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.
I guess this comes down to whether we have a good enough argument for making a "replace view" fail