{"record":{"id":"84f687d2a7740744","repo":"apache/iceberg","slug":"replacing-a-view-is-not-supported-by-catalog-ca-84f687","errorCode":null,"errorMessage":"Replacing a view is not supported by catalog: ${catalogName}","messagePattern":"Replacing a view is not supported by catalog: (.+?)","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"spark/v4.0/spark/src/main/java/org/apache/iceberg/spark/SparkSessionCatalog.java","lineNumber":502,"sourceCode":"      String[] columnAliases,\n      String[] columnComments,\n      Map<String, String> properties)\n      throws NoSuchNamespaceException, NoSuchViewException {\n    if (asViewCatalog instanceof SupportsReplaceView) {\n      return ((SupportsReplaceView) asViewCatalog)\n          .replaceView(\n              ident,\n              sql,\n              currentCatalog,\n              currentNamespace,\n              schema,\n              queryColumnNames,\n              columnAliases,\n              columnComments,\n              properties);\n    }\n\n    throw new UnsupportedOperationException(\n        \"Replacing a view is not supported by catalog: \" + catalogName);\n  }\n\n  @Override\n  public View alterView(Identifier ident, ViewChange... changes)\n      throws NoSuchViewException, IllegalArgumentException {\n    if (null != asViewCatalog && asViewCatalog.viewExists(ident)) {\n      return asViewCatalog.alterView(ident, changes);\n    } else if (isViewCatalog()) {\n      return getSessionCatalog().alterView(ident, changes);\n    }\n\n    throw new UnsupportedOperationException(\n        \"Altering a view is not supported by catalog: \" + catalogName);\n  }\n\n  @Override\n  public boolean dropView(Identifier ident) {","sourceCodeStart":484,"sourceCodeEnd":520,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/spark/v4.0/spark/src/main/java/org/apache/iceberg/spark/SparkSessionCatalog.java#L484-L520","documentation":"Thrown by SparkSessionCatalog.replaceView when no underlying catalog supports view replacement: no Iceberg ViewCatalog is present and the session catalog is not a view catalog. ALTER VIEW ... AS SELECT / REPLACE VIEW cannot be served.","triggerScenarios":"Executing CREATE OR REPLACE VIEW (or REPLACE VIEW) against a session catalog whose delegate lacks ViewCatalog support.","commonSituations":"Migrating SQL workloads that assume replaceable views to a catalog without view support; unqualified view DDL landing on the default session catalog instead of the Iceberg catalog.","solutions":["Route the replace to a catalog with view support (drop and qualify with the Iceberg view-capable catalog name).","Manually DROP VIEW then CREATE VIEW if replacement is not supported by the target.","Configure an Iceberg ViewCatalog as the session catalog delegate."],"exampleFix":"// before\nCREATE OR REPLACE VIEW spark_catalog.db.v AS SELECT ...\n// after\nDROP VIEW IF EXISTS spark_catalog.db.v;\nCREATE VIEW spark_catalog.db.v AS SELECT ...","handlingStrategy":"type-guard","validationCode":"if (!(catalog instanceof ViewCatalog)) { throw new IllegalStateException(\"replace view needs a ViewCatalog\"); }","typeGuard":"boolean supportsReplaceView(Catalog catalog) { return catalog instanceof ViewCatalog; }","tryCatchPattern":"try { catalog.replaceView(ident, ...); } catch (UnsupportedOperationException e) { /* drop+recreate fallback */ }","preventionTips":["Use catalogs with view support for CREATE OR REPLACE VIEW workloads.","Implement a DROP VIEW + CREATE VIEW fallback for catalogs without replacement.","Qualify view DDL with the view-capable catalog name so it is not routed to the session catalog."],"tags":["spark","views","unsupported-operation","catalog"],"backgroundTag":"unsupported-operation","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"}