diff --git a/pyiceberg/table/__init__.py b/pyiceberg/table/__init__.py index 4ec3403bb3..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 ( @@ -404,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 new file mode 100644 index 0000000000..bba50e7645 --- /dev/null +++ b/pyiceberg/table/update/sort_order.py @@ -0,0 +1,43 @@ +# 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, Tuple + +from pyiceberg.table.update import ( + TableRequirement, + TableUpdate, + UpdatesAndRequirements, + UpdateTableMetadata, +) + +if TYPE_CHECKING: + from pyiceberg.table import Transaction + + +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