From 87b2ae07f47dd6818bc6cb61e96eb5c7bd2484b0 Mon Sep 17 00:00:00 2001 From: Kevin Liu Date: Sun, 21 Jul 2024 14:10:59 -0700 Subject: [PATCH 1/3] add test --- tests/table/test_init.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/table/test_init.py b/tests/table/test_init.py index 1c4029a292..8fc78738d8 100644 --- a/tests/table/test_init.py +++ b/tests/table/test_init.py @@ -1258,3 +1258,10 @@ 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_table_update_have_corresponding_dispatch() -> None: + from pyiceberg.table import TableUpdate, _apply_table_update + # asser that every TableUpdate has a corresponding `_apply_table_update` dispatch function + + assert len(_apply_table_update.registry) == len(TableUpdate.__origin__.__args__) # type: ignore From 3ab06e20f62d92ffdb58eac6a1af3bfa27e3dcfa Mon Sep 17 00:00:00 2001 From: Kevin Liu Date: Sun, 21 Jul 2024 14:20:10 -0700 Subject: [PATCH 2/3] better error msg --- tests/table/test_init.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/tests/table/test_init.py b/tests/table/test_init.py index 8fc78738d8..86204dcda4 100644 --- a/tests/table/test_init.py +++ b/tests/table/test_init.py @@ -1260,8 +1260,10 @@ def test_table_module_refactoring_backward_compatibility() -> None: raise pytest.fail("Importing moved modules should not raise an exception") from exc -def test_table_update_have_corresponding_dispatch() -> None: +def test_table_update_has_corresponding_dispatch() -> None: from pyiceberg.table import TableUpdate, _apply_table_update - # asser that every TableUpdate has a corresponding `_apply_table_update` dispatch function - - assert len(_apply_table_update.registry) == len(TableUpdate.__origin__.__args__) # type: ignore + # assert that every TableUpdate has a corresponding `_apply_table_update` dispatch function + table_update_class = set(TableUpdate.__origin__.__args__) # type: ignore + dispatch_function_class = set(_apply_table_update.registry.keys()) + missing_dispatch_function = table_update_class - dispatch_function_class + assert len(missing_dispatch_function) == 0, f"Missing dispatch function for {missing_dispatch_function}" From c5bcea7183eb59babdb01edba355f87daa37ca09 Mon Sep 17 00:00:00 2001 From: Kevin Liu Date: Sat, 2 Nov 2024 17:22:07 -0700 Subject: [PATCH 3/3] add placeholder --- pyiceberg/table/update/__init__.py | 14 ++++++++++++++ tests/table/test_init.py | 15 ++++++++------- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/pyiceberg/table/update/__init__.py b/pyiceberg/table/update/__init__.py index b81a2bf7f4..9a296159fc 100644 --- a/pyiceberg/table/update/__init__.py +++ b/pyiceberg/table/update/__init__.py @@ -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, ...], diff --git a/tests/table/test_init.py b/tests/table/test_init.py index 86204dcda4..4e942acbff 100644 --- a/tests/table/test_init.py +++ b/tests/table/test_init.py @@ -1260,10 +1260,11 @@ def test_table_module_refactoring_backward_compatibility() -> None: raise pytest.fail("Importing moved modules should not raise an exception") from exc -def test_table_update_has_corresponding_dispatch() -> None: - from pyiceberg.table import TableUpdate, _apply_table_update - # assert that every TableUpdate has a corresponding `_apply_table_update` dispatch function - table_update_class = set(TableUpdate.__origin__.__args__) # type: ignore - dispatch_function_class = set(_apply_table_update.registry.keys()) - missing_dispatch_function = table_update_class - dispatch_function_class - assert len(missing_dispatch_function) == 0, f"Missing dispatch function for {missing_dispatch_function}" +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}"