iceberg-cpp
Loading...
Searching...
No Matches
Static Public Member Functions | List of all members
iceberg::SnapshotUtil Class Reference

Utility functions for working with snapshots. More...

#include <snapshot_util_internal.h>

Static Public Member Functions

static Result< std::vector< std::shared_ptr< Snapshot > > > AncestorsOf (const Table &table, int64_t snapshot_id)
 Returns a vector of ancestors of the given snapshot.
 
static Result< std::vector< std::shared_ptr< Snapshot > > > AncestorsOf (const TableMetadata &metadata, int64_t snapshot_id)
 Returns a vector of ancestors of the given snapshot.
 
static Result< std::vector< std::shared_ptr< Snapshot > > > AncestorsOf (int64_t snapshot_id, const std::function< Result< std::shared_ptr< Snapshot > >(int64_t)> &lookup)
 Returns a vector of ancestors of the given snapshot.
 
static Result< bool > IsAncestorOf (const Table &table, int64_t ancestor_snapshot_id)
 Returns whether ancestor_snapshot_id is an ancestor of the table's current state.
 
static Result< bool > IsAncestorOf (const TableMetadata &metadata, int64_t ancestor_snapshot_id)
 Returns whether ancestor_snapshot_id is an ancestor of the metadata's current state.
 
static Result< bool > IsAncestorOf (const Table &table, int64_t snapshot_id, int64_t ancestor_snapshot_id)
 Returns whether ancestor_snapshot_id is an ancestor of snapshot_id.
 
static Result< bool > IsAncestorOf (const TableMetadata &metadata, int64_t snapshot_id, int64_t ancestor_snapshot_id)
 Returns whether ancestor_snapshot_id is an ancestor of snapshot_id.
 
static Result< bool > IsAncestorOf (int64_t snapshot_id, int64_t ancestor_snapshot_id, const std::function< Result< std::shared_ptr< Snapshot > >(int64_t)> &lookup)
 Returns whether ancestor_snapshot_id is an ancestor of snapshot_id using the given lookup function.
 
static Result< bool > IsParentAncestorOf (const Table &table, int64_t snapshot_id, int64_t ancestor_parent_snapshot_id)
 Returns whether some ancestor of snapshot_id has parentId matches ancestor_parent_snapshot_id.
 
static Result< bool > IsParentAncestorOf (const TableMetadata &metadata, int64_t snapshot_id, int64_t ancestor_parent_snapshot_id)
 Returns whether some ancestor of snapshot_id has parentId matches ancestor_parent_snapshot_id.
 
static Result< bool > IsParentAncestorOf (int64_t snapshot_id, int64_t ancestor_parent_snapshot_id, const std::function< Result< std::shared_ptr< Snapshot > >(int64_t)> &lookup)
 Returns whether some ancestor of snapshot_id has parentId matches ancestor_parent_snapshot_id.
 
static Result< std::vector< std::shared_ptr< Snapshot > > > CurrentAncestors (const Table &table)
 Returns a vector that traverses the table's snapshots from the current to the last known ancestor.
 
static Result< std::vector< std::shared_ptr< Snapshot > > > CurrentAncestors (const TableMetadata &metadata)
 Returns a vector that traverses the metadata's snapshots from the current to the last known ancestor.
 
static Result< std::vector< int64_t > > CurrentAncestorIds (const Table &table)
 Returns the snapshot IDs for the ancestors of the current table state.
 
static Result< std::optional< std::shared_ptr< Snapshot > > > OldestAncestor (const Table &table)
 Traverses the history of the table's current snapshot and finds the oldest Snapshot.
 
static Result< std::optional< std::shared_ptr< Snapshot > > > OldestAncestorOf (const Table &table, int64_t snapshot_id)
 Traverses the history and finds the oldest ancestor of the specified snapshot.
 
