{"record":{"id":"81827c81aaab07b7","repo":"apache/iceberg","slug":"identity-transform-is-not-supported","errorCode":null,"errorMessage":"Identity transform is not supported","messagePattern":"Identity transform is not supported","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"api/src/main/java/org/apache/iceberg/transforms/PartitionSpecVisitor.java","lineNumber":33,"sourceCode":" * KIND, either express or implied.  See the License for the\n * specific language governing permissions and limitations\n * under the License.\n */\npackage org.apache.iceberg.transforms;\n\nimport java.util.List;\nimport org.apache.iceberg.PartitionField;\nimport 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","sourceCodeStart":15,"sourceCodeEnd":51,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/api/src/main/java/org/apache/iceberg/transforms/PartitionSpecVisitor.java#L15-L51","documentation":"PartitionSpecVisitor provides default methods that throw UnsupportedOperationException so implementers only override the visit methods they care about. The legacy identity(sourceName, sourceId) default throws; visitors that don't override it but receive identity() dispatch will fail. Implement a visit method or use the fieldId-aware overload's default chain.","triggerScenarios":"A PartitionSpecVisitor implementation that does not override identity(int fieldId, String sourceName, int sourceId) nor identity(String sourceName, int sourceId), visiting a partition spec containing an identity partition field.","commonSituations":"Writing custom spec visitors (e.g. for SQL partition-expression translation, Hive/Spark converters) and forgetting the identity case; specs with identity fields processed by visitors built only for transforms.","solutions":["Override identity(int fieldId, String sourceName, int sourceId) (or the 2-arg overload) in your visitor to return a value.","If identity fields are unsupported in your target, throw a domain-specific error explicitly rather than relying on the default.","Pre-scan the spec (PartitionSpecVisitor.visit(spec)) in tests to ensure every transform type your visitor lacks cannot occur."],"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 identity(int fieldId, String sourceName, int sourceId) {\n    return sourceName; // handle identity fields\n  }\n}","handlingStrategy":"try-catch","validationCode":"boolean hasIdentity = spec.fields().stream().anyMatch(f -> f.transform().isIdentity());","typeGuard":null,"tryCatchPattern":"try { return PartitionSpecVisitor.visit(spec, visitor); } catch (UnsupportedOperationException e) { throw new IllegalArgumentException(\"Spec contains unhandled identity field: \" + spec, e); }","preventionTips":["Override every transform case your specs can contain, including identity","Unit-test visitors against specs with each transform type","Reject unsupported transforms explicitly before visiting"],"tags":["java","partitioning","visitor","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"}