Skip to content

Commit 0272d9b

Browse files
committed
commitstatus to enum
1 parent d14d440 commit 0272d9b

1 file changed

Lines changed: 14 additions & 7 deletions

File tree

pyiceberg/catalog/bigquery_metastore.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from __future__ import annotations
1818

1919
import json
20+
from enum import Enum
2021
from typing import TYPE_CHECKING, Any
2122

2223
from google.api_core.exceptions import NotFound
@@ -69,6 +70,12 @@
6970
HIVE_FILE_OUTPUT_FORMAT = "org.apache.iceberg.mr.hive.HiveIcebergOutputFormat"
7071

7172

73+
class BigqueryCommitStatus(str, Enum):
74+
SUCCESS = "SUCCESS"
75+
FAILURE = "FAILURE"
76+
UNKNOWN = "UNKNOWN"
77+
78+
7279
class BigQueryMetastoreCatalog(MetastoreCatalog):
7380
def __init__(self, name: str, **properties: str):
7481
super().__init__(name, **properties)
@@ -307,9 +314,9 @@ def commit_table(
307314
finally:
308315
if commit_error:
309316
commit_status = self._check_bigquery_commit_status(table_ref, updated_staged_table.metadata_location)
310-
if commit_status == "SUCCESS":
317+
if commit_status == BigqueryCommitStatus.SUCCESS:
311318
commit_error = None
312-
elif commit_status == "UNKNOWN":
319+
elif commit_status == BigqueryCommitStatus.UNKNOWN:
313320
raise CommitStateUnknownException(
314321
f"Commit state unknown for table {dataset_name}.{table_name}"
315322
) from commit_error
@@ -539,10 +546,10 @@ def _check_bigquery_commit_status(self, table_ref: TableReference, new_metadata_
539546
)
540547
current_metadata_location = parameters.get(METADATA_LOCATION_PROP)
541548
if current_metadata_location == new_metadata_location:
542-
return "SUCCESS"
549+
return BigqueryCommitStatus.SUCCESS
543550

544551
if not current_metadata_location:
545-
return "FAILURE"
552+
return BigqueryCommitStatus.FAILURE
546553

547554
io = self._load_file_io(location=current_metadata_location)
548555
current_metadata = FromInputFile.table_metadata(io.new_input(current_metadata_location))
@@ -552,11 +559,11 @@ def _check_bigquery_commit_status(self, table_ref: TableReference, new_metadata_
552559
if previous_metadata_location:
553560
previous_metadata_locations.add(previous_metadata_location)
554561

555-
return "SUCCESS" if new_metadata_location in previous_metadata_locations else "FAILURE"
562+
return BigqueryCommitStatus.SUCCESS if new_metadata_location in previous_metadata_locations else "FAILURE"
556563
except NotFound:
557-
return "FAILURE"
564+
return BigqueryCommitStatus.FAILURE
558565
except Exception:
559-
return "UNKNOWN"
566+
return BigqueryCommitStatus.UNKNOWN
560567

561568
def _default_storage_location(self, location: str | None, dataset_ref: DatasetReference) -> str | None:
562569
if location:

0 commit comments

Comments
 (0)