static Result< std::optional< std::shared_ptr< Snapshot > > > OldestAncestorOf (const TableMetadata &metadata, int64_t snapshot_id)
 Traverses the history and finds the oldest ancestor of the specified snapshot.
 
static Result< std::optional< std::shared_ptr< Snapshot > > > OldestAncestorAfter (const Table &table, TimePointMs timestamp_ms)
 Traverses the history of the table's current snapshot, finds the oldest snapshot that was committed either at or after a given time.
 
static Result< std::vector< int64_t > > SnapshotIdsBetween (const Table &table, int64_t from_snapshot_id, int64_t to_snapshot_id)
 Returns list of snapshot ids in the range (from_snapshot_id,to_snapshot_id].
 
static Result< std::vector< int64_t > > AncestorIdsBetween (const Table &table, int64_t latest_snapshot_id, const std::optional< int64_t > &oldest_snapshot_id)
 Returns a vector of ancestor IDs between two snapshots.
 
static Result< std::vector< std::shared_ptr< Snapshot > > > AncestorsBetween (const Table &table, int64_t latest_snapshot_id, std::optional< int64_t > oldest_snapshot_id)
 Returns a vector of ancestors between two snapshots.
 
static Result< std::vector< std::shared_ptr< Snapshot > > > AncestorsBetween (const TableMetadata &metadata, int64_t latest_snapshot_id, std::optional< int64_t > oldest_snapshot_id)
 Returns a vector of ancestors between two snapshots.
 
static Result< std::shared_ptr< Snapshot > > SnapshotAfter (const Table &table, int64_t snapshot_id)
 Traverses the history of the table's current snapshot and finds the snapshot with the given snapshot id as its parent.
 
static Result< int64_t > SnapshotIdAsOfTime (const Table &table, TimePointMs timestamp_ms)
 Returns the ID of the most recent snapshot for the table as of the timestamp.
 
static Result< int64_t > SnapshotIdAsOfTime (const TableMetadata &metadata, TimePointMs timestamp_ms)
 Returns the ID of the most recent snapshot for the table as of the timestamp.
 
static std::optional< int64_t > OptionalSnapshotIdAsOfTime (const Table &table, TimePointMs timestamp_ms)
 Returns the ID of the most recent snapshot for the table as of the timestamp, or nullopt if not found.
 
static Result< std::shared_ptr< Schema > > SchemaFor (const Table &table, int64_t snapshot_id)
 Returns the schema of the table for the specified snapshot.
 
static Result< std::shared_ptr< Schema > > SchemaFor (const Table &table, TimePointMs timestamp_ms)
 Returns the schema of the table for the specified timestamp.
 
static Result< std::shared_ptr< Schema > > SchemaFor (const Table &table, const std::string &ref)
 Return the schema of the snapshot at a given ref.
 
static Result< std::shared_ptr< Schema > > SchemaFor (const TableMetadata &metadata, const std::string &ref)
 Return the schema of the snapshot at a given ref.
 
static Result< std::shared_ptr< Snapshot > > LatestSnapshot (const Table &table, const std::string &branch)
 Fetch the snapshot at the head of the given branch in the given table.
 
static Result< std::shared_ptr< Snapshot > > LatestSnapshot (const TableMetadata &metadata, const std::string &branch)
 Fetch the snapshot at the head of the given branch in the given table.
 
static Result< std::shared_ptr< Snapshot > > OptionalLatestSnapshot (const TableMetadata &metadata, const std::string &branch)
 Fetch the snapshot at the head of the given branch in the given table.
 
static int64_t GenerateSnapshotId ()
 Generate a new snapshot ID.
 
static int64_t GenerateSnapshotId (const TableMetadata &metadata)
 Generate a new snapshot ID for the given metadata.
 

Detailed Description

Utility functions for working with snapshots.

Note
All the returned std::shared_ptr<Snapshot> are guaranteed to be not null.

Member Function Documentation

◆ AncestorIdsBetween()

