apache/iceberg · error · IcebergAnalysisException
Cannot create view %s.%s that references temporary %s: %s
Error message
Cannot create view %s.%s that references temporary %s: %s
What it means
Iceberg's Spark 4.0 RewriteViewCommands rule throws this AnalysisException when a CREATE VIEW on a view catalog (e.g., Iceberg's REST view catalog) resolves to a plan referencing session-scoped temporary views. Permanent views must be reproducible in any session, so temporary views in their definition are rejected. verifyTemporaryObjectsDontExist performs the check during analysis.
Source
Thrown at spark/v4.0/spark-extensions/src/main/scala/org/apache/spark/sql/catalyst/analysis/RewriteViewCommands.scala:135
case UnresolvedIdentifier(CatalogAndIdentifier(catalog, ident), _)
if ViewUtil.isViewCatalog(catalog) =>
Some(ResolvedIdentifier(catalog, ident))
case _ =>
None
}
}
/**
* Permanent views are not allowed to reference temp objects
*/
private def verifyTemporaryObjectsDontExist(
identifier: ResolvedIdentifier,
child: LogicalPlan): Unit = {
val tempViews = collectTemporaryViews(child)
if (tempViews.nonEmpty) {
throw invalidRefToTempObject(
identifier,
tempViews.map(v => v.quoted).mkString("[", ", ", "]"),
"view")
}
val tempFunctions = collectTemporaryFunctions(child)
if (tempFunctions.nonEmpty) {
throw invalidRefToTempObject(identifier, tempFunctions.mkString("[", ", ", "]"), "function")
}
}
private def invalidRefToTempObject(
ident: ResolvedIdentifier,
tempObjectNames: String,
tempObjectType: String) = {
new IcebergAnalysisException(
String.format(
"Cannot create view %s.%s that references temporary %s: %s",View on GitHub (pinned to 86d9c8fc54)
Solutions
- Persist the temp view's source as a table or permanent view first, then reference that in the new view definition.
- Inline the temp view's SELECT statement into the new view's body.
- Register temp views' data in the Iceberg catalog rather than the session catalog.
- Use CREATE TEMPORARY VIEW for the outer view too if it is genuinely session-scoped.
Example fix
// before (fails) CREATE TEMPORARY VIEW staging AS SELECT * FROM raw.events; CREATE VIEW rest_cat.db.final_view AS SELECT * FROM staging; // after (works) CREATE TABLE rest_cat.db.staging AS SELECT * FROM raw.events; CREATE VIEW rest_cat.db.final_view AS SELECT * FROM rest_cat.db.staging;
Defensive patterns
Strategy: validation
Validate before calling
// Spark 4.0: verify the view's source plan contains no temp views before CREATE VIEW
val analyzed = spark.sessionState.executePlan(df.queryExecution.logical).analyzed
val temps = analyzed.flatMap {
case r: org.apache.spark.sql.catalyst.analysis.UnresolvedRelation
if spark.sessionState.catalog.isTempView(r.multipartIdentifier) => Seq(r.multipartIdentifier)
case _ => Seq.empty
}
if (temps.nonEmpty) throw new IllegalStateException(s"resolve temp views first: $temps") Type guard
def bodyReferencesTempView(viewSql: String, spark: SparkSession): Boolean = spark.sessionState.catalog.listTempViews().exists(v => viewSql.contains(v.name))
Prevention
- Treat session temp views as ephemeral staging; never build catalog views on them.
- Persist the staging result with CREATE TABLE before defining a permanent view.
- Inline temp view definitions into the permanent view's SQL where feasible.
- Enforce in code review: CREATE VIEW bodies must reference only catalog-qualified objects.
- Re-run view creation in a clean session as a CI check.
When it happens
Trigger: `CREATE VIEW iceberg_catalog.db.v AS SELECT ... FROM temp_view` where temp_view is a session temp view (CREATE TEMPORARY VIEW). The exception message includes the quoted temp view names and the target view identifier.
Common situations: Notebook pipelines that stage data as temp views then persist a 'final' Iceberg view referencing them; CI jobs that recreate temp views per run and then create permanent views; migrations from Spark session views to Iceberg views where the body was copied verbatim.
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
- Cannot create view %s.%s that references temporary %s: %s
- Cannot create view %s.%s that references temporary %s: %s
- View does not exist: ident
- View does not exist: fromIdentifier
- View already exists: toIdentifier
AI-assisted analysis of apache/iceberg@86d9c8fc54 (2026-09-12).
Data as JSON: /api/errors/9fbac6746a200e59.
Report an issue: GitHub.