{"record":{"id":"c958b80b73f0b7cc","repo":"apache/iceberg","slug":"does-not-support-altering-tables-c958b8","errorCode":null,"errorMessage":" does not support altering tables","messagePattern":" does not support altering tables","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"spark/v4.1/spark/src/main/java/org/apache/iceberg/spark/SparkRewriteTableCatalog.java","lineNumber":82,"sourceCode":"  @Override\n  public SparkTable loadTable(Identifier ident, long timestampMicros) throws NoSuchTableException {\n    throw new UnsupportedOperationException(CLASS_NAME + \" does not support time travel\");\n  }\n\n  @Override\n  public void invalidateTable(Identifier ident) {\n    throw new UnsupportedOperationException(CLASS_NAME + \" does not support table invalidation\");\n  }\n\n  @Override\n  public SparkTable createTable(Identifier ident, TableInfo tableInfo)\n      throws TableAlreadyExistsException {\n    throw new UnsupportedOperationException(CLASS_NAME + \" does not support creating tables\");\n  }\n\n  @Override\n  public SparkTable alterTable(Identifier ident, TableChange... changes) {\n    throw new UnsupportedOperationException(CLASS_NAME + \" does not support altering tables\");\n  }\n\n  @Override\n  public boolean dropTable(Identifier ident) {\n    throw new UnsupportedOperationException(CLASS_NAME + \" does not support dropping tables\");\n  }\n\n  @Override\n  public boolean purgeTable(Identifier ident) throws UnsupportedOperationException {\n    throw new UnsupportedOperationException(CLASS_NAME + \" does not support purging tables\");\n  }\n\n  @Override\n  public void renameTable(Identifier oldIdent, Identifier newIdent) {\n    throw new UnsupportedOperationException(CLASS_NAME + \" does not support renaming tables\");\n  }\n\n  @Override","sourceCodeStart":64,"sourceCodeEnd":100,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/spark/v4.1/spark/src/main/java/org/apache/iceberg/spark/SparkRewriteTableCatalog.java#L64-L100","documentation":"SparkRewriteTableCatalog.alterTable(ident, changes) always throws UnsupportedOperationException because schema/partition/property changes must be applied through a real catalog; the rewrite catalog is read-only over cached table instances.","triggerScenarios":"Calling alterTable with TableChange arguments on SparkRewriteTableCatalog, or generic clients applying DDL (ALTER TABLE) where the session resolves to the rewrite catalog.","commonSituations":"Migration scripts applying schema changes across catalogs; setting the rewrite catalog as session default so ALTER TABLE routes to it; framework code updating table properties generically.","solutions":["Apply table changes through the real catalog (SparkCatalog.alterTable) or SQL ALTER TABLE on the source catalog.","Use Iceberg's UpdateSchema/UpdateProperties APIs on the loaded org.apache.iceberg.Table for programmatic changes.","Never route DDL through SparkRewriteTableCatalog."],"exampleFix":"// before\nrewriteCatalog.alterTable(ident, TableChange.addColumn(\"new_col\", IntegerType));\n// after\nsparkCatalog.alterTable(ident, TableChange.addColumn(\"new_col\", IntegerType)); // DDL via the real catalog","handlingStrategy":"validation","validationCode":"if (catalog instanceof SparkRewriteTableCatalog) {\n  throw new IllegalArgumentException(\"ALTER TABLE must target a real Iceberg catalog\");\n}","typeGuard":"boolean supportsAlter(CatalogPlugin c) {\n  return !(c instanceof SparkRewriteTableCatalog);\n}","tryCatchPattern":"try {\n  catalog.alterTable(ident, changes);\n} catch (UnsupportedOperationException e) {\n  realCatalog.alterTable(ident, changes);\n}","preventionTips":["Apply schema/property changes via the source catalog or Iceberg Update* APIs.","Never route ALTER TABLE through the rewrite catalog.","Keep the rewrite catalog out of session default position.","Capability-check catalogs before issuing DDL."],"tags":["spark","rewrite","unsupported-operation","ddl"],"backgroundTag":"operation-not-supported","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"}