2626 List ,
2727 Optional ,
2828 Set ,
29+ Tuple ,
2930 Type ,
3031 Union ,
3132)
7980from pyiceberg .schema import Schema , SchemaVisitor , visit
8081from pyiceberg .serializers import FromInputFile
8182from pyiceberg .table import (
82- CommitTableRequest ,
8383 CommitTableResponse ,
8484 StagedTable ,
8585 Table ,
8686 TableProperties ,
87+ TableRequirement ,
88+ TableUpdate ,
8789)
8890from pyiceberg .table .sorting import UNSORTED_SORT_ORDER , SortOrder
8991from pyiceberg .typedef import EMPTY_DICT , Identifier , Properties
@@ -421,11 +423,15 @@ def _do_wait_for_lock() -> LockResponse:
421423
422424 return _do_wait_for_lock ()
423425
424- def _commit_table (self , table_request : CommitTableRequest ) -> CommitTableResponse :
425- """Update the table.
426+ def commit_table (
427+ self , table : Table , requirements : Tuple [TableRequirement , ...], updates : Tuple [TableUpdate , ...]
428+ ) -> CommitTableResponse :
429+ """Commit updates to a table.
426430
427431 Args:
428- table_request (CommitTableRequest): The table requests to be carried out.
432+ table (Table): The table to be updated.
433+ requirements: (Tuple[TableRequirement, ...]): Table requirements.
434+ updates: (Tuple[TableUpdate, ...]): Table updates.
429435
430436 Returns:
431437 CommitTableResponse: The updated metadata.
@@ -434,10 +440,8 @@ def _commit_table(self, table_request: CommitTableRequest) -> CommitTableRespons
434440 NoSuchTableError: If a table with the given identifier does not exist.
435441 CommitFailedException: Requirement not met, or a conflict with a concurrent commit.
436442 """
437- identifier_tuple = self ._identifier_to_tuple_without_catalog (
438- tuple (table_request .identifier .namespace .root + [table_request .identifier .name ])
439- )
440- database_name , table_name = self .identifier_to_database_and_table (identifier_tuple , NoSuchTableError )
443+ table_identifier = self ._identifier_to_tuple_without_catalog (table .identifier )
444+ database_name , table_name = self .identifier_to_database_and_table (table_identifier , NoSuchTableError )
441445 # commit to hive
442446 # https://github.com/apache/hive/blob/master/standalone-metastore/metastore-common/src/main/thrift/hive_metastore.thrift#L1232
443447 with self ._client as open_client :
@@ -448,7 +452,7 @@ def _commit_table(self, table_request: CommitTableRequest) -> CommitTableRespons
448452 if lock .state == LockState .WAITING :
449453 self ._wait_for_lock (database_name , table_name , lock .lockid , open_client )
450454 else :
451- raise CommitFailedException (f"Failed to acquire lock for { table_request . identifier } , state: { lock .state } " )
455+ raise CommitFailedException (f"Failed to acquire lock for { table_identifier } , state: { lock .state } " )
452456
453457 hive_table : Optional [HiveTable ]
454458 current_table : Optional [Table ]
@@ -459,7 +463,7 @@ def _commit_table(self, table_request: CommitTableRequest) -> CommitTableRespons
459463 hive_table = None
460464 current_table = None
461465
462- updated_staged_table = self ._update_and_stage_table (current_table , table_request )
466+ updated_staged_table = self ._update_and_stage_table (current_table , table_identifier , requirements , updates )
463467 if current_table and updated_staged_table .metadata == current_table .metadata :
464468 # no changes, do nothing
465469 return CommitTableResponse (metadata = current_table .metadata , metadata_location = current_table .metadata_location )
@@ -489,7 +493,7 @@ def _commit_table(self, table_request: CommitTableRequest) -> CommitTableRespons
489493 )
490494 self ._create_hive_table (open_client , hive_table )
491495 except WaitingForLockException as e :
492- raise CommitFailedException (f"Failed to acquire lock for { table_request . identifier } , state: { lock .state } " ) from e
496+ raise CommitFailedException (f"Failed to acquire lock for { table_identifier } , state: { lock .state } " ) from e
493497 finally :
494498 open_client .unlock (UnlockRequest (lockid = lock .lockid ))
495499
0 commit comments