Skip to content

Commit e1570fc

Browse files
committed
feat: update pyiceberg/catalog/hive.py to support hive 4.x.x
resolves apache#1222
1 parent 19ba343 commit e1570fc

1 file changed

Lines changed: 15 additions & 5 deletions

File tree

‎pyiceberg/catalog/hive.py‎

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -389,8 +389,8 @@ def _create_hive_table(self, open_client: Client, hive_table: HiveTable) -> None
389389

390390
def _get_hive_table(self, open_client: Client, database_name: str, table_name: str) -> HiveTable:
391391
try:
392-
return open_client.get_table(dbname=database_name, tbl_name=table_name)
393-
except NoSuchObjectException as e:
392+
return open_client.get_tables(db_name=database_name, pattern=table_name).pop()
393+
except IndexError as e:
394394
raise NoSuchTableError(f"Table does not exists: {table_name}") from e
395395

396396
def create_table(
@@ -435,7 +435,10 @@ def create_table(
435435

436436
with self._client as open_client:
437437
self._create_hive_table(open_client, tbl)
438-
hive_table = open_client.get_table(dbname=database_name, tbl_name=table_name)
438+
try:
439+
hive_table = open_client.get_tables(db_name=database_name, pattern=table_name).pop()
440+
except IndexError as e:
441+
raise NoSuchObjectException("get_table failed: unknown result") from e
439442

440443
return self._convert_hive_into_iceberg(hive_table)
441444

@@ -465,7 +468,10 @@ def register_table(self, identifier: Union[str, Identifier], metadata_location:
465468
tbl = self._convert_iceberg_into_hive(staged_table)
466469
with self._client as open_client:
467470
self._create_hive_table(open_client, tbl)
468-
hive_table = open_client.get_table(dbname=database_name, tbl_name=table_name)
471+
try:
472+
hive_table = open_client.get_tables(db_name=database_name, pattern=table_name).pop()
473+
except IndexError as e:
474+
raise NoSuchTableError(f"Table does not exists: {table_name}") from e
469475

470476
return self._convert_hive_into_iceberg(hive_table)
471477

@@ -661,7 +667,10 @@ def rename_table(self, from_identifier: Union[str, Identifier], to_identifier: U
661667

662668
try:
663669
with self._client as open_client:
664-
tbl = open_client.get_table(dbname=from_database_name, tbl_name=from_table_name)
670+
try:
671+
tbl = open_client.get_tables(db_name=from_database_name, pattern=from_table_name).pop()
672+
except IndexError as e:
673+
raise NoSuchObjectException("get_table failed: unknown result") from e
665674
tbl.dbName = to_database_name
666675
tbl.tableName = to_table_name
667676
open_client.alter_table_with_environment_context(
@@ -824,3 +833,4 @@ def drop_view(self, identifier: Union[str, Identifier]) -> None:
824833
def _get_default_warehouse_location(self, database_name: str, table_name: str) -> str:
825834
"""Override the default warehouse location to follow Hive-style conventions."""
826835
return self._get_hive_style_warehouse_location(database_name, table_name)
836+

0 commit comments

Comments
 (0)