-
Notifications
You must be signed in to change notification settings - Fork 63
feat: implement validation for table update requirements #294
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?
Conversation
Implement Validate() methods for remaining table requirement classes: - AssertDoesNotExist: validates table doesn't exist - AssertRefSnapshotID: validates snapshot references (branches/tags) - AssertLastAssignedFieldId: validates last assigned field ID - AssertLastAssignedPartitionId: validates last assigned partition ID - AssertDefaultSpecID: validates default partition spec ID - AssertDefaultSortOrderID: validates default sort order ID All implementations follow the pattern established in AssertCurrentSchemaID and provide descriptive error messages for validation failures.
Add tests for all newly implemented table requirement validation methods: - AssertDoesNotExist: 2 tests (success, table exists) - AssertRefSnapshotID: 6 tests (success, mismatch, missing ref, null base, nullopt success, nullopt but exists) - AssertLastAssignedFieldId: 3 tests (success, mismatch, null base) - AssertLastAssignedPartitionId: 3 tests (success, mismatch, null base) - AssertDefaultSpecID: 3 tests (success, mismatch, null base) - AssertDefaultSortOrderID: 3 tests (success, mismatch, null base) Total: 20 new tests added. All tests pass (73 tests in table_test suite).
de779ff to
35e88f7
Compare
zhjwpku
left a 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.
LGTM
| if (base == nullptr) { | ||
| return CommitFailed("Requirement failed: current table metadata is missing"); | ||
| } | ||
|
|
||
| if (base->last_column_id != last_assigned_field_id_) { |
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.
| if (base == nullptr) { | |
| return CommitFailed("Requirement failed: current table metadata is missing"); | |
| } | |
| if (base->last_column_id != last_assigned_field_id_) { | |
| if (base && base->last_column_id != last_assigned_field_id_) { |
The Java impl allows base metadata is missing. I think it makes sense for a new table.
| if (base == nullptr) { | ||
| return CommitFailed("Requirement failed: current table metadata is missing"); | ||
| } | ||
|
|
||
| if (base->last_partition_id != last_assigned_partition_id_) { |
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.
| if (base == nullptr) { | |
| return CommitFailed("Requirement failed: current table metadata is missing"); | |
| } | |
| if (base->last_partition_id != last_assigned_partition_id_) { | |
| if (base && base->last_partition_id != last_assigned_partition_id_) { |
| return NotImplemented("AssertTableRefSnapshotID::Validate not implemented"); | ||
| // Validate that a reference (branch or tag) points to the expected snapshot ID | ||
|
|
||
| if (base == nullptr) { |
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 inconsistent with the Java impl. Could you double check?
public void validate(TableMetadata base) {
SnapshotRef ref = base.ref(name);
if (ref != null) {
String type = ref.isBranch() ? "branch" : "tag";
if (snapshotId == null) {
// a null snapshot ID means the ref should not exist already
throw new CommitFailedException(
"Requirement failed: %s %s was created concurrently", type, name);
} else if (snapshotId != ref.snapshotId()) {
throw new CommitFailedException(
"Requirement failed: %s %s has changed: expected id %s != %s",
type, name, snapshotId, ref.snapshotId());
}
} else if (snapshotId != null) {
throw new CommitFailedException(
"Requirement failed: branch or tag %s is missing, expected %s", name, snapshotId);
}
}
Implement Validate() methods for remaining table requirement classes:
All implementations follow the pattern established in AssertCurrentSchemaID and provide descriptive error messages for validation failures.