Skip to content

Commit de976fe

Browse files
authored
Move snapshot history expire table properties to constants (#1217)
1 parent ff3a249 commit de976fe

File tree

2 files changed

+43
-5
lines changed

2 files changed

+43
-5
lines changed

pyiceberg/cli/console.py

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,34 @@
3232
from pyiceberg.catalog import Catalog, load_catalog
3333
from pyiceberg.cli.output import ConsoleOutput, JsonOutput, Output
3434
from pyiceberg.exceptions import NoSuchNamespaceError, NoSuchPropertyException, NoSuchTableError
35+
from pyiceberg.table import TableProperties
3536
from pyiceberg.table.refs import SnapshotRef
37+
from pyiceberg.utils.deprecated import deprecated
38+
from pyiceberg.utils.properties import property_as_int
3639

37-
DEFAULT_MIN_SNAPSHOTS_TO_KEEP = 1
38-
DEFAULT_MAX_SNAPSHOT_AGE_MS = 432000000
40+
41+
class DeprecatedConstants:
42+
@property
43+
@deprecated(
44+
deprecated_in="0.8.0",
45+
removed_in="0.9.0",
46+
help_message="DEFAULT_MAX_SNAPSHOT_AGE_MS is deprecated. Use TableProperties.MAX_SNAPSHOT_AGE_MS_DEFAULT instead.",
47+
)
48+
def DEFAULT_MAX_SNAPSHOT_AGE_MS(self) -> int:
49+
return 432000000
50+
51+
@property
52+
@deprecated(
53+
deprecated_in="0.8.0",
54+
removed_in="0.9.0",
55+
help_message="DEFAULT_MIN_SNAPSHOTS_TO_KEEP is deprecated. Use TableProperties.MIN_SNAPSHOTS_TO_KEEP_DEFAULT instead.",
56+
)
57+
def DEFAULT_MIN_SNAPSHOTS_TO_KEEP(self) -> int:
58+
return 1
59+
60+
61+
DEFAULT_MIN_SNAPSHOTS_TO_KEEP = DeprecatedConstants().DEFAULT_MIN_SNAPSHOTS_TO_KEEP
62+
DEFAULT_MAX_SNAPSHOT_AGE_MS = DeprecatedConstants().DEFAULT_MAX_SNAPSHOT_AGE_MS
3963

4064

4165
def catch_exception() -> Callable: # type: ignore
@@ -435,13 +459,21 @@ def list_refs(ctx: Context, identifier: str, type: str, verbose: bool) -> None:
435459
def _retention_properties(ref: SnapshotRef, table_properties: Dict[str, str]) -> Dict[str, str]:
436460
retention_properties = {}
437461
if ref.snapshot_ref_type == "branch":
438-
default_min_snapshots_to_keep = table_properties.get(
439-
"history.expire.min-snapshots-to-keep", DEFAULT_MIN_SNAPSHOTS_TO_KEEP
462+
default_min_snapshots_to_keep = property_as_int(
463+
table_properties,
464+
TableProperties.MIN_SNAPSHOTS_TO_KEEP,
465+
TableProperties.MIN_SNAPSHOTS_TO_KEEP_DEFAULT,
440466
)
467+
468+
default_max_snapshot_age_ms = property_as_int(
469+
table_properties,
470+
TableProperties.MAX_SNAPSHOT_AGE_MS,
471+
TableProperties.MAX_SNAPSHOT_AGE_MS_DEFAULT,
472+
)
473+
441474
retention_properties["min_snapshots_to_keep"] = (
442475
str(ref.min_snapshots_to_keep) if ref.min_snapshots_to_keep else str(default_min_snapshots_to_keep)
443476
)
444-
default_max_snapshot_age_ms = table_properties.get("history.expire.max-snapshot-age-ms", DEFAULT_MAX_SNAPSHOT_AGE_MS)
445477
retention_properties["max_snapshot_age_ms"] = (
446478
str(ref.max_snapshot_age_ms) if ref.max_snapshot_age_ms else str(default_max_snapshot_age_ms)
447479
)

pyiceberg/table/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,12 @@ class TableProperties:
206206
METADATA_PREVIOUS_VERSIONS_MAX = "write.metadata.previous-versions-max"
207207
METADATA_PREVIOUS_VERSIONS_MAX_DEFAULT = 100
208208

209+
MAX_SNAPSHOT_AGE_MS = "history.expire.max-snapshot-age-ms"
210+
MAX_SNAPSHOT_AGE_MS_DEFAULT = 5 * 24 * 60 * 60 * 1000 # 5 days
211+
212+
MIN_SNAPSHOTS_TO_KEEP = "history.expire.min-snapshots-to-keep"
213+
MIN_SNAPSHOTS_TO_KEEP_DEFAULT = 1
214+
209215

210216
class Transaction:
211217
_table: Table

0 commit comments

Comments
 (0)