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

Builder class for constructing TableMetadata objects. More...

#include <table_metadata.h>

Inheritance diagram for iceberg::TableMetadataBuilder:
iceberg::ErrorCollector

Classes

class  Impl
 

Public Member Functions

TableMetadataBuilderApplyChangesForCreate (const TableMetadata &base)
 Apply changes required to create this table metadata.
 
TableMetadataBuilderSetMetadataLocation (std::string_view metadata_location)
 Set the metadata location of the table.
 
TableMetadataBuilderSetPreviousMetadataLocation (std::string_view previous_metadata_location)
 Set the previous metadata location of the table.
 
TableMetadataBuilderAssignUUID ()
 Assign a UUID to the table.
 
TableMetadataBuilderAssignUUID (std::string_view uuid)
 Assign a specific UUID to the table.
 
TableMetadataBuilderUpgradeFormatVersion (int8_t new_format_version)
 Upgrade the format version of the table.
 
TableMetadataBuilderSetCurrentSchema (const std::shared_ptr< Schema > &schema, int32_t new_last_column_id)
 Set the current schema for the table.
 
TableMetadataBuilderSetCurrentSchema (int32_t schema_id)
 Set the current schema by schema ID.
 
TableMetadataBuilderAddSchema (const std::shared_ptr< Schema > &schema)
 Add a schema to the table.
 
TableMetadataBuilderSetDefaultPartitionSpec (std::shared_ptr< PartitionSpec > spec)
 Set the default partition spec for the table.
 
TableMetadataBuilderSetDefaultPartitionSpec (int32_t spec_id)
 Set the default partition spec by spec ID.
 
TableMetadataBuilderAddPartitionSpec (std::shared_ptr< PartitionSpec > spec)
 Add a partition spec to the table.
 
TableMetadataBuilderRemovePartitionSpecs (const std::vector< int32_t > &spec_ids)
 Remove partition specs from the table.
 
TableMetadataBuilderRemoveSchemas (const std::unordered_set< int32_t > &schema_ids)
 Remove schemas from the table.
 
TableMetadataBuilderSetDefaultSortOrder (std::shared_ptr< SortOrder > order)
 Set the default sort order for the table.
 
TableMetadataBuilderSetDefaultSortOrder (int32_t order_id)
 Set the default sort order by order ID.
 
TableMetadataBuilderAddSortOrder (std::shared_ptr< SortOrder > order)
 Add a sort order to the table.
 
TableMetadataBuilderAddSnapshot (std::shared_ptr< Snapshot > snapshot)
 Add a snapshot to the table.
 
TableMetadataBuilderSetBranchSnapshot (int64_t snapshot_id, const std::string &branch)
 Set a branch to point to a specific snapshot.
 
TableMetadataBuilderSetBranchSnapshot (std::shared_ptr< Snapshot > snapshot, const std::string &branch)
 Set a branch to point to a specific snapshot.
 
TableMetadataBuilderSetRef (const std::string &name, std::shared_ptr< SnapshotRef > ref)
 Set a snapshot reference.
 
TableMetadataBuilderRemoveRef (const std::string &name)
 Remove a snapshot reference.
 
TableMetadataBuilderRemoveSnapshots (const std::vector< std::shared_ptr< Snapshot > > &snapshots_to_remove)
 Remove snapshots from the table.
 
TableMetadataBuilderRemoveSnapshots (const std::vector< int64_t > &snapshot_ids)
 Remove snapshots from the table.
 
TableMetadataBuilderSuppressHistoricalSnapshots ()
 Suppresses snapshots that are historical, removing the metadata for lazy snapshot loading.
 
TableMetadataBuilderSetStatistics (std::shared_ptr< StatisticsFile > statistics_file)
 Set table statistics.
 
TableMetadataBuilderRemoveStatistics (int64_t snapshot_id)
 Remove table statistics by snapshot ID.
 
TableMetadataBuilderSetPartitionStatistics (const std::shared_ptr< PartitionStatisticsFile > &partition_statistics_file)
 Set partition statistics.
 
TableMetadataBuilderRemovePartitionStatistics (int64_t snapshot_id)
 Remove partition statistics by snapshot ID.
 
TableMetadataBuilderSetProperties (const std::unordered_map< std::string, std::string > &updated)
 Set table properties.
 
TableMetadataBuilderRemoveProperties (const std::unordered_set< std::string > &removed)
 Remove table properties.
 
TableMetadataBuilderSetLocation (std::string_view location)
 Set the table location.
 
TableMetadataBuilderAddEncryptionKey (std::shared_ptr< EncryptedKey > key)
 Add an encryption key to the table.
 
TableMetadataBuilderRemoveEncryptionKey (std::string_view key_id)
 Remove an encryption key from the table by key ID.
 