Result< std::vector< int64_t > > iceberg::SnapshotUtil::AncestorIdsBetween ( const Table table,
int64_t  latest_snapshot_id,
const std::optional< int64_t > &  oldest_snapshot_id 
)
static

Returns a vector of ancestor IDs between two snapshots.

Parameters
tableThe table
latest_snapshot_idThe latest snapshot ID
oldest_snapshot_idThe oldest snapshot ID (optional, nullopt means all ancestors)
Returns
A vector of snapshot IDs between the two snapshots

◆ AncestorsBetween() [1/2]

Result< std::vector< std::shared_ptr< Snapshot > > > iceberg::SnapshotUtil::AncestorsBetween ( const Table table,
int64_t  latest_snapshot_id,
std::optional< int64_t >  oldest_snapshot_id 
)
static

Returns a vector of ancestors between two snapshots.

Parameters
tableThe table
latest_snapshot_idThe latest snapshot ID
oldest_snapshot_idThe oldest snapshot ID (optional, nullopt means all ancestors)
Returns
A vector of ancestor snapshots between the two snapshots

◆ AncestorsBetween() [2/2]

Result< std::vector< std::shared_ptr< Snapshot > > > iceberg::SnapshotUtil::AncestorsBetween ( const TableMetadata metadata,
int64_t  latest_snapshot_id,
std::optional< int64_t >  oldest_snapshot_id 
)
static

Returns a vector of ancestors between two snapshots.

Parameters
metadataThe table metadata
latest_snapshot_idThe latest snapshot ID
oldest_snapshot_idThe oldest snapshot ID (optional, nullopt means all ancestors)
Returns
A vector of ancestor snapshots between the two snapshots

◆ AncestorsOf() [1/3]

Result< std::vector< std::shared_ptr< Snapshot > > > iceberg::SnapshotUtil::AncestorsOf ( const Table table,
int64_t  snapshot_id 
)
static

Returns a vector of ancestors of the given snapshot.

Parameters
tableThe table
snapshot_idThe snapshot ID to start from
Returns
A vector of ancestor snapshots

◆ AncestorsOf() [2/3]

Result< std::vector< std::shared_ptr< Snapshot > > > iceberg::SnapshotUtil::AncestorsOf ( const TableMetadata metadata,
int64_t  snapshot_id 
)
static

Returns a vector of ancestors of the given snapshot.

Parameters
metadataThe table metadata
snapshot_idThe snapshot ID to start from
Returns
A vector of ancestor snapshots

◆ AncestorsOf() [3/3]

Result< std::vector< std::shared_ptr< Snapshot > > > iceberg::SnapshotUtil::AncestorsOf ( int64_t  snapshot_id,
const std::function< Result< std::shared_ptr< Snapshot > >(int64_t)> &  lookup 
)
static

Returns a vector of ancestors of the given snapshot.

Parameters
snapshot_idThe snapshot ID to start from
lookupA function to look up snapshots by ID
Returns
A vector of ancestor snapshots

◆ CurrentAncestorIds()

Result< std::vector< int64_t > > iceberg::SnapshotUtil::CurrentAncestorIds ( const Table table)
static

Returns 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
tableThe table
Returns
A vector of snapshot IDs of the known ancestor snapshots, including the current ID

◆ CurrentAncestors() [1/2]

Result< std::vector< std::shared_ptr< Snapshot > > > iceberg::SnapshotUtil::CurrentAncestors ( const Table table)
static

Returns a vector that traverses the table's snapshots from the current to the last known ancestor.

Parameters
tableThe table
Returns
A vector from the table's current snapshot to its last known ancestor

◆ CurrentAncestors() [2/2]

Result< std::vector< std::shared_ptr< Snapshot > > > iceberg::SnapshotUtil::CurrentAncestors ( const TableMetadata metadata)
static

Returns a vector that traverses the metadata's snapshots from the current to the last known ancestor.

