apache/iceberg · error · IcebergAnalysisException
ALTER VIEW AS is not supported. Use CREATE OR REPLACE VIEW…
Error message
ALTER VIEW <viewName> AS is not supported. Use CREATE OR REPLACE VIEW instead
What it means
Iceberg's view support in Spark 4.0 does not implement ALTER VIEW ... AS (redefining a view in place). When CheckViews sees AlterViewAs applied to a resolved Iceberg V2 view, it throws this IcebergAnalysisException and directs users to CREATE OR REPLACE VIEW, which Iceberg supports for full view redefinition.
Solutions
- Rewrite the statement as CREATE OR REPLACE VIEW catalog.db.v AS SELECT ...
- Drop and recreate the view if replace semantics are unacceptable
- Use ALTER VIEW only for operations Iceberg supports (e.g. rename is via ALTER VIEW RENAME TO)
Example fix
// before ALTER VIEW my_view AS SELECT id, name FROM t // after CREATE OR REPLACE VIEW my_view AS SELECT id, name FROM t
Defensive patterns
Strategy: validation
Validate before calling
// static check: replace any occurrence in your SQL pipeline val fixed = sql.replaceAll(?i"ALTER\s+VIEW\s+(\S+)\s+AS", "CREATE OR REPLACE VIEW $1 AS")
Try / catch
try {
spark.sql(stmt)
} catch {
case e: Exception if e.getMessage.contains("ALTER VIEW") && e.getMessage.contains("CREATE OR REPLACE VIEW") =>
val rewritten = rewriteAlterViewAs(stmt)
spark.sql(rewritten)
} Prevention
- Use CREATE OR REPLACE VIEW as the standard redefinition idiom for Iceberg views
- Lint SQL scripts for ALTER VIEW ... AS against Iceberg catalogs
- Review migration scripts from the built-in session catalog for unsupported DDL
When it happens
Trigger: Running ALTER VIEW catalog.db.v AS SELECT ... against an Iceberg view (a ResolvedV2View) via the Iceberg Spark extensions.
Common situations: Scripts written for the built-in Spark session catalog ported to Iceberg catalogs where ALTER VIEW AS is unavailable; schema-evolution workflows attempting to redefine a view in place.
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
- ALTER VIEW AS is not supported. Use CREATE OR REPLACE VIEW…
- Cannot remove property that is not set: '$property'
- CREATE_VIEW_COLUMN_ARITY_MISMATCH.NOT_ENOUGH_DATA_COLUMNS
- CREATE_VIEW_COLUMN_ARITY_MISMATCH.NOT_ENOUGH_DATA_COLUMNS
- CREATE_VIEW_COLUMN_ARITY_MISMATCH.TOO_MANY_DATA_COLUMNS
AI-assisted analysis of apache/iceberg@86d9c8fc54 (2026-09-12).
Data as JSON: /api/errors/936cafc980c2558f.
Report an issue: GitHub.
Appendix: source
Thrown at spark/v4.0/spark-extensions/src/main/scala/org/apache/spark/sql/catalyst/analysis/CheckViews.scala:64
_,
_,
_,
_,
replace,
_,
_) =>
verifyColumnCount(resolvedIdent, columnAliases, query)
SchemaUtils.checkColumnNameDuplication(
query.schema.fieldNames.toIndexedSeq,
SQLConf.get.resolver)
if (replace) {
val viewIdent: Seq[String] =
resolvedIdent.catalog.name() +: resolvedIdent.identifier.asMultipartIdentifier
checkCyclicViewReference(viewIdent, query, Seq(viewIdent))
}
case AlterViewAs(ResolvedV2View(_, _), _, _) =>
throw new IcebergAnalysisException(
"ALTER VIEW <viewName> AS is not supported. Use CREATE OR REPLACE VIEW instead")
case _ => // OK
}
}
private def verifyColumnCount(
ident: ResolvedIdentifier,
columns: Seq[String],
query: LogicalPlan): Unit = {
if (columns.nonEmpty) {
if (columns.length > query.output.length) {
throw new AnalysisException(
errorClass = "CREATE_VIEW_COLUMN_ARITY_MISMATCH.NOT_ENOUGH_DATA_COLUMNS",
messageParameters = Map(
"viewName" -> String.format("%s.%s", ident.catalog.name(), ident.identifier),
"viewColumns" -> columns.mkString(", "),
"dataColumns" -> query.output.map(c => c.name).mkString(", ")))View on GitHub (pinned to 86d9c8fc54)