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

Represents a transform used in partitioning or sorting in Iceberg. More...

#include <transform.h>

Inheritance diagram for iceberg::Transform:
iceberg::util::Formattable

Public Member Functions

TransformType transform_type () const
 Returns the transform type.
 
Result< std::shared_ptr< TransformFunction > > Bind (const std::shared_ptr< Type > &source_type) const
 Binds this transform to a source type, returning a typed TransformFunction.
 
bool CanTransform (const Type &source_type) const
 Checks whether this function can be applied to the given Type.
 
bool PreservesOrder () const
 Whether the transform preserves the order of values (is monotonic).
 
bool SatisfiesOrderOf (const Transform &other) const
 Whether ordering by this transform's result satisfies the ordering of another transform's result.
 
Result< std::unique_ptr< UnboundPredicate > > Project (std::string_view name, const std::shared_ptr< BoundPredicate > &predicate)
 Transforms a BoundPredicate to an inclusive predicate on the partition values produced by the transform.
 
Result< std::unique_ptr< UnboundPredicate > > ProjectStrict (std::string_view name, const std::shared_ptr< BoundPredicate > &predicate)
 Transforms a BoundPredicate to a strict predicate on the partition values produced by the transform.
 
Result< std::string > ToHumanString (const Literal &value)
 Returns a human-readable string representation of a transformed value.
 
std::string ToString () const override
 Returns a string representation of this transform (e.g., "bucket[16]").
 
std::string DedupName () const
 Return the unique transform name to check if similar transforms for the same source field are added multiple times in partition spec builder.
 
Result< std::string > GeneratePartitionName (std::string_view source_name) const
 Generates a partition name for the transform.
 

Static Public Member Functions

static std::shared_ptr< TransformIdentity ()
 Returns a shared singleton instance of the Identity transform.
 
static std::shared_ptr< TransformBucket (int32_t num_buckets)
 Creates a shared instance of the Bucket transform.
 
static std::shared_ptr< TransformTruncate (int32_t width)
 Creates a shared instance of the Truncate transform.
 
static std::shared_ptr< TransformYear ()
 Creates a shared singleton instance of the Year transform.
 
static std::shared_ptr< TransformMonth ()
 Creates a shared singleton instance of the Month transform.
 
static std::shared_ptr< TransformDay ()
 Creates a shared singleton instance of the Day transform.
 
static std::shared_ptr< TransformHour ()
 Creates a shared singleton instance of the Hour transform.
 
static std::shared_ptr< TransformVoid ()
 Creates a shared singleton instance of the Void transform.
 

Friends

bool operator== (const Transform &lhs, const Transform &rhs)
 Equality comparison.
 

Detailed Description

Represents a transform used in partitioning or sorting in Iceberg.

This class supports binding to a source type and instantiating the corresponding TransformFunction, as well as serialization-friendly introspection.

Member Function Documentation

◆ Bind()

Result< std::shared_ptr< TransformFunction > > iceberg::Transform::Bind ( const std::shared_ptr< Type > &  source_type) const

Binds this transform to a source type, returning a typed TransformFunction.

This creates a concrete transform implementation based on the transform type and parameter.

Parameters
source_typeThe source column type to bind to.
Returns
A TransformFunction instance wrapped in expected, or an error on failure.

◆ Bucket()

std::shared_ptr< Transform > iceberg::Transform::Bucket ( int32_t  num_buckets)
static

Creates a shared instance of the Bucket transform.

Buckets values using a hash modulo operation. Commonly used for distributing data.

Parameters
num_bucketsThe number of buckets.
Returns
A shared pointer to the Bucket transform.

◆ CanTransform()

bool iceberg::Transform::CanTransform ( const Type source_type) const

Checks whether this function can be applied to the given Type.

Parameters
source_typeThe source type to check.
Returns
true if this transform can be applied to the type, false otherwise

◆ Day()

std::shared_ptr< Transform > iceberg::Transform::Day ( )
static

Creates a shared singleton instance of the Day transform.