Parameters
metadataThe table metadata
Returns
A vector from the metadata's current snapshot to its last known ancestor

◆ GenerateSnapshotId()

int64_t iceberg::SnapshotUtil::GenerateSnapshotId ( const TableMetadata metadata)
static

Generate a new snapshot ID for the given metadata.

Parameters
metadataThe table metadata
Returns
A new snapshot ID

◆ IsAncestorOf() [1/5]

Result< bool > iceberg::SnapshotUtil::IsAncestorOf ( const Table table,
int64_t  ancestor_snapshot_id 
)
static

Returns whether ancestor_snapshot_id is an ancestor of the table's current state.

Parameters
tableThe table to check
ancestor_snapshot_idThe ancestor snapshot ID to check for
Returns
true if ancestor_snapshot_id is an ancestor of the current snapshot

◆ IsAncestorOf() [2/5]

Result< bool > iceberg::SnapshotUtil::IsAncestorOf ( const Table table,
int64_t  snapshot_id,
int64_t  ancestor_snapshot_id 
)
static

Returns whether ancestor_snapshot_id is an ancestor of snapshot_id.

Parameters
tableThe table to check
snapshot_idThe snapshot ID to check
ancestor_snapshot_idThe ancestor snapshot ID to check for
Returns
true if ancestor_snapshot_id is an ancestor of snapshot_id

◆ IsAncestorOf() [3/5]

Result< bool > iceberg::SnapshotUtil::IsAncestorOf ( const TableMetadata metadata,
int64_t  ancestor_snapshot_id 
)
static

Returns whether ancestor_snapshot_id is an ancestor of the metadata's current state.

Parameters
metadataThe table metadata to check
ancestor_snapshot_idThe ancestor snapshot ID to check for
Returns
true if ancestor_snapshot_id is an ancestor of the current snapshot

◆ IsAncestorOf() [4/5]

Result< bool > iceberg::SnapshotUtil::IsAncestorOf ( const TableMetadata metadata,
int64_t  snapshot_id,
int64_t  ancestor_snapshot_id 
)
static

Returns whether ancestor_snapshot_id is an ancestor of snapshot_id.

Parameters
metadataThe table metadata to check
snapshot_idThe snapshot ID to check
ancestor_snapshot_idThe ancestor snapshot ID to check for
Returns
true if ancestor_snapshot_id is an ancestor of snapshot_id

◆ IsAncestorOf() [5/5]

Result< bool > iceberg::SnapshotUtil::IsAncestorOf ( int64_t  snapshot_id,
int64_t  ancestor_snapshot_id,
const std::function< Result< std::shared_ptr< Snapshot > >(int64_t)> &  lookup 
)
static

Returns whether ancestor_snapshot_id is an ancestor of snapshot_id using the given lookup function.

Parameters
snapshot_idThe snapshot ID to check
ancestor_snapshot_idThe ancestor snapshot ID to check for
lookupFunction to lookup snapshots by ID
Returns
true if ancestor_snapshot_id is an ancestor of snapshot_id

◆ IsParentAncestorOf() [1/3]

Result< bool > iceberg::SnapshotUtil::IsParentAncestorOf ( const Table table,
int64_t  snapshot_id,
int64_t  ancestor_parent_snapshot_id 
)
static

Returns whether some ancestor of snapshot_id has parentId matches ancestor_parent_snapshot_id.

Parameters
tableThe table to check
snapshot_idThe snapshot ID to check
ancestor_parent_snapshot_idThe ancestor parent snapshot ID to check for
Returns
true if any ancestor has the given parent ID

◆ IsParentAncestorOf() [2/3]

Result< bool > iceberg::SnapshotUtil::IsParentAncestorOf ( const TableMetadata metadata,
int64_t  snapshot_id,
int64_t  ancestor_parent_snapshot_id 
)
static

Returns whether some ancestor of snapshot_id has parentId matches ancestor_parent_snapshot_id.

