apache/iceberg · error · UnsupportedOperationException
Cannot rewrite in a table
Error message
Cannot rewrite in a %s table
What it means
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.
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.
Example fix
// before
table.files().newRewrite().rewriteFiles(added, deleted).commit();
// after
Table dataTable = catalog.loadTable(TableIdentifier.of("db", "tbl"));
dataTable.newRewrite().rewriteFiles(added, deleted).commit(); Defensive patterns
Strategy: try-catch
Validate before calling
if (isMetadataTableName(table.name())) { throw new IllegalArgumentException("Cannot rewrite files of metadata table " + table.name()); } Type guard
boolean canRewrite = !(table instanceof BaseReadOnlyTable); // practical check: handle provenance is Catalog.loadTable
Try / catch
try {
table.newRewrite().rewriteFiles(added, deleted).commit();
} catch (UnsupportedOperationException e) {
log.error("Rewrites are not supported on read-only table {}", table.name(), e);
} Prevention
- 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.
When it happens
Trigger: Calling table.newRewrite().rewriteFiles(...).commit() on a metadata table or any BaseReadOnlyTable subclass instance.
Common situations: 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.
Understand the failure class
Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.
Related errors
- Cannot append to a table
- Cannot create transactions for a
- Cannot delete from a
- Cannot expire snapshots from a
- Cannot manage snapshots in a
AI-assisted analysis of apache/iceberg@86d9c8fc54 (2026-09-12).
Data as JSON: /api/errors/21719638ccbf2a24.
Report an issue: GitHub.
Appendix: source
Thrown at core/src/main/java/org/apache/iceberg/BaseReadOnlyTable.java:66
public ReplaceSortOrder replaceSortOrder() {
throw new UnsupportedOperationException(
"Cannot update the sort order of a " + descriptor + " table");
}
@Override
public UpdateLocation updateLocation() {
throw new UnsupportedOperationException(
"Cannot update the location of a " + descriptor + " table");
}
@Override
public AppendFiles newAppend() {
throw new UnsupportedOperationException("Cannot append to a " + descriptor + " table");
}
@Override
public RewriteFiles newRewrite() {
throw new UnsupportedOperationException("Cannot rewrite in a " + descriptor + " table");
}
@Override
public RewriteManifests rewriteManifests() {
throw new UnsupportedOperationException(
"Cannot rewrite manifests in a " + descriptor + " table");
}
@Override
public OverwriteFiles newOverwrite() {
throw new UnsupportedOperationException("Cannot overwrite in a " + descriptor + " table");
}
@Override
public RowDelta newRowDelta() {
throw new UnsupportedOperationException(
"Cannot remove or replace rows in a " + descriptor + " table");
}View on GitHub (pinned to 86d9c8fc54)