{"record":{"id":"d7746787877f5d6e","repo":"apache/iceberg","slug":"bucket-transform-is-not-supported","errorCode":null,"errorMessage":"Bucket transform is not supported","messagePattern":"Bucket transform is not supported","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"api/src/main/java/org/apache/iceberg/transforms/PartitionSpecVisitor.java","lineNumber":41,"sourceCode":"import org.apache.iceberg.PartitionSpec;\nimport org.apache.iceberg.Schema;\nimport org.apache.iceberg.relocated.com.google.common.collect.Lists;\n\npublic interface PartitionSpecVisitor<T> {\n  default T identity(int fieldId, String sourceName, int sourceId) {\n    return identity(sourceName, sourceId);\n  }\n\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","sourceCodeStart":23,"sourceCodeEnd":59,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/api/src/main/java/org/apache/iceberg/transforms/PartitionSpecVisitor.java#L23-L59","documentation":"PartitionSpecVisitor's default bucket(sourceName, sourceId, numBuckets) throws UnsupportedOperationException: visitors are expected to override it to handle bucket partition fields. Hitting this default means the spec contained a bucket field the visitor did not implement.","triggerScenarios":"Visiting a partition spec that includes a bucket[N] transform with a visitor implementation that does not override bucket(...).","commonSituations":"Custom spec-to-SQL/translation utilities where the author implemented identity/year/month but not bucket; processing user tables with bucketed partitions through a partial visitor.","solutions":["Override bucket(int fieldId, String sourceName, int sourceId, int numBuckets) (or the legacy overload) in the visitor.","If bucketing is unsupported downstream, detect it up front via spec.fields() and reject with a clear message before visiting.","Add a test visiting a spec with a bucket field to cover the path."],"exampleFix":"// before\nnew PartitionSpecVisitor<String>() {\n  public String identity(String name, int id) { return name; }\n}\n// after\nnew PartitionSpecVisitor<String>() {\n  public String identity(String name, int id) { return name; }\n  @Override\n  public String bucket(int fieldId, String sourceName, int sourceId, int numBuckets) {\n    return \"bucket[\" + numBuckets + \"](\" + sourceName + \")\";\n  }\n}","handlingStrategy":"try-catch","validationCode":"boolean hasBucket = spec.fields().stream().anyMatch(f -> f.transform().toString().startsWith(\"bucket\"));","typeGuard":null,"tryCatchPattern":"try { return PartitionSpecVisitor.visit(spec, visitor); } catch (UnsupportedOperationException e) { throw new IllegalArgumentException(\"Spec contains unhandled bucket field: \" + spec, e); }","preventionTips":["Override bucket(...) in every PartitionSpecVisitor implementation","Add a visit test with a bucket[N] partition field","Pre-validate spec transforms against the visitor's supported set"],"tags":["java","partitioning","visitor","bucketing","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"}