Parameters
metadataThe table metadata to check
snapshot_idThe snapshot ID to check
ancestor_parent_snapshot_idThe ancestor parent snapshot ID to check for
Returns
true if any ancestor has the given parent ID

◆ IsParentAncestorOf() [3/3]

Result< bool > iceberg::SnapshotUtil::IsParentAncestorOf ( int64_t  snapshot_id,
int64_t  ancestor_parent_snapshot_id,
const std::function< Result< std::shared_ptr< Snapshot > >(int64_t)> &  lookup 
)
static

Returns whether some ancestor of snapshot_id has parentId matches ancestor_parent_snapshot_id.

Parameters
snapshot_idThe snapshot ID to check
ancestor_parent_snapshot_idThe ancestor parent snapshot ID to check for
lookupFunction to lookup snapshots by ID
Returns
true if any ancestor has the given parent ID

◆ LatestSnapshot() [1/2]

Result< std::shared_ptr< Snapshot > > iceberg::SnapshotUtil::LatestSnapshot ( const Table table,
const std::string &  branch 
)
static

Fetch the snapshot at the head of the given branch in the given table.

This method calls TableMetadata::Snapshot() instead of using branch API for the main branch so that existing code still goes through the old code path to ensure backwards compatibility.

Parameters
tableThe table
branchBranch name of the table (empty string means main branch)
Returns
The latest snapshot for the given branch, or NotFoundError.

◆ LatestSnapshot() [2/2]

Result< std::shared_ptr< Snapshot > > iceberg::SnapshotUtil::LatestSnapshot ( const TableMetadata metadata,
const std::string &  branch 
)
static

Fetch the snapshot at the head of the given branch in the given table.

This method calls TableMetadata::Snapshot() instead of using branch API 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
metadataThe table metadata
branchBranch name of the table metadata (empty string means main branch)
Returns
The latest snapshot for the given branch, or NotFoundError.

◆ OldestAncestor()

Result< std::optional< std::shared_ptr< Snapshot > > > iceberg::SnapshotUtil::OldestAncestor ( const Table table)
static

Traverses the history of the table's current snapshot and finds the oldest Snapshot.

Parameters
tableThe table
Returns
The oldest snapshot, or nullopt if there is no current snapshot

◆ OldestAncestorAfter()

Result< std::optional< std::shared_ptr< Snapshot > > > iceberg::SnapshotUtil::OldestAncestorAfter ( const Table table,
TimePointMs  timestamp_ms 
)
static

Traverses the history of the table's current snapshot, finds the oldest snapshot that was committed either at or after a given time.

Parameters
tableThe table
timestamp_msA timestamp in milliseconds
Returns
The first snapshot after the given timestamp, or nullopt if the current snapshot is older than the timestamp. If the first ancestor after the given time can't be determined, returns a NotFound error.

◆ OldestAncestorOf() [1/2]

Result< std::optional< std::shared_ptr< Snapshot > > > iceberg::SnapshotUtil::OldestAncestorOf ( const Table table,
int64_t  snapshot_id 
)
static

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
tableThe table
snapshot_idThe ID of the snapshot to find the oldest ancestor
Returns
The oldest snapshot, or nullopt if not found

◆ OldestAncestorOf() [2/2]

Result< std::optional< std::shared_ptr< Snapshot > > > iceberg::SnapshotUtil::OldestAncestorOf ( const TableMetadata metadata,
int64_t  snapshot_id 
)
static

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
metadataThe table metadata
snapshot_idThe ID of the snapshot to find the oldest ancestor
Returns
The oldest snapshot, or nullopt if not found

◆ OptionalLatestSnapshot()

Result< std::shared_ptr< Snapshot > > iceberg::SnapshotUtil::OptionalLatestSnapshot ( const TableMetadata metadata,
const std::string &  branch 
)
static

Fetch the snapshot at the head of the given branch in the given table.

Like LatestSnapshot above except that nullptr is returned if snapshot does not exist.

Parameters
metadataThe table metadata
branchBranch name of the table metadata (empty string means main branch)
Returns
The latest snapshot for the given branch, or nullptr if not found.

◆ OptionalSnapshotIdAsOfTime()

std::optional< int64_t > iceberg::SnapshotUtil::OptionalSnapshotIdAsOfTime ( const Table table,
TimePointMs  timestamp_ms 
)
static

Returns the ID of the most recent snapshot for the table as of the timestamp, or nullopt if not found.

Parameters
tableThe table
timestamp_msThe timestamp in millis since the Unix epoch
Returns
The snapshot ID, or nullopt if not found

◆ SchemaFor() [1/4]

Result< std::shared_ptr< Schema > > iceberg::SnapshotUtil::SchemaFor ( const Table table,
const std::string &  ref 
)
static

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
tableThe table
refRef name of the table (empty string means main branch)
Returns
Schema of the specific snapshot at the given ref

◆ SchemaFor() [2/4]

Result< std::shared_ptr< Schema > > iceberg::SnapshotUtil::SchemaFor ( const Table table,
int64_t  snapshot_id 
)
static

Returns the schema of the table for the specified snapshot.

Parameters
tableThe table
snapshot_idThe ID of the snapshot
Returns
The schema

◆ SchemaFor() [3/4]

Result< std::shared_ptr< Schema > > iceberg::SnapshotUtil::SchemaFor ( const Table table,
TimePointMs  timestamp_ms 
)
static

Returns the schema of the table for the specified timestamp.

Parameters
tableThe table
timestamp_msThe timestamp in millis since the Unix epoch
Returns
The schema

◆ SchemaFor() [4/4]

Result< std::shared_ptr< Schema > > iceberg::SnapshotUtil::SchemaFor ( const TableMetadata metadata,
const std::string &  ref 
)
static

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
metadataThe table metadata
refRef name of the table (empty string means main branch)
Returns
Schema of the specific snapshot at the given branch

◆ SnapshotAfter()

Result< std::shared_ptr< Snapshot > > iceberg::SnapshotUtil::SnapshotAfter ( const Table table,
int64_t  snapshot_id 
)
static

Traverses the history of the table's current snapshot and finds the snapshot with the given snapshot id as its parent.

Parameters
tableThe table
snapshot_idThe parent snapshot ID
Returns
The snapshot for which the given snapshot is the parent

◆ SnapshotIdAsOfTime() [1/2]

Result< int64_t > iceberg::SnapshotUtil::SnapshotIdAsOfTime ( const Table table,
TimePointMs  timestamp_ms 
)
static

Returns the ID of the most recent snapshot for the table as of the timestamp.

Parameters
tableThe table
timestamp_msThe timestamp in millis since the Unix epoch
Returns
The snapshot ID

◆ SnapshotIdAsOfTime() [2/2]

Result< int64_t > iceberg::SnapshotUtil::SnapshotIdAsOfTime ( const TableMetadata metadata,
TimePointMs  timestamp_ms 
)
static

Returns the ID of the most recent snapshot for the table as of the timestamp.

Parameters
metadataThe table metadata
timestamp_msThe timestamp in millis since the Unix epoch
Returns
The snapshot ID

◆ SnapshotIdsBetween()

Result< std::vector< int64_t > > iceberg::SnapshotUtil::SnapshotIdsBetween ( const Table table,
int64_t  from_snapshot_id,
int64_t  to_snapshot_id 
)
static

Returns list of snapshot ids in the range (from_snapshot_id,to_snapshot_id].

This method assumes that from_snapshot_id is an ancestor of to_snapshot_id.

Parameters
tableThe table
from_snapshot_idThe starting snapshot ID (exclusive)
to_snapshot_idThe ending snapshot ID (inclusive)
Returns
A vector of snapshot IDs in the range

The documentation for this class was generated from the following files: