Skip to content

Commit f9ff171

Browse files
committed
Merge branch 'hive-4-support'
2 parents 8def539 + a87d102 commit f9ff171

2 files changed

Lines changed: 13 additions & 17 deletions

File tree

pyiceberg/catalog/hive.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,8 @@
5555
StorageDescriptor,
5656
UnlockRequest,
5757
)
58-
from hive_metastore.v3.ttypes import (
59-
Database as HiveDatabase,
60-
)
61-
from hive_metastore.v3.ttypes import (
62-
Table as HiveTable,
63-
)
58+
from hive_metastore.v3.ttypes import Database as HiveDatabase
59+
from hive_metastore.v3.ttypes import Table as HiveTable
6460
from tenacity import retry, retry_if_exception_type, stop_after_attempt, wait_exponential
6561
from thrift.protocol import TBinaryProtocol
6662
from thrift.transport import TSocket, TTransport
@@ -196,7 +192,7 @@ def _init_thrift_transport(self) -> TTransport:
196192

197193
def _client(self) -> Client:
198194
protocol = TBinaryProtocol.TBinaryProtocol(self._transport)
199-
hms = self.hms_v4 if all((self._hive_version.major >= 4, self._hive_version.minor > 0)) else self.hms_v3
195+
hms = self.hms_v4 if all((self._hive_version.major >= 4, self._hive_version.patch > 0)) else self.hms_v3
200196
client: Client = hms.Client(protocol)
201197
if self._ugi:
202198
client.set_ugi(*self._ugi)

tests/catalog/test_hive.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ def test_no_uri_supplied() -> None:
260260

261261

262262
def test_check_number_of_namespaces(table_schema_simple: Schema) -> None:
263-
_HiveClient._get_hive_version = MagicMock(return_value=HiveVersion(4, 0, 0)) # type: ignore
263+
_HiveClient._get_hive_version = MagicMock(return_value=HiveVersion(4, 0, 0)) # type: ignore[method-assign]
264264
catalog = HiveCatalog(HIVE_CATALOG_NAME, uri=HIVE_METASTORE_FAKE_URL)
265265

