Skip to content

Conversation

@shangxinli
Copy link
Contributor

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.

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).
@shangxinli shangxinli force-pushed the implement_update_requirements branch from de779ff to 35e88f7 Compare November 4, 2025 16:34
Copy link
Collaborator

@zhjwpku zhjwpku left a comment

Choose a reason for hiding this comment

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

LGTM

Comment on lines +92 to +96
if (base == nullptr) {
return CommitFailed("Requirement failed: current table metadata is missing");
}

if (base->last_column_id != last_assigned_field_id_) {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
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.

Comment on lines +130 to +134
if (base == nullptr) {
return CommitFailed("Requirement failed: current table metadata is missing");
}

if (base->last_partition_id != last_assigned_partition_id_) {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
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) {
Copy link
Member

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);
      }
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants