Skip to content

Commit

Permalink
Move snapshot history expire table properties to constants (apache#1217)
Browse files Browse the repository at this point in the history
  • Loading branch information
ndrluis authored Oct 23, 2024
1 parent ff3a249 commit de976fe
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 5 deletions.
42 changes: 37 additions & 5 deletions pyiceberg/cli/console.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,34 @@
from pyiceberg.catalog import Catalog, load_catalog
from pyiceberg.cli.output import ConsoleOutput, JsonOutput, Output
from pyiceberg.exceptions import NoSuchNamespaceError, NoSuchPropertyException, NoSuchTableError
from pyiceberg.table import TableProperties
from pyiceberg.table.refs import SnapshotRef
from pyiceberg.utils.deprecated import deprecated
from pyiceberg.utils.properties import property_as_int

DEFAULT_MIN_SNAPSHOTS_TO_KEEP = 1
DEFAULT_MAX_SNAPSHOT_AGE_MS = 432000000

class DeprecatedConstants:
@property
@deprecated(
deprecated_in="0.8.0",
removed_in="0.9.0",
help_message="DEFAULT_MAX_SNAPSHOT_AGE_MS is deprecated. Use TableProperties.MAX_SNAPSHOT_AGE_MS_DEFAULT instead.",
)
def DEFAULT_MAX_SNAPSHOT_AGE_MS(self) -> int:
return 432000000

@property
@deprecated(
deprecated_in="0.8.0",
removed_in="0.9.0",
help_message="DEFAULT_MIN_SNAPSHOTS_TO_KEEP is deprecated. Use TableProperties.MIN_SNAPSHOTS_TO_KEEP_DEFAULT instead.",
)
def DEFAULT_MIN_SNAPSHOTS_TO_KEEP(self) -> int:
return 1


DEFAULT_MIN_SNAPSHOTS_TO_KEEP = DeprecatedConstants().DEFAULT_MIN_SNAPSHOTS_TO_KEEP
DEFAULT_MAX_SNAPSHOT_AGE_MS = DeprecatedConstants().DEFAULT_MAX_SNAPSHOT_AGE_MS


def catch_exception() -> Callable: # type: ignore
Expand Down Expand Up @@ -435,13 +459,21 @@ def list_refs(ctx: Context, identifier: str, type: str, verbose: bool) -> None:
def _retention_properties(ref: SnapshotRef, table_properties: Dict[str, str]) -> Dict[str, str]:
retention_properties = {}
if ref.snapshot_ref_type == "branch":
default_min_snapshots_to_keep = table_properties.get(
"history.expire.min-snapshots-to-keep", DEFAULT_MIN_SNAPSHOTS_TO_KEEP
default_min_snapshots_to_keep = property_as_int(
table_properties,
TableProperties.MIN_SNAPSHOTS_TO_KEEP,
TableProperties.MIN_SNAPSHOTS_TO_KEEP_DEFAULT,
)

default_max_snapshot_age_ms = property_as_int(
table_properties,
TableProperties.MAX_SNAPSHOT_AGE_MS,
TableProperties.MAX_SNAPSHOT_AGE_MS_DEFAULT,
)

retention_properties["min_snapshots_to_keep"] = (
str(ref.min_snapshots_to_keep) if ref.min_snapshots_to_keep else str(default_min_snapshots_to_keep)
)
default_max_snapshot_age_ms = table_properties.get("history.expire.max-snapshot-age-ms", DEFAULT_MAX_SNAPSHOT_AGE_MS)
retention_properties["max_snapshot_age_ms"] = (
str(ref.max_snapshot_age_ms) if ref.max_snapshot_age_ms else str(default_max_snapshot_age_ms)
)
Expand Down
6 changes: 6 additions & 0 deletions pyiceberg/table/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,12 @@ class TableProperties:
METADATA_PREVIOUS_VERSIONS_MAX = "write.metadata.previous-versions-max"
METADATA_PREVIOUS_VERSIONS_MAX_DEFAULT = 100

MAX_SNAPSHOT_AGE_MS = "history.expire.max-snapshot-age-ms"
MAX_SNAPSHOT_AGE_MS_DEFAULT = 5 * 24 * 60 * 60 * 1000 # 5 days

MIN_SNAPSHOTS_TO_KEEP = "history.expire.min-snapshots-to-keep"
MIN_SNAPSHOTS_TO_KEEP_DEFAULT = 1


class Transaction:
_table: Table
Expand Down

0 comments on commit de976fe

Please sign in to comment.