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
@@ -418,11 +420,15 @@ def _do_wait_for_lock() -> LockResponse:
418420
419421 return _do_wait_for_lock ()
420422
421- def _commit_table (self , table_request : CommitTableRequest ) -> CommitTableResponse :
422- """Update the table.
423+ def commit_table (
424+ self , table : Table , requirements : Tuple [TableRequirement , ...], updates : Tuple [TableUpdate , ...]
425+ ) -> CommitTableResponse :
426+ """Commit updates to a table.
423427
424428 Args:
425- table_request (CommitTableRequest): The table requests to be carried out.
429+ table (Table): The table to be updated.
430+ requirements: (Tuple[TableRequirement, ...]): Table requirements.
431+ updates: (Tuple[TableUpdate, ...]): Table updates.
426432
427433 Returns:
428434 CommitTableResponse: The updated metadata.
@@ -431,10 +437,8 @@ def _commit_table(self, table_request: CommitTableRequest) -> CommitTableRespons
431437 NoSuchTableError: If a table with the given identifier does not exist.
432438 CommitFailedException: Requirement not met, or a conflict with a concurrent commit.
433439 """
434- identifier_tuple = self ._identifier_to_tuple_without_catalog (
435- tuple (table_request .identifier .namespace .root + [table_request .identifier .name ])
436- )
437- database_name , table_name = self .identifier_to_database_and_table (identifier_tuple , NoSuchTableError )
440+ table_identifier = self .identifier_to_tuple_without_catalog (table .identifier )
441+ database_name , table_name = table_identifier
438442 # commit to hive
439443 # https://github.com/apache/hive/blob/master/standalone-metastore/metastore-common/src/main/thrift/hive_metastore.thrift#L1232
440444 with self ._client as open_client :
@@ -445,7 +449,9 @@ def _commit_table(self, table_request: CommitTableRequest) -> CommitTableRespons
445449 if lock .state == LockState .WAITING :
446450 self ._wait_for_lock (database_name , table_name , lock .lockid , open_client )
447451 else :
448- raise CommitFailedException (f"Failed to acquire lock for { table_request .identifier } , state: { lock .state } " )
452+ raise CommitFailedException (
453+ f"Failed to acquire lock for { table_identifier .identifier } , state: { lock .state } "
454+ )
449455
450456 hive_table : Optional [HiveTable ]
451457 current_table : Optional [Table ]
@@ -456,7 +462,7 @@ def _commit_table(self, table_request: CommitTableRequest) -> CommitTableRespons
456462 hive_table = None
457463 current_table = None
458464
459- updated_staged_table = self ._update_and_stage_table (current_table , table_request )
465+ updated_staged_table = self ._update_and_stage_table (current_table , table_identifier , requirements , updates )
460466 if current_table and updated_staged_table .metadata == current_table .metadata :
461467 # no changes, do nothing
462468 return CommitTableResponse (metadata = current_table .metadata , metadata_location = current_table .metadata_location )
@@ -486,7 +492,7 @@ def _commit_table(self, table_request: CommitTableRequest) -> CommitTableRespons
486492 )
487493 self ._create_hive_table (open_client , hive_table )
488494 except WaitingForLockException as e :
489- raise CommitFailedException (f"Failed to acquire lock for { table_request .identifier } , state: { lock .state } " ) from e
495+ raise CommitFailedException (f"Failed to acquire lock for { table .identifier } , state: { lock .state } " ) from e
490496 finally :
491497 open_client .unlock (UnlockRequest (lockid = lock .lockid ))
492498
0 commit comments