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

A partition spec for a Table. More...

#include <partition_spec.h>

Inheritance diagram for iceberg::PartitionSpec:
iceberg::util::Formattable

Public Types

using PartitionFieldRef = std::reference_wrapper< const PartitionField >
 Get the partition fields by source ID.
 

Public Member Functions

int32_t spec_id () const
 Get the spec ID.
 
std::span< const PartitionFieldfields () const
 Get a list view of the partition fields.
 
Result< std::unique_ptr< StructType > > PartitionType (const Schema &schema) const
 Get the partition type binding to the input schema.
 
Result< std::string > PartitionPath (const PartitionValues &data) const
 Get the partition path for the given partition data.
 
bool CompatibleWith (const PartitionSpec &other) const
 Returns true if this spec is equivalent to the other, with partition field ids ignored. That is, if both specs have the same number of fields, field order, field name, source columns, and transforms.
 
std::string ToString () const override
 Get a user-readable string representation.
 
int32_t last_assigned_field_id () const
 
Status Validate (const Schema &schema, bool allow_missing_fields) const
 Validates the partition spec against a schema.
 
Result< std::vector< PartitionFieldRef > > GetFieldsBySourceId (int32_t source_id) const
 

Static Public Member Functions

static const std::shared_ptr< PartitionSpec > & Unpartitioned ()
 Get an unsorted partition spec singleton.
 
static Status ValidatePartitionName (const Schema &schema, const PartitionSpec &spec)
 
static Result< std::unique_ptr< PartitionSpec > > Make (const Schema &schema, int32_t spec_id, std::vector< PartitionField > fields, bool allow_missing_fields, std::optional< int32_t > last_assigned_field_id=std::nullopt)
 Create a PartitionSpec binding to a schema.
 
static Result< std::unique_ptr< PartitionSpec > > Make (int32_t spec_id, std::vector< PartitionField > fields, std::optional< int32_t > last_assigned_field_id=std::nullopt)
 Create a PartitionSpec without binding to a schema.
 
static bool HasSequentialFieldIds (const PartitionSpec &spec)
 

Static Public Attributes

static constexpr int32_t kInitialSpecId = 0
 
static constexpr int32_t kLegacyPartitionDataIdStart = 1000
 The start ID for partition field. It is only used to generate partition field id for v1 metadata where it is tracked.
 
static constexpr int32_t kInvalidPartitionFieldId = -1
 

Friends

bool operator== (const PartitionSpec &lhs, const PartitionSpec &rhs)
 

Detailed Description

A partition spec for a Table.

A partition spec is a list of partition fields, along with a unique integer ID. A Table may have different partition specs over its lifetime due to partition spec evolution.

Member Typedef Documentation

◆ PartitionFieldRef

using iceberg::PartitionSpec::PartitionFieldRef = std::reference_wrapper<const PartitionField>

Get the partition fields by source ID.

Parameters
source_idThe id of the source field.
Returns
The partition fields by source ID, or NotFound if the source field is not found.

Member Function Documentation

◆ Make() [1/2]

Result< std::unique_ptr< PartitionSpec > > iceberg::PartitionSpec::Make ( const Schema schema,
int32_t  spec_id,
std::vector< PartitionField fields,
bool  allow_missing_fields,
std::optional< int32_t >  last_assigned_field_id = std::nullopt 
)
static

Create a PartitionSpec binding to a schema.

Parameters
schemaThe schema to bind the partition spec to.
spec_idThe spec ID.
fieldsThe partition fields.
allowMissingFieldsWhether to skip validation for partition fields whose source columns have been dropped from the schema.
last_assigned_field_idThe last assigned field ID assigned to ensure new fields get unique IDs.
Returns
A Result containing the partition spec or an error.

◆ Make() [2/2]

Result< std::unique_ptr< PartitionSpec > > iceberg::PartitionSpec::Make ( int32_t  spec_id,
std::vector< PartitionField fields,
std::optional< int32_t >  last_assigned_field_id = std::nullopt 
)
static

Create a PartitionSpec without binding to a schema.

Parameters
spec_idThe spec ID.
fieldsThe partition fields.
last_assigned_field_idThe last assigned field ID assigned to ensure new fields get unique IDs.
Returns
A Result containing the partition spec or an error.
Note
This method does not check whether the sort fields are valid for any schema.

◆ ToString()

std::string iceberg::PartitionSpec::ToString ( ) const
overridevirtual

Get a user-readable string representation.

Implements iceberg::util::Formattable.

◆ Validate()

Status iceberg::PartitionSpec::Validate ( const Schema schema,
bool  allow_missing_fields 
) const

Validates the partition spec against a schema.

Parameters
schemaThe schema to validate against.
allow_missing_fieldsWhether to skip validation for partition fields whose source columns have been dropped from the schema.
Returns
Error status if the partition spec is invalid.

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