Skip to content
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

Add test to ensure every table update has corresponding _apply_table_update function #952

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions pyiceberg/table/update/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,20 @@ def _(
return base_metadata.model_copy(update={"default_sort_order_id": new_sort_order_id})


@_apply_table_update.register(RemoveSnapshotRefUpdate)
def _(update: RemoveSnapshotRefUpdate, base_metadata: TableMetadata, context: _TableMetadataUpdateContext) -> TableMetadata:
context.add_update(update)
# TODO: implement me
return base_metadata


@_apply_table_update.register(RemoveSnapshotsUpdate)
def _(update: RemoveSnapshotsUpdate, base_metadata: TableMetadata, context: _TableMetadataUpdateContext) -> TableMetadata:
context.add_update(update)
# TODO: implement me
return base_metadata


def update_table_metadata(
base_metadata: TableMetadata,
updates: Tuple[TableUpdate, ...],
Expand Down
10 changes: 10 additions & 0 deletions tests/table/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -1258,3 +1258,13 @@ def test_table_module_refactoring_backward_compatibility() -> None:
)
except Exception as exc:
raise pytest.fail("Importing moved modules should not raise an exception") from exc


def test_all_table_updates_have_dispatch() -> None:
# ensures that every TableUpdate subclass has a corresponding `_apply_table_update` dispatch function.
from pyiceberg.table.update import TableUpdate, _apply_table_update

table_update_classes = set(TableUpdate.__origin__.__args__) # type: ignore
dispatch_classes = set(_apply_table_update.registry.keys())
missing_dispatch = table_update_classes - dispatch_classes
assert not missing_dispatch, f"Missing dispatch function for: {missing_dispatch}"
Loading