1515# specific language governing permissions and limitations
1616# under the License.
1717import json
18+ from enum import Enum
1819from typing import TYPE_CHECKING , Any , Union
1920
2021from google .api_core .exceptions import NotFound
6566HIVE_FILE_OUTPUT_FORMAT = "org.apache.iceberg.mr.hive.HiveIcebergOutputFormat"
6667
6768
69+ class BigqueryCommitStatus (str , Enum ):
70+ SUCCESS = "SUCCESS"
71+ FAILURE = "FAILURE"
72+ UNKNOWN = "UNKNOWN"
73+
74+
6875class BigQueryMetastoreCatalog (MetastoreCatalog ):
6976 def __init__ (self , name : str , ** properties : str ):
7077 super ().__init__ (name , ** properties )
@@ -302,9 +309,9 @@ def commit_table(
302309 finally :
303310 if commit_error :
304311 commit_status = self ._check_bigquery_commit_status (table_ref , updated_staged_table .metadata_location )
305- if commit_status == " SUCCESS" :
312+ if commit_status == BigqueryCommitStatus . SUCCESS :
306313 commit_error = None
307- elif commit_status == " UNKNOWN" :
314+ elif commit_status == BigqueryCommitStatus . UNKNOWN :
308315 raise CommitStateUnknownException (
309316 f"Commit state unknown for table { dataset_name } .{ table_name } "
310317 ) from commit_error
@@ -512,10 +519,10 @@ def _check_bigquery_commit_status(self, table_ref: TableReference, new_metadata_
512519 )
513520 current_metadata_location = parameters .get (METADATA_LOCATION_PROP )
514521 if current_metadata_location == new_metadata_location :
515- return " SUCCESS"
522+ return BigqueryCommitStatus . SUCCESS
516523
517524 if not current_metadata_location :
518- return " FAILURE"
525+ return BigqueryCommitStatus . FAILURE
519526
520527 io = self ._load_file_io (location = current_metadata_location )
521528 current_metadata = FromInputFile .table_metadata (io .new_input (current_metadata_location ))
@@ -525,11 +532,11 @@ def _check_bigquery_commit_status(self, table_ref: TableReference, new_metadata_
525532 if previous_metadata_location :
526533 previous_metadata_locations .add (previous_metadata_location )
527534
528- return " SUCCESS" if new_metadata_location in previous_metadata_locations else "FAILURE"
535+ return BigqueryCommitStatus . SUCCESS if new_metadata_location in previous_metadata_locations else "FAILURE"
529536 except NotFound :
530- return " FAILURE"
537+ return BigqueryCommitStatus . FAILURE
531538 except Exception :
532- return " UNKNOWN"
539+ return BigqueryCommitStatus . UNKNOWN
533540
534541 def _default_storage_location (self , location : str | None , dataset_ref : DatasetReference ) -> str | None :
535542 if location :
0 commit comments