apache/iceberg · error · UnsupportedOperationException
Truncate transform is not supported
Error message
Truncate transform is not supported
What it means
PartitionSpecVisitor's default truncate(sourceName, sourceId, width) throws UnsupportedOperationException: implementers must override it to handle truncate[W] partition fields. The default exists so partial visitors compile, but visiting a truncate field without an override fails fast.
Source
Thrown at api/src/main/java/org/apache/iceberg/transforms/PartitionSpecVisitor.java:49
default T identity(String sourceName, int sourceId) {
throw new UnsupportedOperationException("Identity transform is not supported");
}
default T bucket(int fieldId, String sourceName, int sourceId, int numBuckets) {
return bucket(sourceName, sourceId, numBuckets);
}
default T bucket(String sourceName, int sourceId, int numBuckets) {
throw new UnsupportedOperationException("Bucket transform is not supported");
}
default T truncate(int fieldId, String sourceName, int sourceId, int width) {
return truncate(sourceName, sourceId, width);
}
default T truncate(String sourceName, int sourceId, int width) {
throw new UnsupportedOperationException("Truncate transform is not supported");
}
default T year(int fieldId, String sourceName, int sourceId) {
return year(sourceName, sourceId);
}
default T year(String sourceName, int sourceId) {
throw new UnsupportedOperationException("Year transform is not supported");
}
default T month(int fieldId, String sourceName, int sourceId) {
return month(sourceName, sourceId);
}
default T month(String sourceName, int sourceId) {
throw new UnsupportedOperationException("Month transform is not supported");
}
View on GitHub (pinned to 86d9c8fc54)
Solutions
- Override truncate(int fieldId, String sourceName, int sourceId, int width) (or the legacy overload) in the visitor.
- Reject specs containing truncate transforms explicitly if unsupported, with a user-facing message.
- Cover the truncate case with a unit test using a spec built via PartitionSpec.builder().addTruncateField(...).
Example fix
// before
new PartitionSpecVisitor<String>() {
public String bucket(String name, int id, int n) { return ...; }
}
// after
new PartitionSpecVisitor<String>() {
public String bucket(String name, int id, int n) { return ...; }
@Override
public String truncate(int fieldId, String sourceName, int sourceId, int width) {
return "truncate[" + width + "](" + sourceName + ")";
}
} Defensive patterns
Strategy: try-catch
Validate before calling
boolean hasTruncate = spec.fields().stream().anyMatch(f -> f.transform().toString().startsWith("truncate")); Try / catch
try { return PartitionSpecVisitor.visit(spec, visitor); } catch (UnsupportedOperationException e) { throw new IllegalArgumentException("Spec contains unhandled truncate field: " + spec, e); } Prevention
- Override truncate(...) in every PartitionSpecVisitor implementation
- Add a visit test with a truncate[W] partition field
- Fail early with a clear message when a spec uses transforms the visitor cannot map
When it happens
Trigger: Visiting a partition spec containing a truncate[W] partition field with a visitor that does not override truncate(...).
Common situations: Translation utilities that convert Iceberg partition specs to engine-specific expressions (e.g. SQL) where the author omitted the truncate case; tables partitioned with truncate on string/int columns processed by partial visitors.
Understand the failure class
Background: "NotImplementedError: Subclasses should override this method" / "must be implemented" — abstract method errors explained — this error's family across 40 libraries.
Related errors
- Identity transform is not supported
- Bucket transform is not supported
- ${className} does not implement notNaN
- Cannot bind unsupported transform: %s
- Unsupported type for fromPartitionString: + type
AI-assisted analysis of apache/iceberg@86d9c8fc54 (2026-09-12).
Data as JSON: /api/errors/6be39dc322aa9f76.
Report an issue: GitHub.