Skip to content

Commit e5a58b3

Browse files
HA HMS support (#752)
* Support HA and kerberos * reformat * Remove kerberos auth * Capture all exceptions * Make more pythonic * Add uts * Update UT to use assert_called_once_with * Fix for linting Co-authored-by: Kevin Liu <[email protected]> * Fix f string * fix formatting --------- Co-authored-by: Kevin Liu <[email protected]>
1 parent 09ec814 commit e5a58b3

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

pyiceberg/catalog/hive.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ class HiveCatalog(MetastoreCatalog):
261261

262262
def __init__(self, name: str, **properties: str):
263263
super().__init__(name, **properties)
264-
self._client = _HiveClient(properties["uri"], properties.get("ugi"))
264+
self._client = self._create_hive_client(properties)
265265

266266
self._lock_check_min_wait_time = property_as_float(properties, LOCK_CHECK_MIN_WAIT_TIME, DEFAULT_LOCK_CHECK_MIN_WAIT_TIME)
267267
self._lock_check_max_wait_time = property_as_float(properties, LOCK_CHECK_MAX_WAIT_TIME, DEFAULT_LOCK_CHECK_MAX_WAIT_TIME)
@@ -271,6 +271,19 @@ def __init__(self, name: str, **properties: str):
271271
DEFAULT_LOCK_CHECK_RETRIES,
272272
)
273273

274+
@staticmethod
275+
def _create_hive_client(properties: Dict[str, str]) -> _HiveClient:
276+
last_exception = None
277+
for uri in properties["uri"].split(","):
278+
try:
279+
return _HiveClient(uri, properties.get("ugi"))
280+
except BaseException as e:
281+
last_exception = e
282+
if last_exception is not None:
283+
raise last_exception
284+
else:
285+
raise ValueError(f"Unable to connect to hive using uri: {properties['uri']}")
286+
274287
def _convert_hive_into_iceberg(self, table: HiveTable) -> Table:
275288
properties: Dict[str, str] = table.parameters
276289
if TABLE_TYPE not in properties:

tests/catalog/test_hive.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1195,3 +1195,33 @@ def test_hive_wait_for_lock() -> None:
11951195
with pytest.raises(WaitingForLockException):
11961196
catalog._wait_for_lock("db", "tbl", lockid, catalog._client)
11971197
assert catalog._client.check_lock.call_count == 5
1198+
1199+
1200+
def test_create_hive_client_success() -> None:
1201+
properties = {"uri": "thrift://localhost:10000", "ugi": "user"}
1202+
1203+
with patch("pyiceberg.catalog.hive._HiveClient", return_value=MagicMock()) as mock_hive_client:
1204+
client = HiveCatalog._create_hive_client(properties)
1205+
mock_hive_client.assert_called_once_with("thrift://localhost:10000", "user")
1206+
assert client is not None
1207+
1208+
1209+
def test_create_hive_client_multiple_uris() -> None:
1210+
properties = {"uri": "thrift://localhost:10000,thrift://localhost:10001", "ugi": "user"}
1211+
1212+
with patch("pyiceberg.catalog.hive._HiveClient") as mock_hive_client:
1213+
mock_hive_client.side_effect = [Exception("Connection failed"), MagicMock()]
1214+
1215+
client = HiveCatalog._create_hive_client(properties)
1216+
assert mock_hive_client.call_count == 2
1217+
mock_hive_client.assert_has_calls([call("thrift://localhost:10000", "user"), call("thrift://localhost:10001", "user")])
1218+
assert client is not None
1219+
1220+
1221+
def test_create_hive_client_failure() -> None:
1222+
properties = {"uri": "thrift://localhost:10000,thrift://localhost:10001", "ugi": "user"}
1223+
1224+
with patch("pyiceberg.catalog.hive._HiveClient", side_effect=Exception("Connection failed")) as mock_hive_client:
1225+
with pytest.raises(Exception, match="Connection failed"):
1226+
HiveCatalog._create_hive_client(properties)
1227+
assert mock_hive_client.call_count == 2

0 commit comments

Comments
 (0)