Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions pyiceberg/catalog/hive.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@

LOCK_CHECK_MIN_WAIT_TIME = "lock-check-min-wait-time"
LOCK_CHECK_MAX_WAIT_TIME = "lock-check-max-wait-time"
LOCK_CHECK_MIN_WAIT_TIME_MS = "iceberg.hive.lock-check-min-wait-ms"
LOCK_CHECK_MAX_WAIT_TIME_MS = "iceberg.hive.lock-check-max-wait-ms"
LOCK_CHECK_RETRIES = "lock-check-retries"
DEFAULT_LOCK_CHECK_MIN_WAIT_TIME = 0.1 # 100 milliseconds
DEFAULT_LOCK_CHECK_MAX_WAIT_TIME = 60 # 1 min
Expand All @@ -146,6 +148,19 @@
logger = logging.getLogger(__name__)


def _lock_check_wait_time(
properties: Properties,
seconds_property: str,
milliseconds_property: str,
default: float,
) -> float:
if (seconds := property_as_float(properties, seconds_property)) is not None:
return seconds
if (milliseconds := property_as_float(properties, milliseconds_property)) is not None:
return milliseconds / 1000
return default


class _HiveClient:
"""Helper class to nicely open and close the transport."""

Expand Down Expand Up @@ -305,8 +320,12 @@ def __init__(self, name: str, **properties: str):
self._client = self._create_hive_client(properties)
self._hive2_compatible = property_as_bool(properties, HIVE2_COMPATIBLE, HIVE2_COMPATIBLE_DEFAULT)

self._lock_check_min_wait_time = property_as_float(properties, LOCK_CHECK_MIN_WAIT_TIME, DEFAULT_LOCK_CHECK_MIN_WAIT_TIME)
self._lock_check_max_wait_time = property_as_float(properties, LOCK_CHECK_MAX_WAIT_TIME, DEFAULT_LOCK_CHECK_MAX_WAIT_TIME)
self._lock_check_min_wait_time = _lock_check_wait_time(
properties, LOCK_CHECK_MIN_WAIT_TIME, LOCK_CHECK_MIN_WAIT_TIME_MS, DEFAULT_LOCK_CHECK_MIN_WAIT_TIME
)
self._lock_check_max_wait_time = _lock_check_wait_time(
properties, LOCK_CHECK_MAX_WAIT_TIME, LOCK_CHECK_MAX_WAIT_TIME_MS, DEFAULT_LOCK_CHECK_MAX_WAIT_TIME
)
self._lock_check_retries = property_as_float(
properties,
LOCK_CHECK_RETRIES,
Expand Down
32 changes: 32 additions & 0 deletions tests/catalog/test_hive.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@
HIVE_KERBEROS_SERVICE_HOST,
HIVE_KERBEROS_SERVICE_NAME,
LOCK_CHECK_MAX_WAIT_TIME,
LOCK_CHECK_MAX_WAIT_TIME_MS,
LOCK_CHECK_MIN_WAIT_TIME,
LOCK_CHECK_MIN_WAIT_TIME_MS,
LOCK_CHECK_RETRIES,
HiveCatalog,
_construct_hive_storage_descriptor,
Expand Down Expand Up @@ -1344,6 +1346,36 @@ def test_hive_wait_for_lock() -> None:
assert catalog._client.check_lock.call_count == 5


def test_hive_lock_check_java_millisecond_properties() -> None:
catalog = HiveCatalog(
HIVE_CATALOG_NAME,
uri=HIVE_METASTORE_FAKE_URL,
**{
LOCK_CHECK_MIN_WAIT_TIME_MS: "100",
LOCK_CHECK_MAX_WAIT_TIME_MS: "500",
},
)

assert catalog._lock_check_min_wait_time == 0.1
assert catalog._lock_check_max_wait_time == 0.5


def test_hive_lock_check_native_properties_take_precedence() -> None:
catalog = HiveCatalog(
HIVE_CATALOG_NAME,
uri=HIVE_METASTORE_FAKE_URL,
**{
LOCK_CHECK_MIN_WAIT_TIME: "1.5",
LOCK_CHECK_MIN_WAIT_TIME_MS: "100",
LOCK_CHECK_MAX_WAIT_TIME: "2.5",
LOCK_CHECK_MAX_WAIT_TIME_MS: "500",
},
)

assert catalog._lock_check_min_wait_time == 1.5
assert catalog._lock_check_max_wait_time == 2.5


def test_create_hive_client_success() -> None:
properties = {"uri": "thrift://localhost:10000", "ugi": "user"}

Expand Down
Loading