|
32 | 32 | from pyiceberg.catalog import Catalog, load_catalog
|
33 | 33 | from pyiceberg.cli.output import ConsoleOutput, JsonOutput, Output
|
34 | 34 | from pyiceberg.exceptions import NoSuchNamespaceError, NoSuchPropertyException, NoSuchTableError
|
| 35 | +from pyiceberg.table import TableProperties |
35 | 36 | from pyiceberg.table.refs import SnapshotRef
|
| 37 | +from pyiceberg.utils.deprecated import deprecated |
| 38 | +from pyiceberg.utils.properties import property_as_int |
36 | 39 |
|
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 |
39 | 63 |
|
40 | 64 |
|
41 | 65 | def catch_exception() -> Callable: # type: ignore
|
@@ -435,13 +459,21 @@ def list_refs(ctx: Context, identifier: str, type: str, verbose: bool) -> None:
|
435 | 459 | def _retention_properties(ref: SnapshotRef, table_properties: Dict[str, str]) -> Dict[str, str]:
|
436 | 460 | retention_properties = {}
|
437 | 461 | 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, |
440 | 466 | )
|
| 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 | + |
441 | 474 | retention_properties["min_snapshots_to_keep"] = (
|
442 | 475 | str(ref.min_snapshots_to_keep) if ref.min_snapshots_to_keep else str(default_min_snapshots_to_keep)
|
443 | 476 | )
|
444 |
| - default_max_snapshot_age_ms = table_properties.get("history.expire.max-snapshot-age-ms", DEFAULT_MAX_SNAPSHOT_AGE_MS) |
445 | 477 | retention_properties["max_snapshot_age_ms"] = (
|
446 | 478 | str(ref.max_snapshot_age_ms) if ref.max_snapshot_age_ms else str(default_max_snapshot_age_ms)
|
447 | 479 | )
|
|
0 commit comments