Extracts the number of days from a date or timestamp since the epoch.

Returns
A shared pointer to the Day transform.

◆ GeneratePartitionName()

Result< std::string > iceberg::Transform::GeneratePartitionName ( std::string_view  source_name) const

Generates a partition name for the transform.

Parameters
source_nameThe name of the source column.
Returns
A string representation of the partition name.

◆ Hour()

std::shared_ptr< Transform > iceberg::Transform::Hour ( )
static

Creates a shared singleton instance of the Hour transform.

Extracts the number of hours from a timestamp since the epoch.

Returns
A shared pointer to the Hour transform.

◆ Identity()

std::shared_ptr< Transform > iceberg::Transform::Identity ( )
static

Returns a shared singleton instance of the Identity transform.

This transform leaves values unchanged and is commonly used for direct partitioning.

Returns
A shared pointer to the Identity transform.

◆ Month()

std::shared_ptr< Transform > iceberg::Transform::Month ( )
static

Creates a shared singleton instance of the Month transform.

Extracts the number of months from a date or timestamp since the epoch.

Returns
A shared pointer to the Month transform.

◆ Project()

Result< std::unique_ptr< UnboundPredicate > > iceberg::Transform::Project ( std::string_view  name,
const std::shared_ptr< BoundPredicate > &  predicate 
)

Transforms a BoundPredicate to an inclusive predicate on the partition values produced by the transform.

This inclusive transform guarantees that if predicate->Test(value) is true, then Projected(transform(value)) is true.

Parameters
nameThe name of the partition column.
predicateThe predicate to project.
Returns
A Result containing either a unique pointer to the projected predicate, nullptr if the projection cannot be performed, or an Error if the projection fails.

◆ ProjectStrict()

Result< std::unique_ptr< UnboundPredicate > > iceberg::Transform::ProjectStrict ( std::string_view  name,
const std::shared_ptr< BoundPredicate > &  predicate 
)

Transforms a BoundPredicate to a strict predicate on the partition values produced by the transform.

This strict transform guarantees that if Projected(transform(value)) is true, then predicate->Test(value) is also true.

Parameters
nameThe name of the partition column.
predicateThe predicate to project.
Returns
A Result containing either a unique pointer to the projected predicate, nullptr if the projection cannot be performed, or an Error if the projection fails.

◆ SatisfiesOrderOf()

bool iceberg::Transform::SatisfiesOrderOf ( const Transform other) const

Whether ordering by this transform's result satisfies the ordering of another transform's result.

For example, sorting by day(ts) will produce an ordering that is also by month(ts) or year(ts). However, sorting by day(ts) will not satisfy the order of hour(ts) or identity(ts).

Parameters
otherThe other transform to compare with.
Returns
true if ordering by this transform is equivalent to ordering by the other transform.

◆ ToHumanString()

Result< std::string > iceberg::Transform::ToHumanString ( const Literal value)

Returns a human-readable string representation of a transformed value.

Parameters
valueThe literal value to be transformed.
Returns
A human-readable string representation of the value

◆ ToString()

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

Returns a string representation of this transform (e.g., "bucket[16]").

Implements iceberg::util::Formattable.

◆ Truncate()

std::shared_ptr< Transform > iceberg::Transform::Truncate ( int32_t  width)
static

Creates a shared instance of the Truncate transform.

Truncates values to a fixed width (e.g., for strings or binary data).

Parameters
widthThe width to truncate to.
Returns
A shared pointer to the Truncate transform.

◆ Void()

std::shared_ptr< Transform > iceberg::Transform::Void ( )
static

Creates a shared singleton instance of the Void transform.

Ignores values and always returns null. Useful for testing or special cases.

Returns
A shared pointer to the Void transform.

◆ Year()

std::shared_ptr< Transform > iceberg::Transform::Year ( )
static

Creates a shared singleton instance of the Year transform.

Extracts the number of years from a date or timestamp since the epoch.

Returns
A shared pointer to the Year transform.

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