{"record":{"id":"68bc142c4cd17693","repo":"apache/iceberg","slug":"renaming-a-view-is-not-supported-by-catalog","errorCode":null,"errorMessage":"Renaming a view is not supported by catalog: ","messagePattern":"Renaming a view is not supported by catalog: ","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"spark/v4.1/spark/src/main/java/org/apache/iceberg/spark/SparkSessionCatalog.java","lineNumber":579,"sourceCode":"  public boolean dropView(Identifier ident) {\n    if (null != asViewCatalog && asViewCatalog.viewExists(ident)) {\n      return asViewCatalog.dropView(ident);\n    } else if (isViewCatalog()) {\n      return getSessionCatalog().dropView(ident);\n    }\n\n    return false;\n  }\n\n  @Override\n  public void renameView(Identifier fromIdentifier, Identifier toIdentifier)\n      throws NoSuchViewException, ViewAlreadyExistsException {\n    if (null != asViewCatalog && asViewCatalog.viewExists(fromIdentifier)) {\n      asViewCatalog.renameView(fromIdentifier, toIdentifier);\n    } else if (isViewCatalog()) {\n      getSessionCatalog().renameView(fromIdentifier, toIdentifier);\n    } else {\n      throw new UnsupportedOperationException(\n          \"Renaming a view is not supported by catalog: \" + catalogName);\n    }\n  }\n}\n","sourceCodeStart":561,"sourceCodeEnd":584,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/spark/v4.1/spark/src/main/java/org/apache/iceberg/spark/SparkSessionCatalog.java#L561-L584","documentation":"renameView in SparkSessionCatalog throws UnsupportedOperationException when neither the delegate view catalog nor the session catalog supports view renaming. Like other view operations, it is only available through a ViewCatalog-capable underlying catalog.","triggerScenarios":"Executing ALTER VIEW ... RENAME TO on a catalog without ViewCatalog support; both asViewCatalog checks and isViewCatalog() fail so the else branch throws.","commonSituations":"Renaming views in spark_catalog backed by a table-only delegate; migration scripts assuming view rename works everywhere; Spark versions where session catalogs lack view rename.","solutions":["Rename via DROP VIEW + CREATE VIEW in a view-capable catalog","Register an Iceberg view-capable catalog (REST/Hive with views) and perform the rename there","Rename the view in the underlying metastore directly if it is a session/Hive view"],"exampleFix":"// before\nspark.sql(\"ALTER VIEW iceberg.db.v1 RENAME TO iceberg.db.v2\"); // unsupported\n// after\nspark.sql(\"CREATE VIEW spark_catalog.db.v2 AS SELECT * FROM spark_catalog.db.v1\");\nspark.sql(\"DROP VIEW spark_catalog.db.v1\");","handlingStrategy":"fallback","validationCode":null,"typeGuard":"boolean supportsViewRename(Catalog c) { return c instanceof ViewCatalog; }","tryCatchPattern":"try {\n  catalog.renameView(from, to);\n} catch (UnsupportedOperationException e) {\n  // fall back to DROP + CREATE\n}","preventionTips":["Avoid ALTER VIEW RENAME on catalogs without view support; script DROP+CREATE instead","Consolidate views in one view-capable catalog so rename is available"],"tags":["spark","catalog","view","unsupported-operation","rename"],"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"}