Skip to content

Commit b955e94

Browse files
committed
Style fixes
1 parent 54610a2 commit b955e94

File tree

3 files changed

+35
-28
lines changed

3 files changed

+35
-28
lines changed

pyiceberg/catalog/hive.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -133,12 +133,16 @@
133133
DEFAULT_LOCK_CHECK_MIN_WAIT_TIME = 0.1 # 100 milliseconds
134134
DEFAULT_LOCK_CHECK_MAX_WAIT_TIME = 60 # 1 min
135135
DEFAULT_LOCK_CHECK_RETRIES = 4
136+
136137
DO_NOT_UPDATE_STATS = "DO_NOT_UPDATE_STATS"
137138
DO_NOT_UPDATE_STATS_DEFAULT = "true"
138139

139140
NO_LOCK_EXPECTED_KEY = "expected_parameter_key"
140141
NO_LOCK_EXPECTED_VALUE = "expected_parameter_value"
141142

143+
HIVE_LOCK_ENABLED = "engine.hive.lock-enabled"
144+
HIVE_LOCK_ENABLED_DEFAULT = True
145+
142146
logger = logging.getLogger(__name__)
143147

144148

@@ -509,11 +513,9 @@ def _hive_lock_enabled(table_properties: Properties, catalog_properties: Propert
509513
Matches the Java implementation in HiveTableOperations: checks the table property first,
510514
then falls back to catalog properties, then defaults to True.
511515
"""
512-
if TableProperties.HIVE_LOCK_ENABLED in table_properties:
513-
return property_as_bool(
514-
table_properties, TableProperties.HIVE_LOCK_ENABLED, TableProperties.HIVE_LOCK_ENABLED_DEFAULT
515-
)
516-
return property_as_bool(catalog_properties, TableProperties.HIVE_LOCK_ENABLED, TableProperties.HIVE_LOCK_ENABLED_DEFAULT)
516+
if HIVE_LOCK_ENABLED in table_properties:
517+
return property_as_bool(table_properties, HIVE_LOCK_ENABLED, HIVE_LOCK_ENABLED_DEFAULT)
518+
return property_as_bool(catalog_properties, HIVE_LOCK_ENABLED, HIVE_LOCK_ENABLED_DEFAULT)
517519

518520
def commit_table(
519521
self, table: Table, requirements: tuple[TableRequirement, ...], updates: tuple[TableUpdate, ...]

pyiceberg/table/__init__.py

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -247,9 +247,6 @@ class TableProperties:
247247
MIN_SNAPSHOTS_TO_KEEP = "history.expire.min-snapshots-to-keep"
248248
MIN_SNAPSHOTS_TO_KEEP_DEFAULT = 1
249249

250-
HIVE_LOCK_ENABLED = "engine.hive.lock-enabled"
251-
HIVE_LOCK_ENABLED_DEFAULT = True
252-
253250

254251
class Transaction:
255252
_table: Table
@@ -2005,13 +2002,11 @@ def _build_residual_evaluator(self, spec_id: int) -> Callable[[DataFile], Residu
20052002
# The lambda created here is run in multiple threads.
20062003
# So we avoid creating _EvaluatorExpression methods bound to a single
20072004
# shared instance across multiple threads.
2008-
return lambda datafile: (
2009-
residual_evaluator_of(
2010-
spec=spec,
2011-
expr=self.row_filter,
2012-
case_sensitive=self.case_sensitive,
2013-
schema=self.table_metadata.schema(),
2014-
)
2005+
return lambda datafile: residual_evaluator_of(
2006+
spec=spec,
2007+
expr=self.row_filter,
2008+
case_sensitive=self.case_sensitive,
2009+
schema=self.table_metadata.schema(),
20152010
)
20162011

20172012
@staticmethod

tests/catalog/test_hive.py

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
DO_NOT_UPDATE_STATS_DEFAULT,
4949
HIVE_KERBEROS_AUTH,
5050
HIVE_KERBEROS_SERVICE_NAME,
51+
HIVE_LOCK_ENABLED,
5152
LOCK_CHECK_MAX_WAIT_TIME,
5253
LOCK_CHECK_MIN_WAIT_TIME,
5354
LOCK_CHECK_RETRIES,
@@ -68,7 +69,6 @@
6869
)
6970
from pyiceberg.partitioning import PartitionField, PartitionSpec
7071
from pyiceberg.schema import Schema
71-
from pyiceberg.table import TableProperties
7272
from pyiceberg.table.metadata import TableMetadataUtil, TableMetadataV1, TableMetadataV2
7373
from pyiceberg.table.refs import SnapshotRef, SnapshotRefType
7474
from pyiceberg.table.snapshots import (
@@ -1420,24 +1420,24 @@ def test_hive_lock_enabled_defaults_to_true() -> None:
14201420

14211421
def test_hive_lock_enabled_table_property_disables_lock() -> None:
14221422
"""Table property engine.hive.lock-enabled=false disables locking."""
1423-
table_props = {TableProperties.HIVE_LOCK_ENABLED: "false"}
1423+
table_props = {HIVE_LOCK_ENABLED: "false"}
14241424
assert HiveCatalog._hive_lock_enabled(table_properties=table_props, catalog_properties={}) is False
14251425

14261426

14271427
def test_hive_lock_enabled_catalog_property_disables_lock() -> None:
14281428
"""Catalog property engine.hive.lock-enabled=false disables locking when table doesn't set it."""
1429-
catalog_props = {TableProperties.HIVE_LOCK_ENABLED: "false"}
1429+
catalog_props = {HIVE_LOCK_ENABLED: "false"}
14301430
assert HiveCatalog._hive_lock_enabled(table_properties={}, catalog_properties=catalog_props) is False
14311431

14321432

14331433
def test_hive_lock_enabled_table_property_overrides_catalog() -> None:
14341434
"""Table property takes precedence over catalog property."""
1435-
table_props = {TableProperties.HIVE_LOCK_ENABLED: "true"}
1436-
catalog_props = {TableProperties.HIVE_LOCK_ENABLED: "false"}
1435+
table_props = {HIVE_LOCK_ENABLED: "true"}
1436+
catalog_props = {HIVE_LOCK_ENABLED: "false"}
14371437
assert HiveCatalog._hive_lock_enabled(table_properties=table_props, catalog_properties=catalog_props) is True
14381438

1439-
table_props = {TableProperties.HIVE_LOCK_ENABLED: "false"}
1440-
catalog_props = {TableProperties.HIVE_LOCK_ENABLED: "true"}
1439+
table_props = {HIVE_LOCK_ENABLED: "false"}
1440+
catalog_props = {HIVE_LOCK_ENABLED: "true"}
14411441
assert HiveCatalog._hive_lock_enabled(table_properties=table_props, catalog_properties=catalog_props) is False
14421442

14431443

@@ -1449,7 +1449,7 @@ def test_commit_table_skips_locking_when_table_property_disables_it() -> None:
14491449

14501450
mock_table = MagicMock()
14511451
mock_table.name.return_value = ("default", "my_table")
1452-
mock_table.properties = {TableProperties.HIVE_LOCK_ENABLED: "false"}
1452+
mock_table.properties = {HIVE_LOCK_ENABLED: "false"}
14531453

14541454
mock_do_commit = MagicMock()
14551455
mock_do_commit.return_value = MagicMock()
@@ -1467,7 +1467,7 @@ def test_commit_table_skips_locking_when_table_property_disables_it() -> None:
14671467

14681468
def test_commit_table_skips_locking_when_catalog_property_disables_it() -> None:
14691469
"""When catalog property engine.hive.lock-enabled=false, commit_table must not lock/unlock."""
1470-
prop = {"uri": HIVE_METASTORE_FAKE_URL, TableProperties.HIVE_LOCK_ENABLED: "false"}
1470+
prop = {"uri": HIVE_METASTORE_FAKE_URL, HIVE_LOCK_ENABLED: "false"}
14711471
catalog = HiveCatalog(HIVE_CATALOG_NAME, **prop)
14721472
catalog._client = MagicMock()
14731473

@@ -1551,8 +1551,13 @@ def test_do_commit_env_context_includes_expected_params_when_lock_disabled() ->
15511551
mock_stage.return_value = mock_staged
15521552

15531553
catalog._do_commit(
1554-
mock_client, ("default", "my_table"), "default", "my_table",
1555-
requirements=(), updates=(), lock_enabled=False,
1554+
mock_client,
1555+
("default", "my_table"),
1556+
"default",
1557+
"my_table",
1558+
requirements=(),
1559+
updates=(),
1560+
lock_enabled=False,
15561561
)
15571562

15581563
mock_client.alter_table_with_environment_context.assert_called_once()
@@ -1594,8 +1599,13 @@ def test_do_commit_env_context_excludes_expected_params_when_lock_enabled() -> N
15941599
mock_stage.return_value = mock_staged
15951600

15961601
catalog._do_commit(
1597-
mock_client, ("default", "my_table"), "default", "my_table",
1598-
requirements=(), updates=(), lock_enabled=True,
1602+
mock_client,
1603+
("default", "my_table"),
1604+
"default",
1605+
"my_table",
1606+
requirements=(),
1607+
updates=(),
1608+
lock_enabled=True,
15991609
)
16001610

16011611
mock_client.alter_table_with_environment_context.assert_called_once()

0 commit comments

Comments
 (0)