266266
with pytest.raises(ValueError):
@@ -287,7 +287,7 @@ def test_create_table(
287287

288288
catalog._client = MagicMock()
289289
catalog._client.__enter__().create_table.return_value = None
290-
catalog._get_hive_table = MagicMock(return_value=hive_table) # type: ignore
290+
catalog._get_hive_table = MagicMock(return_value=hive_table) # type: ignore[method-assign]
291291
catalog._client.__enter__().get_database.return_value = hive_database
292292
catalog.create_table(("default", "table"), schema=table_schema_with_all_types, properties={"owner": "javaberg"})
293293

@@ -466,7 +466,7 @@ def test_create_table_with_given_location_removes_trailing_slash(
466466

467467
catalog._client = MagicMock()
468468
catalog._client.__enter__().create_table.return_value = None
469-
catalog._get_hive_table = MagicMock(return_value=hive_table) # type: ignore
469+
catalog._get_hive_table = MagicMock(return_value=hive_table) # type: ignore[method-assign]
470470
catalog._client.__enter__().get_database.return_value = hive_database
471471
catalog.create_table(
472472
("default", "table"), schema=table_schema_with_all_types, properties={"owner": "javaberg"}, location=f"{location}/"
@@ -639,7 +639,7 @@ def test_create_v1_table(table_schema_simple: Schema, hive_database: HiveDatabas
639639
catalog = HiveCatalog(HIVE_CATALOG_NAME, uri=HIVE_METASTORE_FAKE_URL)
640640

641641
catalog._client = MagicMock()
642-
catalog._get_hive_table = MagicMock() # type: ignore
642+
catalog._get_hive_table = MagicMock() # type: ignore[method-assign]
643643
catalog._client.__enter__().create_table.return_value = None
644644
catalog._get_hive_table.return_value = hive_table
645645
catalog._client.__enter__().get_database.return_value = hive_database
@@ -692,7 +692,7 @@ def test_load_table(hive_table: HiveTable) -> None:
692692
catalog = HiveCatalog(HIVE_CATALOG_NAME, uri=HIVE_METASTORE_FAKE_URL)
693693

694694
catalog._client = MagicMock()
695-
catalog._get_hive_table = MagicMock(return_value=hive_table) # type: ignore
695+
catalog._get_hive_table = MagicMock(return_value=hive_table) # type: ignore[method-assign]
696696
table = catalog.load_table(("default", "new_tabl2e"))
697697

698698
catalog._get_hive_table.assert_called_with(catalog._client.__enter__(), dbname="default", tbl_name="new_tabl2e")
@@ -792,7 +792,7 @@ def test_load_table_from_self_identifier(hive_table: HiveTable) -> None:
792792
catalog = HiveCatalog(HIVE_CATALOG_NAME, uri=HIVE_METASTORE_FAKE_URL)
793793

794794
catalog._client = MagicMock()
795-
catalog._get_hive_table = MagicMock(return_value=hive_table) # type: ignore
795+
catalog._get_hive_table = MagicMock(return_value=hive_table) # type: ignore[method-assign]
796796
intermediate = catalog.load_table(("default", "new_tabl2e"))
797797
table = catalog.load_table(intermediate.name())
798798

@@ -898,7 +898,7 @@ def test_rename_table(hive_table: HiveTable) -> None:
898898
renamed_table.tableName = "new_tabl3e"
899899

900900
catalog._client = MagicMock()
901-
catalog._get_hive_table = MagicMock(side_effect=[hive_table, renamed_table]) # type: ignore
901+
catalog._get_hive_table = MagicMock(side_effect=[hive_table, renamed_table]) # type: ignore[method-assign]
902902
catalog._client.__enter__().alter_table_with_environment_context.return_value = None
903903

904904
from_identifier = ("default", "new_tabl2e")
@@ -925,7 +925,7 @@ def test_rename_table_from_self_identifier(hive_table: HiveTable) -> None:
925925
catalog.table_exists = MagicMock(return_value=False) # type: ignore[method-assign]
926926

927927
catalog._client = MagicMock()
928-
catalog._get_hive_table = MagicMock(return_value=hive_table) # type: ignore
928+
catalog._get_hive_table = MagicMock(return_value=hive_table) # type: ignore[method-assign]
929929

930930
from_identifier = ("default", "new_tabl2e")
931931
from_table = catalog.load_table(from_identifier)
@@ -1043,7 +1043,7 @@ def test_list_tables(hive_table: HiveTable) -> None:
10431043

10441044
catalog._client = MagicMock()
10451045
catalog._client.__enter__().get_all_tables.return_value = ["table1", "table2", "table3", "table4"]
1046-
catalog._get_table_objects_by_name = MagicMock() # type: ignore
1046+
catalog._get_table_objects_by_name = MagicMock() # type: ignore[method-assign]
10471047
catalog._get_table_objects_by_name.return_value = [tbl1, tbl2, tbl3, tbl4]
10481048

10491049
got_tables = catalog.list_tables("database")
@@ -1080,7 +1080,7 @@ def test_drop_table_from_self_identifier(hive_table: HiveTable) -> None:
10801080
catalog = HiveCatalog(HIVE_CATALOG_NAME, uri=HIVE_METASTORE_FAKE_URL)
10811081

10821082
catalog._client = MagicMock()
1083-
catalog._get_hive_table = MagicMock(return_value=hive_table) # type: ignore
1083+
catalog._get_hive_table = MagicMock(return_value=hive_table) # type: ignore[method-assign]
10841084
table = catalog.load_table(("default", "new_tabl2e"))
10851085

10861086
catalog._client.__enter__().get_all_databases.return_value = ["namespace1", "namespace2"]

0 commit comments

Comments
 (0)