Class SnapshotUtil
-
Method Summary
Modifier and TypeMethodDescriptionancestorIds(Snapshot snapshot, Function<Long, Snapshot> lookup) ancestorIdsBetween(long latestSnapshotId, Long oldestSnapshotId, Function<Long, Snapshot> lookup) ancestorsBetween(long latestSnapshotId, Long oldestSnapshotId, Function<Long, Snapshot> lookup) ancestorsBetween(Table table, long latestSnapshotId, Long oldestSnapshotId) ancestorsOf(long snapshotId, Function<Long, Snapshot> lookup) currentAncestorIds(Table table) Return the snapshot IDs for the ancestors of the current table state.currentAncestors(Table table) Returns an iterable that traverses the table's snapshots from the current to the last known ancestor.static booleanisAncestorOf(long snapshotId, long ancestorSnapshotId, Function<Long, Snapshot> lookup) Returns whether ancestorSnapshotId is an ancestor of snapshotId using the given lookup function.static booleanisAncestorOf(Table table, long ancestorSnapshotId) Returns whether ancestorSnapshotId is an ancestor of the table's current state.static booleanisAncestorOf(Table table, long snapshotId, long ancestorSnapshotId) Returns whether ancestorSnapshotId is an ancestor of snapshotId.static booleanisParentAncestorOf(Table table, long snapshotId, long ancestorParentSnapshotId) Returns whether some ancestor of snapshotId has parentId matches ancestorParentSnapshotIdstatic SnapshotlatestSnapshot(TableMetadata metadata, String branch) Fetch the snapshot at the head of the given branch in the given table.static SnapshotlatestSnapshot(Table table, String branch) Fetch the snapshot at the head of the given branch in the given table.static LongnullableSnapshotIdAsOfTime(Table table, long timestampMillis) static SnapshotoldestAncestor(Table table) Traverses the history of the table's current snapshot and finds the oldest Snapshot.static SnapshotoldestAncestorAfter(Table table, long timestampMillis) Traverses the history of the table's current snapshot, finds the oldest snapshot that was committed either at or after a given time.static SnapshotoldestAncestorOf(long snapshotId, Function<Long, Snapshot> lookup) Traverses the history and finds the oldest ancestor of the specified snapshot.static SnapshotoldestAncestorOf(Table table, long snapshotId) static SchemaschemaFor(TableMetadata metadata, String ref) Return the schema of the snapshot at a given ref.static SchemaReturns the schema of the table for the specified snapshot.static SchemaConvenience method for returning the schema of the table for a snapshot, when we have a snapshot id or a timestamp.static SchemaReturn the schema of the snapshot at a given ref.static SnapshotsnapshotAfter(Table table, long snapshotId) Traverses the history of the table's current snapshot and finds the snapshot with the given snapshot id as its parent.static longsnapshotIdAsOfTime(Table table, long timestampMillis) Returns the ID of the most recent snapshot for the table as of the timestamp.snapshotIdsBetween(Table table, long fromSnapshotId, long toSnapshotId) Returns list of snapshot ids in the range - (fromSnapshotId, toSnapshotId]
-
Method Details
-
isAncestorOf
Returns whether ancestorSnapshotId is an ancestor of snapshotId. -
isAncestorOf
public static boolean isAncestorOf(long snapshotId, long ancestorSnapshotId, Function<Long, Snapshot> lookup) Returns whether ancestorSnapshotId is an ancestor of snapshotId using the given lookup function. -
isAncestorOf
Returns whether ancestorSnapshotId is an ancestor of the table's current state. -
isParentAncestorOf
public static boolean isParentAncestorOf(Table table, long snapshotId, long ancestorParentSnapshotId) Returns whether some ancestor of snapshotId has parentId matches ancestorParentSnapshotId -
currentAncestors
Returns an iterable that traverses the table's snapshots from the current to the last known ancestor.- Parameters:
table- a Table- Returns:
- an iterable from the table's current snapshot to its last known ancestor
-
currentAncestorIds
Return the snapshot IDs for the ancestors of the current table state.Ancestor IDs are ordered by commit time, descending. The first ID is the current snapshot, followed by its parent, and so on.
- Parameters:
table- aTable- Returns:
- a set of snapshot IDs of the known ancestor snapshots, including the current ID
-
oldestAncestor
Traverses the history of the table's current snapshot and finds the oldest Snapshot.- Returns:
- null if there is no current snapshot in the table, else the oldest Snapshot.
-
oldestAncestorOf
-
oldestAncestorOf
Traverses the history and finds the oldest ancestor of the specified snapshot.Oldest ancestor is defined as the ancestor snapshot whose parent is null or has been expired. If the specified snapshot has no parent or parent has been expired, the specified snapshot itself is returned.
- Parameters:
snapshotId- the ID of the snapshot to find the oldest ancestorlookup- lookup function from snapshot ID to snapshot- Returns:
- null if there is no current snapshot in the table, else the oldest Snapshot.
-
ancestorsOf
-
oldestAncestorAfter
Traverses the history of the table's current snapshot, finds the oldest snapshot that was committed either at or after a given time.- Parameters:
table- a tabletimestampMillis- a timestamp in milliseconds- Returns:
- the first snapshot after the given timestamp, or null if the current snapshot is older than the timestamp
- Throws:
IllegalStateException- if the first ancestor after the given time can't be determined
-
snapshotIdsBetween
Returns list of snapshot ids in the range - (fromSnapshotId, toSnapshotId]This method assumes that fromSnapshotId is an ancestor of toSnapshotId.
-
ancestorIdsBetween
-
ancestorsBetween
-
ancestorsBetween
-
ancestorIds
-
newFiles
-
snapshotAfter
Traverses the history of the table's current snapshot and finds the snapshot with the given snapshot id as its parent.- Returns:
- the snapshot for which the given snapshot is the parent
- Throws:
IllegalArgumentException- when the given snapshotId is not found in the tableIllegalStateException- when the given snapshotId is not an ancestor of the current table state
-
snapshotIdAsOfTime
Returns the ID of the most recent snapshot for the table as of the timestamp.- Parameters:
table- aTabletimestampMillis- the timestamp in millis since the Unix epoch- Returns:
- the snapshot ID
- Throws:
IllegalArgumentException- when no snapshot is found in the table older than the timestamp
-
nullableSnapshotIdAsOfTime
-
schemaFor
Returns the schema of the table for the specified snapshot.- Parameters:
table- aTablesnapshotId- the ID of the snapshot- Returns:
- the schema
-
schemaFor
Convenience method for returning the schema of the table for a snapshot, when we have a snapshot id or a timestamp. Only one of them should be specified (non-null), or an IllegalArgumentException is thrown.- Parameters:
table- aTablesnapshotId- the ID of the snapshottimestampMillis- the timestamp in millis since the Unix epoch- Returns:
- the schema
- Throws:
IllegalArgumentException- if both snapshotId and timestampMillis are non-null
-
schemaFor
Return the schema of the snapshot at a given ref.If the ref does not exist or the ref is a branch, the table schema is returned because it will be the schema when the new branch is created. If the ref is a tag, then the snapshot schema is returned.
- Parameters:
table- aTableref- ref name of the table (nullable)- Returns:
- schema of the specific snapshot at the given ref
-
schemaFor
Return the schema of the snapshot at a given ref.If the ref does not exist or the ref is a branch, the table schema is returned because it will be the schema when the new branch is created. If the ref is a tag, then the snapshot schema is returned.
- Parameters:
metadata- aTableMetadataref- ref name of the table (nullable)- Returns:
- schema of the specific snapshot at the given branch
-
latestSnapshot
Fetch the snapshot at the head of the given branch in the given table.This method calls
Table.currentSnapshot()instead of using branch APITable.snapshot(String)for the main branch so that existing code still goes through the old code path to ensure backwards compatibility.- Parameters:
table- aTablebranch- branch name of the table (nullable)- Returns:
- the latest snapshot for the given branch
-
latestSnapshot
Fetch the snapshot at the head of the given branch in the given table.This method calls
TableMetadata.currentSnapshot()instead of using branch APITableMetadata.ref(String)} for the main branch so that existing code still goes through the old code path to ensure backwards compatibility.If branch does not exist, the table's latest snapshot is returned it will be the schema when the new branch is created.
- Parameters:
metadata- aTableMetadatabranch- branch name of the table metadata (nullable)- Returns:
- the latest snapshot for the given branch
-