Skip to main content
The Transforms class provides factory methods for creating partition transform functions in Apache Iceberg.

Overview

Transforms are used to:
  • Partition data efficiently
  • Create hidden partitions from column values
  • Enable partition pruning during queries
Most users should create transforms using PartitionSpec.builderFor(Schema) rather than directly.

Identity Transform

identity()

Returns an identity transform that passes values through unchanged.
Example:
Usage in PartitionSpec:

Bucket Transform

bucket()

Returns a bucket transform that hashes values into a fixed number of buckets.
Parameters:
  • numBuckets - The number of buckets to distribute values into
Example:
Usage in PartitionSpec:
Common Bucket Sizes:
  • 4, 8, 16 - For small to medium tables
  • 32, 64 - For larger tables
  • 128, 256 - For very large tables

Truncate Transform

truncate()

Returns a truncate transform that truncates values to a specified width.
Parameters:
  • width - The width to truncate to
    • For strings: truncates to width characters
    • For integers/longs: truncates to width units
    • For decimals: truncates to width units
Example:
Usage in PartitionSpec:

Temporal Transforms

year()

Extracts the year from dates or timestamps.
Example:
Usage in PartitionSpec:

month()

Extracts the month from dates or timestamps (as months since epoch).
Example:
Usage in PartitionSpec:

day()

Extracts the day from dates or timestamps (as days since epoch).
Example:
Usage in PartitionSpec:

hour()

Extracts the hour from timestamps (as hours since epoch).
Example:
Usage in PartitionSpec:

Void Transform

alwaysNull()

Returns a transform that always produces null (void transform).
Example:

Parsing Transforms

fromString()

Parses a transform from a string representation.
Supported Formats:
  • "identity"
  • "year", "month", "day", "hour"
  • "bucket[N]" - e.g., "bucket[16]"
  • "truncate[N]" - e.g., "truncate[10]"
  • "void"
Example:

Examples

Basic Partition Specs

Time-Based Partitioning

Multi-Level Partitioning

String Truncation

Numeric Truncation

Hash-Based Distribution

Evolving Partition Specs

Custom Partition Values

Transform String Representation

Best Practices

Choosing Partition Transforms

  1. Time-based data: Use year(), month(), day(), or hour() based on query patterns
  2. High cardinality columns: Use bucket() to limit number of partitions
  3. String prefixes: Use truncate() for prefix-based partitioning
  4. Low cardinality: Use identity() for direct partitioning

Partition Granularity

Bucket Count Selection

See Also