Result< std::unique_ptr< TableMetadata > > Build ()
 Build the TableMetadata object.
 
const std::vector< std::unique_ptr< TableUpdate > > & changes () const
 Returns the changes made to the table metadata.
 
const TableMetadatabase () const
 Returns the base metadata without any changes.
 
const TableMetadatacurrent () const
 Returns the current metadata with staged changes applied.
 
 ~TableMetadataBuilder () override
 Destructor.
 
 TableMetadataBuilder (const TableMetadataBuilder &)=delete
 
TableMetadataBuilderoperator= (const TableMetadataBuilder &)=delete
 
 TableMetadataBuilder (TableMetadataBuilder &&) noexcept
 
TableMetadataBuilderoperator= (TableMetadataBuilder &&) noexcept
 
- Public Member Functions inherited from iceberg::ErrorCollector
 ErrorCollector (ErrorCollector &&)=default
 
ErrorCollectoroperator= (ErrorCollector &&)=default
 
 ErrorCollector (const ErrorCollector &)=default
 
ErrorCollectoroperator= (const ErrorCollector &)=default
 
template<typename... Args>
auto & AddError (this auto &self, ErrorKind kind, const std::format_string< Args... > fmt, Args &&... args)
 Add a specific error and return reference to derived class.
 
auto & AddError (this auto &self, Error err)
 Add an existing error object and return reference to derived class.
 
auto & AddError (this auto &self, std::unexpected< Error > err)
 Add an unexpected result's error and return reference to derived class.
 
bool has_errors () const
 Check if any errors have been collected.
 
size_t error_count () const
 Get the number of errors collected.
 
Status CheckErrors () const
 Check for accumulated errors and return them if any exist.
 
void ClearErrors ()
 Clear all accumulated errors.
 
const std::vector< Error > & errors () const
 Get read-only access to all collected errors.
 

Static Public Member Functions

static std::unique_ptr< TableMetadataBuilderBuildFromEmpty (int8_t format_version=TableMetadata::kDefaultTableFormatVersion)
 Create a builder for a new table.
 
static std::unique_ptr< TableMetadataBuilderBuildFrom (const TableMetadata *base)
 Create a builder from existing table metadata.
 

Additional Inherited Members

- Protected Attributes inherited from iceberg::ErrorCollector
std::vector< Errorerrors_
 

Detailed Description

Builder class for constructing TableMetadata objects.

This builder provides a fluent interface for creating and modifying table metadata. It supports both creating new tables and building from existing metadata.

Each modification method generates a corresponding TableUpdate that is tracked in a changes list. This allows the builder to maintain a complete history of all modifications made to the table metadata, which is important for tracking table evolution and for serialization purposes.

If a modification violates Iceberg table constraints (e.g., setting a current schema ID that does not exist), an error will be recorded and returned when Build() is called.

Member Function Documentation

◆ AddEncryptionKey()

TableMetadataBuilder & iceberg::TableMetadataBuilder::AddEncryptionKey ( std::shared_ptr< EncryptedKey >  key)

Add an encryption key to the table.

Parameters
keyThe encryption key to add
Returns
Reference to this builder for method chaining

◆ AddPartitionSpec()

TableMetadataBuilder & iceberg::TableMetadataBuilder::AddPartitionSpec ( std::shared_ptr< PartitionSpec spec)

Add a partition spec to the table.

Parameters
specThe partition spec to add
Returns
Reference to this builder for method chaining

◆ AddSchema()

TableMetadataBuilder & iceberg::TableMetadataBuilder::AddSchema ( const std::shared_ptr< Schema > &  schema)

Add a schema to the table.

Parameters
schemaThe schema to add
Returns
Reference to this builder for method chaining

◆ AddSnapshot()

TableMetadataBuilder & iceberg::TableMetadataBuilder::AddSnapshot ( std::shared_ptr< Snapshot snapshot)

Add a snapshot to the table.

Parameters
snapshotThe snapshot to add
Returns
Reference to this builder for method chaining

◆ AddSortOrder()

TableMetadataBuilder & iceberg::TableMetadataBuilder::AddSortOrder ( std::shared_ptr< SortOrder order)

Add a sort order to the table.

Parameters
orderThe sort order to add
Returns
Reference to this builder for method chaining

◆ ApplyChangesForCreate()

TableMetadataBuilder & iceberg::TableMetadataBuilder::ApplyChangesForCreate ( const TableMetadata base)

Apply changes required to create this table metadata.

Parameters
baseThe table metadata to build from
Returns
Reference to this builder for method chaining

◆ AssignUUID() [1/2]

TableMetadataBuilder & iceberg::TableMetadataBuilder::AssignUUID ( )

Assign a UUID to the table.

If no UUID is provided, a random UUID will be generated.

Returns
Reference to this builder for method chaining

