public class SnapshotUtil
extends java.lang.Object
Modifier and Type | Method and Description |
---|---|
static java.util.List<java.lang.Long> |
ancestorIds(Snapshot snapshot,
java.util.function.Function<java.lang.Long,Snapshot> lookup) |
static java.lang.Iterable<java.lang.Long> |
ancestorIdsBetween(long latestSnapshotId,
java.lang.Long oldestSnapshotId,
java.util.function.Function<java.lang.Long,Snapshot> lookup) |
static java.lang.Iterable<Snapshot> |
ancestorsBetween(long latestSnapshotId,
java.lang.Long oldestSnapshotId,
java.util.function.Function<java.lang.Long,Snapshot> lookup) |
static java.lang.Iterable<Snapshot> |
ancestorsBetween(Table table,
long latestSnapshotId,
java.lang.Long oldestSnapshotId) |
static java.lang.Iterable<Snapshot> |
ancestorsOf(long snapshotId,
java.util.function.Function<java.lang.Long,Snapshot> lookup) |
static java.util.List<java.lang.Long> |
currentAncestorIds(Table table)
Return the snapshot IDs for the ancestors of the current table state.
|
static java.lang.Iterable<Snapshot> |
currentAncestors(Table table)
Returns an iterable that traverses the table's snapshots from the current to the last known
ancestor.
|
static boolean |
isAncestorOf(long snapshotId,
long ancestorSnapshotId,
java.util.function.Function<java.lang.Long,Snapshot> lookup)
Returns whether ancestorSnapshotId is an ancestor of snapshotId using the given lookup
function.
|
static boolean |
isAncestorOf(Table table,
long ancestorSnapshotId)
Returns whether ancestorSnapshotId is an ancestor of the table's current state.
|
static boolean |
isAncestorOf(Table table,
long snapshotId,
long ancestorSnapshotId)
Returns whether ancestorSnapshotId is an ancestor of snapshotId.
|
static boolean |
isParentAncestorOf(Table table,
long snapshotId,
long ancestorParentSnapshotId)
Returns whether some ancestor of snapshotId has parentId matches ancestorParentSnapshotId
|
static Snapshot |
latestSnapshot(TableMetadata metadata,
java.lang.String branch)
Fetch the snapshot at the head of the given branch in the given table.
|
static Snapshot |
latestSnapshot(Table table,
java.lang.String branch)
Fetch the snapshot at the head of the given branch in the given table.
|
static java.util.List<DataFile> |
newFiles(java.lang.Long baseSnapshotId,
long latestSnapshotId,
java.util.function.Function<java.lang.Long,Snapshot> lookup,
FileIO io) |
static java.lang.Long |
nullableSnapshotIdAsOfTime(Table table,
long timestampMillis) |
static Snapshot |
oldestAncestor(Table table)
Traverses the history of the table's current snapshot and finds the oldest Snapshot.
|
static Snapshot |
oldestAncestorAfter(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 Snapshot |
oldestAncestorOf(long snapshotId,
java.util.function.Function<java.lang.Long,Snapshot> lookup)
Traverses the history and finds the oldest ancestor of the specified snapshot.
|
static Snapshot |
oldestAncestorOf(Table table,
long snapshotId) |
static Schema |
schemaFor(Table table,
long snapshotId)
Returns the schema of the table for the specified snapshot.
|
static Schema |
schemaFor(Table table,
java.lang.Long snapshotId,
java.lang.Long timestampMillis)
Convenience method for returning the schema of the table for a snapshot, when we have a
snapshot id or a timestamp.
|
static Schema |
schemaFor(TableMetadata metadata,
java.lang.String ref)
Return the schema of the snapshot at a given ref.
|
static Schema |
schemaFor(Table table,
java.lang.String ref)
Return the schema of the snapshot at a given ref.
|
static Snapshot |
snapshotAfter(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 long |
snapshotIdAsOfTime(Table table,
long timestampMillis)
Returns the ID of the most recent snapshot for the table as of the timestamp.
|
static java.util.List<java.lang.Long> |
snapshotIdsBetween(Table table,
long fromSnapshotId,
long toSnapshotId)
Returns list of snapshot ids in the range - (fromSnapshotId, toSnapshotId]
|
public static boolean isAncestorOf(Table table, long snapshotId, long ancestorSnapshotId)
public static boolean isAncestorOf(long snapshotId, long ancestorSnapshotId, java.util.function.Function<java.lang.Long,Snapshot> lookup)
public static boolean isAncestorOf(Table table, long ancestorSnapshotId)
public static boolean isParentAncestorOf(Table table, long snapshotId, long ancestorParentSnapshotId)
public static java.lang.Iterable<Snapshot> currentAncestors(Table table)
table
- a Tablepublic static java.util.List<java.lang.Long> currentAncestorIds(Table table)
Ancestor IDs are ordered by commit time, descending. The first ID is the current snapshot, followed by its parent, and so on.
table
- a Table
public static Snapshot oldestAncestor(Table table)
public static Snapshot oldestAncestorOf(long snapshotId, java.util.function.Function<java.lang.Long,Snapshot> lookup)
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.
snapshotId
- the ID of the snapshot to find the oldest ancestorlookup
- lookup function from snapshot ID to snapshotpublic static java.lang.Iterable<Snapshot> ancestorsOf(long snapshotId, java.util.function.Function<java.lang.Long,Snapshot> lookup)
public static Snapshot oldestAncestorAfter(Table table, long timestampMillis)
table
- a tabletimestampMillis
- a timestamp in millisecondsjava.lang.IllegalStateException
- if the first ancestor after the given time can't be determinedpublic static java.util.List<java.lang.Long> snapshotIdsBetween(Table table, long fromSnapshotId, long toSnapshotId)
This method assumes that fromSnapshotId is an ancestor of toSnapshotId.
public static java.lang.Iterable<java.lang.Long> ancestorIdsBetween(long latestSnapshotId, java.lang.Long oldestSnapshotId, java.util.function.Function<java.lang.Long,Snapshot> lookup)
public static java.lang.Iterable<Snapshot> ancestorsBetween(Table table, long latestSnapshotId, java.lang.Long oldestSnapshotId)
public static java.lang.Iterable<Snapshot> ancestorsBetween(long latestSnapshotId, java.lang.Long oldestSnapshotId, java.util.function.Function<java.lang.Long,Snapshot> lookup)
public static java.util.List<java.lang.Long> ancestorIds(Snapshot snapshot, java.util.function.Function<java.lang.Long,Snapshot> lookup)
public static java.util.List<DataFile> newFiles(java.lang.Long baseSnapshotId, long latestSnapshotId, java.util.function.Function<java.lang.Long,Snapshot> lookup, FileIO io)
public static Snapshot snapshotAfter(Table table, long snapshotId)
java.lang.IllegalArgumentException
- when the given snapshotId is not found in the tablejava.lang.IllegalStateException
- when the given snapshotId is not an ancestor of the current table
statepublic static long snapshotIdAsOfTime(Table table, long timestampMillis)
table
- a Table
timestampMillis
- the timestamp in millis since the Unix epochjava.lang.IllegalArgumentException
- when no snapshot is found in the table older than the
timestamppublic static java.lang.Long nullableSnapshotIdAsOfTime(Table table, long timestampMillis)
public static Schema schemaFor(Table table, long snapshotId)
table
- a Table
snapshotId
- the ID of the snapshotpublic static Schema schemaFor(Table table, java.lang.Long snapshotId, java.lang.Long timestampMillis)
table
- a Table
snapshotId
- the ID of the snapshottimestampMillis
- the timestamp in millis since the Unix epochjava.lang.IllegalArgumentException
- if both snapshotId and timestampMillis are non-nullpublic static Schema schemaFor(Table table, java.lang.String 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.
table
- a Table
ref
- ref name of the table (nullable)public static Schema schemaFor(TableMetadata metadata, java.lang.String 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.
metadata
- a TableMetadata
ref
- ref name of the table (nullable)public static Snapshot latestSnapshot(Table table, java.lang.String branch)
This method calls Table.currentSnapshot()
instead of using branch API Table.snapshot(String)
for the main branch so that existing code still goes through the old
code path to ensure backwards compatibility.
table
- a Table
branch
- branch name of the table (nullable)public static Snapshot latestSnapshot(TableMetadata metadata, java.lang.String branch)
This method calls TableMetadata.currentSnapshot()
instead of using branch API TableMetadata.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.
metadata
- a TableMetadata
branch
- branch name of the table metadata (nullable)