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

  1. Override truncate(int fieldId, String sourceName, int sourceId, int width) (or the legacy overload) in the visitor.
  2. Reject specs containing truncate transforms explicitly if unsupported, with a user-facing message.
  3. 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

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


AI-assisted analysis of apache/iceberg@86d9c8fc54 (2026-09-12). Data as JSON: /api/errors/6be39dc322aa9f76. Report an issue: GitHub.