◆ AssignUUID() [2/2]

TableMetadataBuilder & iceberg::TableMetadataBuilder::AssignUUID ( std::string_view  uuid)

Assign a specific UUID to the table.

Parameters
uuidThe UUID string to assign
Returns
Reference to this builder for method chaining

◆ Build()

Result< std::unique_ptr< TableMetadata > > iceberg::TableMetadataBuilder::Build ( )

Build the TableMetadata object.

Returns
A Result containing the constructed TableMetadata or an error

◆ BuildFrom()

std::unique_ptr< TableMetadataBuilder > iceberg::TableMetadataBuilder::BuildFrom ( const TableMetadata base)
static

Create a builder from existing table metadata.

Parameters
baseThe base table metadata to build from
Returns
A new TableMetadataBuilder instance initialized with base metadata

◆ BuildFromEmpty()

std::unique_ptr< TableMetadataBuilder > iceberg::TableMetadataBuilder::BuildFromEmpty ( int8_t  format_version = TableMetadata::kDefaultTableFormatVersion)
static

Create a builder for a new table.

Parameters
format_versionThe format version for the table
Returns
A new TableMetadataBuilder instance

◆ RemoveEncryptionKey()

TableMetadataBuilder & iceberg::TableMetadataBuilder::RemoveEncryptionKey ( std::string_view  key_id)

Remove an encryption key from the table by key ID.

Parameters
key_idThe ID of the encryption key to remove
Returns
Reference to this builder for method chaining

◆ RemovePartitionSpecs()

TableMetadataBuilder & iceberg::TableMetadataBuilder::RemovePartitionSpecs ( const std::vector< int32_t > &  spec_ids)

Remove partition specs from the table.

Parameters
spec_idsThe IDs of partition specs to remove
Returns
Reference to this builder for method chaining

◆ RemovePartitionStatistics()

TableMetadataBuilder & iceberg::TableMetadataBuilder::RemovePartitionStatistics ( int64_t  snapshot_id)

Remove partition statistics by snapshot ID.

Parameters
snapshot_idThe snapshot ID whose partition statistics to remove
Returns
Reference to this builder for method chaining

◆ RemoveProperties()

TableMetadataBuilder & iceberg::TableMetadataBuilder::RemoveProperties ( const std::unordered_set< std::string > &  removed)

Remove table properties.

Parameters
removedSet of property keys to remove
Returns
Reference to this builder for method chaining

◆ RemoveRef()

TableMetadataBuilder & iceberg::TableMetadataBuilder::RemoveRef ( const std::string &  name)

Remove a snapshot reference.

Parameters
nameThe name of the reference to remove
Returns
Reference to this builder for method chaining

◆ RemoveSchemas()

TableMetadataBuilder & iceberg::TableMetadataBuilder::RemoveSchemas ( const std::unordered_set< int32_t > &  schema_ids)

Remove schemas from the table.

Parameters
schema_idsThe IDs of schemas to remove
Returns
Reference to this builder for method chaining

◆ RemoveSnapshots() [1/2]

TableMetadataBuilder & iceberg::TableMetadataBuilder::RemoveSnapshots ( const std::vector< int64_t > &  snapshot_ids)

Remove snapshots from the table.

Parameters
snapshot_idsThe IDs of snapshots to remove
Returns
Reference to this builder for method chaining

◆ RemoveSnapshots() [2/2]

TableMetadataBuilder & iceberg::TableMetadataBuilder::RemoveSnapshots ( const std::vector< std::shared_ptr< Snapshot > > &  snapshots_to_remove)

Remove snapshots from the table.

Parameters
snapshots_to_removeThe snapshots to remove
Returns
Reference to this builder for method chaining

◆ RemoveStatistics()

TableMetadataBuilder & iceberg::TableMetadataBuilder::RemoveStatistics ( int64_t  snapshot_id)

Remove table statistics by snapshot ID.

Parameters
snapshot_idThe snapshot ID whose statistics to remove
Returns
Reference to this builder for method chaining

◆ SetBranchSnapshot() [1/2]

TableMetadataBuilder & iceberg::TableMetadataBuilder::SetBranchSnapshot ( int64_t  snapshot_id,
const std::string &  branch 
)

Set a branch to point to a specific snapshot.

Parameters
snapshot_idThe snapshot ID the branch should reference
branchThe name of the branch
Returns
Reference to this builder for method chaining

◆ SetBranchSnapshot() [2/2]

TableMetadataBuilder & iceberg::TableMetadataBuilder::SetBranchSnapshot ( std::shared_ptr< Snapshot snapshot,
const std::string &  branch 
)

Set a branch to point to a specific snapshot.

Parameters
snapshotThe snapshot the branch should reference
branchThe name of the branch
Returns
Reference to this builder for method chaining

