From e1c836bec9df70c71e873e925ec0877b490432d2 Mon Sep 17 00:00:00 2001 From: Jasper Ginn Date: Mon, 23 Dec 2024 15:45:52 +0100 Subject: [PATCH 1/4] chore: add method --- pyiceberg/table/__init__.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pyiceberg/table/__init__.py b/pyiceberg/table/__init__.py index 4ec3403bb3..19c70d4381 100644 --- a/pyiceberg/table/__init__.py +++ b/pyiceberg/table/__init__.py @@ -294,6 +294,9 @@ def upgrade_table_version(self, format_version: TableVersion) -> Transaction: return self._apply((UpgradeFormatVersionUpdate(format_version=format_version),)) return self + + def replace_sort_order(self) -> None: + ... def set_properties(self, properties: Properties = EMPTY_DICT, **kwargs: Any) -> Transaction: """Set properties. From 583c8439259e6f0fa007592c65d3f964795e25ac Mon Sep 17 00:00:00 2001 From: Jasper Ginn Date: Mon, 23 Dec 2024 15:59:15 +0100 Subject: [PATCH 2/4] chore: pre-commit --- pyiceberg/table/__init__.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/pyiceberg/table/__init__.py b/pyiceberg/table/__init__.py index 19c70d4381..ad72b271ba 100644 --- a/pyiceberg/table/__init__.py +++ b/pyiceberg/table/__init__.py @@ -294,9 +294,8 @@ def upgrade_table_version(self, format_version: TableVersion) -> Transaction: return self._apply((UpgradeFormatVersionUpdate(format_version=format_version),)) return self - - def replace_sort_order(self) -> None: - ... + + def replace_sort_order(self) -> None: ... def set_properties(self, properties: Properties = EMPTY_DICT, **kwargs: Any) -> Transaction: """Set properties. From 767f9645b868b0d8986c066ddbb991321e84e918 Mon Sep 17 00:00:00 2001 From: Jasper Ginn Date: Mon, 23 Dec 2024 16:04:45 +0100 Subject: [PATCH 3/4] chore: scaffolding --- pyiceberg/table/update/sort_order.py | 35 ++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 pyiceberg/table/update/sort_order.py diff --git a/pyiceberg/table/update/sort_order.py b/pyiceberg/table/update/sort_order.py new file mode 100644 index 0000000000..a08bc3784b --- /dev/null +++ b/pyiceberg/table/update/sort_order.py @@ -0,0 +1,35 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +from __future__ import annotations + +from typing import ( + TYPE_CHECKING, +) + +from pyiceberg.table.update import ( + UpdateTableMetadata, +) + +if TYPE_CHECKING: + from pyiceberg.table import Transaction + + +class UpdateSpec(UpdateTableMetadata["UpdateSpec"]): + _transaction: Transaction + + def __init__(self, transaction: Transaction, case_sensitive: bool = True) -> None: + super().__init__(transaction) From 2fa5a7492a815b4e4a1d0c940894e9dedbc0d174 Mon Sep 17 00:00:00 2001 From: Jasper Ginn Date: Mon, 23 Dec 2024 16:14:40 +0100 Subject: [PATCH 4/4] chore: scaffolding --- pyiceberg/table/__init__.py | 11 +++++++++-- pyiceberg/table/update/sort_order.py | 16 ++++++++++++---- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/pyiceberg/table/__init__.py b/pyiceberg/table/__init__.py index ad72b271ba..9d1ab4c831 100644 --- a/pyiceberg/table/__init__.py +++ b/pyiceberg/table/__init__.py @@ -117,6 +117,7 @@ UpdateSnapshot, _FastAppendFiles, ) +from pyiceberg.table.update.sort_order import UpdateSortOrder from pyiceberg.table.update.spec import UpdateSpec from pyiceberg.transforms import IdentityTransform from pyiceberg.typedef import ( @@ -295,8 +296,6 @@ def upgrade_table_version(self, format_version: TableVersion) -> Transaction: return self - def replace_sort_order(self) -> None: ... - def set_properties(self, properties: Properties = EMPTY_DICT, **kwargs: Any) -> Transaction: """Set properties. @@ -406,6 +405,14 @@ def update_schema(self, allow_incompatible_changes: bool = False, case_sensitive name_mapping=self.table_metadata.name_mapping(), ) + def replace_sort_order(self) -> UpdateSortOrder: + """Create a new UpdateSortOrder to replace the sort order of this table. + + Returns: + A new UpdateSortOrder. + """ + return UpdateSortOrder(self) + def update_snapshot(self, snapshot_properties: Dict[str, str] = EMPTY_DICT) -> UpdateSnapshot: """Create a new UpdateSnapshot to produce a new snapshot for the table. diff --git a/pyiceberg/table/update/sort_order.py b/pyiceberg/table/update/sort_order.py index a08bc3784b..bba50e7645 100644 --- a/pyiceberg/table/update/sort_order.py +++ b/pyiceberg/table/update/sort_order.py @@ -16,11 +16,12 @@ # under the License. from __future__ import annotations -from typing import ( - TYPE_CHECKING, -) +from typing import TYPE_CHECKING, Tuple from pyiceberg.table.update import ( + TableRequirement, + TableUpdate, + UpdatesAndRequirements, UpdateTableMetadata, ) @@ -28,8 +29,15 @@ from pyiceberg.table import Transaction -class UpdateSpec(UpdateTableMetadata["UpdateSpec"]): +class UpdateSortOrder(UpdateTableMetadata["UpdateSortOrder"]): _transaction: Transaction def __init__(self, transaction: Transaction, case_sensitive: bool = True) -> None: super().__init__(transaction) + + def _commit(self) -> UpdatesAndRequirements: + """Apply the pending changes and commit.""" + requirements: Tuple[TableRequirement, ...] = () + updates: Tuple[TableUpdate, ...] = () + + return updates, requirements