Package org.apache.iceberg.util
Class SnapshotUtil
- java.lang.Object
-
- org.apache.iceberg.util.SnapshotUtil
-
public class SnapshotUtil extends java.lang.Object
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method 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>
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(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 java.util.List<DataFile>
newFiles(java.lang.Long baseSnapshotId, long latestSnapshotId, java.util.function.Function<java.lang.Long,Snapshot> lookup)
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 and finds the first snapshot committed after the given time.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 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]
-
-
-
Method Detail
-
isAncestorOf
public static boolean isAncestorOf(Table table, long snapshotId, long ancestorSnapshotId)
Returns whether ancestorSnapshotId is an ancestor of snapshotId.
-
isAncestorOf
public static boolean isAncestorOf(Table table, long ancestorSnapshotId)
Returns whether ancestorSnapshotId is an ancestor of the table's current state.
-
currentAncestors
public 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.- Parameters:
table
- a Table- Returns:
- an iterable from the table's current snapshot to its last known ancestor
-
currentAncestorIds
public static java.util.List<java.lang.Long> currentAncestorIds(Table table)
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
public static Snapshot oldestAncestor(Table table)
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.
-
ancestorsOf
public static java.lang.Iterable<Snapshot> ancestorsOf(long snapshotId, java.util.function.Function<java.lang.Long,Snapshot> lookup)
-
oldestAncestorAfter
public static Snapshot oldestAncestorAfter(Table table, long timestampMillis)
Traverses the history of the table's current snapshot and finds the first snapshot committed after the 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:
java.lang.IllegalStateException
- if the first ancestor after the given time can't be determined
-
snapshotIdsBetween
public static java.util.List<java.lang.Long> snapshotIdsBetween(Table table, long fromSnapshotId, long toSnapshotId)
Returns list of snapshot ids in the range - (fromSnapshotId, toSnapshotId]This method assumes that fromSnapshotId is an ancestor of toSnapshotId.
-
ancestorIdsBetween
public static java.lang.Iterable<java.lang.Long> ancestorIdsBetween(long latestSnapshotId, java.lang.Long oldestSnapshotId, java.util.function.Function<java.lang.Long,Snapshot> lookup)
-
ancestorsBetween
public static java.lang.Iterable<Snapshot> ancestorsBetween(long latestSnapshotId, java.lang.Long oldestSnapshotId, java.util.function.Function<java.lang.Long,Snapshot> lookup)
-
ancestorIds
public static java.util.List<java.lang.Long> ancestorIds(Snapshot snapshot, java.util.function.Function<java.lang.Long,Snapshot> lookup)
-
newFiles
public static java.util.List<DataFile> newFiles(java.lang.Long baseSnapshotId, long latestSnapshotId, java.util.function.Function<java.lang.Long,Snapshot> lookup)
-
snapshotAfter
public 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.- Returns:
- the snapshot for which the given snapshot is the parent
- Throws:
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 state
-
snapshotIdAsOfTime
public static long snapshotIdAsOfTime(Table table, long timestampMillis)
Returns the ID of the most recent snapshot for the table as of the timestamp.- Parameters:
table
- aTable
timestampMillis
- the timestamp in millis since the Unix epoch- Returns:
- the snapshot ID
- Throws:
java.lang.IllegalArgumentException
- when no snapshot is found in the table older than the timestamp
-
schemaFor
public static Schema schemaFor(Table table, long snapshotId)
Returns the schema of the table for the specified snapshot.- Parameters:
table
- aTable
snapshotId
- the ID of the snapshot- Returns:
- the schema
-
schemaFor
public 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. Only one of them should be specified (non-null), or an IllegalArgumentException is thrown.- Parameters:
table
- aTable
snapshotId
- the ID of the snapshottimestampMillis
- the timestamp in millis since the Unix epoch- Returns:
- the schema
- Throws:
java.lang.IllegalArgumentException
- if both snapshotId and timestampMillis are non-null
-
-