{"record":{"id":"21719638ccbf2a24","repo":"apache/iceberg","slug":"cannot-rewrite-in-a-s-table","errorCode":null,"errorMessage":"Cannot rewrite in a %s table","messagePattern":"Cannot rewrite in a (.+?) table","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/org/apache/iceberg/BaseReadOnlyTable.java","lineNumber":66,"sourceCode":"  public ReplaceSortOrder replaceSortOrder() {\n    throw new UnsupportedOperationException(\n        \"Cannot update the sort order of a \" + descriptor + \" table\");\n  }\n\n  @Override\n  public UpdateLocation updateLocation() {\n    throw new UnsupportedOperationException(\n        \"Cannot update the location of a \" + descriptor + \" table\");\n  }\n\n  @Override\n  public AppendFiles newAppend() {\n    throw new UnsupportedOperationException(\"Cannot append to a \" + descriptor + \" table\");\n  }\n\n  @Override\n  public RewriteFiles newRewrite() {\n    throw new UnsupportedOperationException(\"Cannot rewrite in a \" + descriptor + \" table\");\n  }\n\n  @Override\n  public RewriteManifests rewriteManifests() {\n    throw new UnsupportedOperationException(\n        \"Cannot rewrite manifests in a \" + descriptor + \" table\");\n  }\n\n  @Override\n  public OverwriteFiles newOverwrite() {\n    throw new UnsupportedOperationException(\"Cannot overwrite in a \" + descriptor + \" table\");\n  }\n\n  @Override\n  public RowDelta newRowDelta() {\n    throw new UnsupportedOperationException(\n        \"Cannot remove or replace rows in a \" + descriptor + \" table\");\n  }","sourceCodeStart":48,"sourceCodeEnd":84,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/core/src/main/java/org/apache/iceberg/BaseReadOnlyTable.java#L48-L84","documentation":"Iceberg throws this UnsupportedOperationException when newRewrite() is called on a read-only table. Rewriting data files commits a new snapshot, which BaseReadOnlyTable subclasses never allow. The descriptor identifies the read-only table kind.","triggerScenarios":"Calling table.newRewrite().rewriteFiles(...).commit() on a metadata table or any BaseReadOnlyTable subclass instance.","commonSituations":"Compaction/rewrite jobs iterating over table references that include metadata tables, or code that captured a read-only handle earlier and passes it to maintenance utilities.","solutions":["Run rewrite operations on the writable data table from catalog.loadTable(identifier).","Exclude metadata tables from compaction job inputs.","Use table.currentSnapshot()/scan APIs to plan rewrites, then commit via the data table."],"exampleFix":"// before\ntable.files().newRewrite().rewriteFiles(added, deleted).commit();\n\n// after\nTable dataTable = catalog.loadTable(TableIdentifier.of(\"db\", \"tbl\"));\ndataTable.newRewrite().rewriteFiles(added, deleted).commit();","handlingStrategy":"try-catch","validationCode":"if (isMetadataTableName(table.name())) { throw new IllegalArgumentException(\"Cannot rewrite files of metadata table \" + table.name()); }","typeGuard":"boolean canRewrite = !(table instanceof BaseReadOnlyTable); // practical check: handle provenance is Catalog.loadTable","tryCatchPattern":"try {\n  table.newRewrite().rewriteFiles(added, deleted).commit();\n} catch (UnsupportedOperationException e) {\n  log.error(\"Rewrites are not supported on read-only table {}\", table.name(), e);\n}","preventionTips":["Filter metadata tables out of compaction job inputs.","Plan rewrites via scans but commit via the data-table handle.","Log table.name() in jobs to surface wrong-handle bugs early."],"tags":["unsupported-operation","compaction","read-only-table"],"backgroundTag":"unsupported-operation","analyzedSha":"86d9c8fc543e7c56c9f624eb725f76c9baff9570","analyzedAt":"2026-09-12T00:46:39.097Z","contentChangedAt":"2026-09-12T00:46:39.097Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}