◆ SetCurrentSchema() [1/2]

TableMetadataBuilder & iceberg::TableMetadataBuilder::SetCurrentSchema ( const std::shared_ptr< Schema > &  schema,
int32_t  new_last_column_id 
)

Set the current schema for the table.

Parameters
schemaThe schema to set as current
new_last_column_idThe highest column ID in the schema
Returns
Reference to this builder for method chaining

◆ SetCurrentSchema() [2/2]

TableMetadataBuilder & iceberg::TableMetadataBuilder::SetCurrentSchema ( int32_t  schema_id)

Set the current schema by schema ID.

Parameters
schema_idThe ID of the schema to set as current
Returns
Reference to this builder for method chaining

◆ SetDefaultPartitionSpec() [1/2]

TableMetadataBuilder & iceberg::TableMetadataBuilder::SetDefaultPartitionSpec ( int32_t  spec_id)

Set the default partition spec by spec ID.

Parameters
spec_idThe ID of the partition spec to set as default
Returns
Reference to this builder for method chaining

◆ SetDefaultPartitionSpec() [2/2]

TableMetadataBuilder & iceberg::TableMetadataBuilder::SetDefaultPartitionSpec ( std::shared_ptr< PartitionSpec spec)

Set the default partition spec for the table.

Parameters
specThe partition spec to set as default
Returns
Reference to this builder for method chaining

◆ SetDefaultSortOrder() [1/2]

TableMetadataBuilder & iceberg::TableMetadataBuilder::SetDefaultSortOrder ( int32_t  order_id)

Set the default sort order by order ID.

Parameters
order_idThe ID of the sort order to set as default
Returns
Reference to this builder for method chaining

◆ SetDefaultSortOrder() [2/2]

TableMetadataBuilder & iceberg::TableMetadataBuilder::SetDefaultSortOrder ( std::shared_ptr< SortOrder order)

Set the default sort order for the table.

Parameters
orderThe sort order to set as default
Returns
Reference to this builder for method chaining

◆ SetLocation()

TableMetadataBuilder & iceberg::TableMetadataBuilder::SetLocation ( std::string_view  location)

Set the table location.

Parameters
locationThe table base location
Returns
Reference to this builder for method chaining

◆ SetMetadataLocation()

TableMetadataBuilder & iceberg::TableMetadataBuilder::SetMetadataLocation ( std::string_view  metadata_location)

Set the metadata location of the table.

Parameters
metadata_locationThe new metadata location
Returns
Reference to this builder for method chaining

◆ SetPartitionStatistics()

TableMetadataBuilder & iceberg::TableMetadataBuilder::SetPartitionStatistics ( const std::shared_ptr< PartitionStatisticsFile > &  partition_statistics_file)

Set partition statistics.

Parameters
partition_statistics_fileThe partition statistics file to set
Returns
Reference to this builder for method chaining

◆ SetPreviousMetadataLocation()

TableMetadataBuilder & iceberg::TableMetadataBuilder::SetPreviousMetadataLocation ( std::string_view  previous_metadata_location)

Set the previous metadata location of the table.

Parameters
previous_metadata_locationThe previous metadata location
Returns
Reference to this builder for method chaining

◆ SetProperties()

TableMetadataBuilder & iceberg::TableMetadataBuilder::SetProperties ( const std::unordered_map< std::string, std::string > &  updated)

Set table properties.

Parameters
updatedMap of properties to set or update
Returns
Reference to this builder for method chaining

◆ SetRef()

TableMetadataBuilder & iceberg::TableMetadataBuilder::SetRef ( const std::string &  name,
std::shared_ptr< SnapshotRef ref 
)

Set a snapshot reference.

Parameters
nameThe name of the reference
refThe snapshot reference to set
Returns
Reference to this builder for method chaining

◆ SetStatistics()

TableMetadataBuilder & iceberg::TableMetadataBuilder::SetStatistics ( std::shared_ptr< StatisticsFile statistics_file)

Set table statistics.

Parameters
statistics_fileThe statistics file to set
Returns
Reference to this builder for method chaining

◆ SuppressHistoricalSnapshots()

TableMetadataBuilder & iceberg::TableMetadataBuilder::SuppressHistoricalSnapshots ( )

Suppresses snapshots that are historical, removing the metadata for lazy snapshot loading.

Note that the snapshots are not considered removed from metadata and no RemoveSnapshot changes are created. A snapshot is historical if no ref directly references its ID.

Returns
Reference to this builder for method chaining

◆ UpgradeFormatVersion()

TableMetadataBuilder & iceberg::TableMetadataBuilder::UpgradeFormatVersion ( int8_t  new_format_version)

Upgrade the format version of the table.

Parameters
new_format_versionThe new format version (must be >= current version)
Returns
Reference to this builder for method chaining

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