PartitionSpec Class
ThePartitionSpec class defines how to produce partition data for an Apache Iceberg table. Partition data is produced by transforming columns in a table.
Package: org.apache.iceberg
Overview
ThePartitionSpec class provides:
- Column transformation for partitioning (identity, bucket, truncate, temporal)
- Partition evolution with spec IDs
- Multiple partition fields per spec
- Compatibility checking with schemas
Partition field IDs start at 1000 to avoid conflicts with schema field IDs.
Basic Methods
schema()
specId()
fields()
isPartitioned()
isUnpartitioned()
Partition Field Access
getFieldsBySourceId(int fieldId)
int
required
A field ID from the source schema
identitySourceIds()
Partition Types
partitionType()
rawPartitionType()
partitionType() when field IDs have been reassigned.
Returns: StructType with original field IDs
javaClasses()
Partition Path Operations
partitionToPath(StructLike data)
StructLike
required
The partition data
Compatibility
compatibleWith(PartitionSpec other)
- Number of fields
- Field order
- Field names
- Source columns
- Transforms
PartitionSpec
required
Another PartitionSpec to compare
Conversion
toUnbound()
Static Factory Methods
unpartitioned()
builderFor(Schema schema)
Schema
required
The table schema
Builder Class
TheBuilder class creates valid partition specs.
Builder Methods
identity(String sourceName)
String
required
The source column name
identity(String sourceName, String targetName)
String
required
The source column name
String
required
The partition field name
year(String sourceName)
String
required
The source date/timestamp column name
year(String sourceName, String targetName)
month(String sourceName)
String
required
The source date/timestamp column name
month(String sourceName, String targetName)
day(String sourceName)
String
required
The source date/timestamp column name
day(String sourceName, String targetName)
hour(String sourceName)
String
required
The source timestamp column name
hour(String sourceName, String targetName)
bucket(String sourceName, int numBuckets)
String
required
The source column name
int
required
The number of buckets
bucket(String sourceName, int numBuckets, String targetName)
truncate(String sourceName, int width)
String
required
The source column name
int
required
The truncation width
truncate(String sourceName, int width, String targetName)
alwaysNull(String sourceName)
String
required
The source column name
Void transforms are used for deprecated partition fields in version 1 tables.
alwaysNull(String sourceName, String targetName)
withSpecId(int newSpecId)
int
required
The spec ID
caseSensitive(boolean sensitive)
boolean
required
True for case-sensitive matching
build()
ValidationException if the spec is invalid
build(boolean allowMissingFields)
boolean
required
If true, allows partition fields whose source columns are missing
Usage Examples
Creating an Unpartitioned Spec
Creating a Simple Partitioned Spec
Creating a Multi-Level Time Partition
Creating a Hash Bucket Partition
Creating a Truncate Partition
Working with Partition Data
Checking Spec Compatibility
Inspecting Partition Fields
Partition Evolution Example
Source Code Reference
Source:org/apache/iceberg/PartitionSpec.java:53