{"record":{"id":"93642ee17a698de8","repo":"apache/iceberg","slug":"unsupported-delete-granularity-granularity","errorCode":null,"errorMessage":"Unsupported delete granularity: ${granularity}","messagePattern":"Unsupported delete granularity: (.+?)","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/org/apache/iceberg/deletes/SortingPositionOnlyDeleteWriter.java","lineNumber":111,"sourceCode":"  }\n\n  @Override\n  public DeleteWriteResult result() {\n    return result;\n  }\n\n  @Override\n  public void close() throws IOException {\n    if (result == null) {\n      switch (granularity) {\n        case FILE:\n          this.result = writeFileDeletes();\n          return;\n        case PARTITION:\n          this.result = writePartitionDeletes();\n          return;\n        default:\n          throw new UnsupportedOperationException(\"Unsupported delete granularity: \" + granularity);\n      }\n    }\n  }\n\n  // write deletes for all data files together\n  private DeleteWriteResult writePartitionDeletes() throws IOException {\n    return writeDeletes(positionsByPath.keySet());\n  }\n\n  // write deletes for different data files into distinct delete files\n  private DeleteWriteResult writeFileDeletes() throws IOException {\n    List<DeleteFile> deleteFiles = Lists.newArrayList();\n    CharSequenceSet referencedDataFiles = CharSequenceSet.empty();\n    List<DeleteFile> rewrittenDeleteFiles = Lists.newArrayList();\n\n    for (CharSequence path : positionsByPath.keySet()) {\n      DeleteWriteResult writeResult = writeDeletes(ImmutableList.of(path));\n      deleteFiles.addAll(writeResult.deleteFiles());","sourceCodeStart":93,"sourceCodeEnd":129,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/core/src/main/java/org/apache/iceberg/deletes/SortingPositionOnlyDeleteWriter.java#L93-L129","documentation":"SortingPositionOnlyDeleteWriter.close() dispatches on the configured DeleteGranularity (FILE, PARTITION, etc.); any other value falls through to default and throws UnsupportedOperationException. This means the writer was configured with a granularity it cannot produce.","triggerScenarios":"Constructing a SortingPositionOnlyDeleteWriter with a DeleteGranularity other than FILE or PARTITION (e.g. a newly added enum value the writer does not handle) and then calling close().","commonSituations":"Enum evolution: a new DeleteGranularity value added to the API but not yet supported by the sorting writer; custom writer configs passing an invalid granularity value.","solutions":["Configure the writer with DeleteGranularity.FILE or DeleteGranularity.PARTITION","If a new granularity value was introduced, upgrade Iceberg so the writer supports it, or handle it in writePartitionDeletes-style methods","Add a case for the new granularity in close() if extending the writer yourself"],"exampleFix":"// before\nDeleteGranularity granularity = DeleteGranularity.valueOf(cfg); // e.g. NEW_VALUE\n// after\nif (granularity != DeleteGranularity.FILE && granularity != DeleteGranularity.PARTITION) {\n  throw new IllegalArgumentException(\"Sorting writer requires FILE or PARTITION, got: \" + granularity);\n}","handlingStrategy":"validation","validationCode":"Preconditions.checkArgument(granularity == DeleteGranularity.FILE || granularity == DeleteGranularity.PARTITION, \"Unsupported granularity: %s\", granularity);","typeGuard":"boolean writerSupports(DeleteGranularity g) { return g == DeleteGranularity.FILE || g == DeleteGranularity.PARTITION; }","tryCatchPattern":"try { writer.close(); } catch (UnsupportedOperationException e) { throw new IllegalArgumentException(\"Check writer DeleteGranularity config\", e); }","preventionTips":["Validate granularity config at writer construction time, not at close()","Watch for new DeleteGranularity enum values when upgrading Iceberg and check writer support","Exhaustive switch over DeleteGranularity with a compile-time-checked expression avoids the default fallthrough"],"tags":["java","deletes","enum"],"backgroundTag":"unsupported-enum-value","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"}