{"record":{"id":"e4164751092da16a","repo":"apache/iceberg","slug":"cannot-replace-partitions-in-a-s-table","errorCode":null,"errorMessage":"Cannot replace partitions in a %s table","messagePattern":"Cannot replace partitions in a (.+?) table","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/org/apache/iceberg/BaseReadOnlyTable.java","lineNumber":88,"sourceCode":"  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  }\n\n  @Override\n  public ReplacePartitions newReplacePartitions() {\n    throw new UnsupportedOperationException(\n        \"Cannot replace partitions in a \" + descriptor + \" table\");\n  }\n\n  @Override\n  public DeleteFiles newDelete() {\n    throw new UnsupportedOperationException(\"Cannot delete from a \" + descriptor + \" table\");\n  }\n\n  @Override\n  public UpdateStatistics updateStatistics() {\n    throw new UnsupportedOperationException(\n        \"Cannot update statistics of a \" + descriptor + \" table\");\n  }\n\n  @Override\n  public UpdatePartitionStatistics updatePartitionStatistics() {\n    throw new UnsupportedOperationException(\n        \"Cannot update partition statistics of a \" + descriptor + \" table\");","sourceCodeStart":70,"sourceCodeEnd":106,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/core/src/main/java/org/apache/iceberg/BaseReadOnlyTable.java#L70-L106","documentation":"BaseReadOnlyTable wraps a table snapshot in a read-only view (e.g. a time-travel snapshot reference or metadata table). All mutation APIs are disabled, so calling newReplacePartitions() throws UnsupportedOperationException. The library cannot accept row replacements against a table that has no write path to the current table metadata.","triggerScenarios":"Calling table.newReplacePartitions() on a Table instance backed by BaseReadOnlyTable — i.e. a snapshot object or other read-only descriptor obtained from Iceberg metadata rather than a writable table handle.","commonSituations":"Fetching a snapshot via table.snapshot(...)-style read-only wrappers, using a metadata/view table as if it were a base table, or passing a read-only table handle into generic code that performs overwrite-by-partition writes.","solutions":["Resolve the actual current Table from the catalog (catalog.loadTable(identifier)) instead of using the read-only/snapshot wrapper.","Guard generic write code with a capability check before calling newReplacePartitions().","If the intent is snapshot-based writes, create a branching/writing through WAP or branch references on the real table."],"exampleFix":"// before\nTable snapshotView = getReadOnlyTable();\nsnapshotView.newReplacePartitions().appendFile(dataFile).commit();\n// after\nTable table = catalog.loadTable(tableIdentifier);\ntable.newReplacePartitions().appendFile(dataFile).commit();","handlingStrategy":"validation","validationCode":"// Java\nif (table instanceof BaseReadOnlyTable || isReadOnly(table)) {\n  throw new IllegalStateException(\"Table handle is read-only; load via catalog.loadTable() to write\");\n}\ntable.newReplacePartitions()...","typeGuard":"boolean isWritable(Table t) { return !(t instanceof BaseReadOnlyTable); }","tryCatchPattern":"try { table.newReplacePartitions()...commit(); } catch (UnsupportedOperationException e) { /* fall back to catalog.loadTable() */ }","preventionTips":["Only call write APIs on tables loaded from catalog.loadTable(identifier)","Use snapshot handles solely for time-travel reads","Centralize write paths in a utility that resolves a writable table handle first"],"tags":["unsupported-operation","read-only-table","iceberg"],"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"}