{"record":{"id":"6be39dc322aa9f76","repo":"apache/iceberg","slug":"truncate-transform-is-not-supported","errorCode":null,"errorMessage":"Truncate transform is not supported","messagePattern":"Truncate transform is not supported","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"api/src/main/java/org/apache/iceberg/transforms/PartitionSpecVisitor.java","lineNumber":49,"sourceCode":"\n  default T identity(String sourceName, int sourceId) {\n    throw new UnsupportedOperationException(\"Identity transform is not supported\");\n  }\n\n  default T bucket(int fieldId, String sourceName, int sourceId, int numBuckets) {\n    return bucket(sourceName, sourceId, numBuckets);\n  }\n\n  default T bucket(String sourceName, int sourceId, int numBuckets) {\n    throw new UnsupportedOperationException(\"Bucket transform is not supported\");\n  }\n\n  default T truncate(int fieldId, String sourceName, int sourceId, int width) {\n    return truncate(sourceName, sourceId, width);\n  }\n\n  default T truncate(String sourceName, int sourceId, int width) {\n    throw new UnsupportedOperationException(\"Truncate transform is not supported\");\n  }\n\n  default T year(int fieldId, String sourceName, int sourceId) {\n    return year(sourceName, sourceId);\n  }\n\n  default T year(String sourceName, int sourceId) {\n    throw new UnsupportedOperationException(\"Year transform is not supported\");\n  }\n\n  default T month(int fieldId, String sourceName, int sourceId) {\n    return month(sourceName, sourceId);\n  }\n\n  default T month(String sourceName, int sourceId) {\n    throw new UnsupportedOperationException(\"Month transform is not supported\");\n  }\n","sourceCodeStart":31,"sourceCodeEnd":67,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/api/src/main/java/org/apache/iceberg/transforms/PartitionSpecVisitor.java#L31-L67","documentation":"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.","triggerScenarios":"Visiting a partition spec containing a truncate[W] partition field with a visitor that does not override truncate(...).","commonSituations":"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.","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(...)."],"exampleFix":"// before\nnew PartitionSpecVisitor<String>() {\n  public String bucket(String name, int id, int n) { return ...; }\n}\n// after\nnew PartitionSpecVisitor<String>() {\n  public String bucket(String name, int id, int n) { return ...; }\n  @Override\n  public String truncate(int fieldId, String sourceName, int sourceId, int width) {\n    return \"truncate[\" + width + \"](\" + sourceName + \")\";\n  }\n}","handlingStrategy":"try-catch","validationCode":"boolean hasTruncate = spec.fields().stream().anyMatch(f -> f.transform().toString().startsWith(\"truncate\"));","typeGuard":null,"tryCatchPattern":"try { return PartitionSpecVisitor.visit(spec, visitor); } catch (UnsupportedOperationException e) { throw new IllegalArgumentException(\"Spec contains unhandled truncate field: \" + spec, e); }","preventionTips":["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"],"tags":["java","partitioning","visitor","truncate","unsupported-operation"],"backgroundTag":"abstract-method-not-implemented","analyzedSha":"86d9c8fc543e7c56c9f624eb725f76c9baff9570","analyzedAt":"2026-09-12T00:46:39.097Z","contentChangedAt":"2026-09-12T00:46:39.097Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}