apache/iceberg · error · AnalysisException
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 3.5 RewriteViewCommands rule throws this AnalysisException when a CREATE VIEW targeting a permanent (non-session) view catalog resolves to a plan that references session-scoped temporary objects. Permanent views store their SQL text and must be resolvable independent of the creator's session, so temp views/functions (which die with the session) may not appear in their definition. The check runs in verifyTemporaryObjectsDontExist during analysis of CreateViewCommand-like plans.
Source
Thrown at spark/v3.5/spark-extensions/src/main/scala/org/apache/spark/sql/catalyst/analysis/RewriteViewCommands.scala:134
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 AnalysisException(
String.format(
"Cannot create view %s.%s that references temporary %s: %s",View on GitHub (pinned to 86d9c8fc54)
Solutions
- Replace the temporary view reference with a persistent table or view (e.g., CREATE OR REPLACE TABLE / VIEW in a real catalog) before creating the permanent view.
- Inline the temp view's query into the new view definition: CREATE VIEW cat.db.v AS SELECT * FROM (<temp view query>).
- Replace temporary function usage with a permanent function registered in the catalog, or inline its logic.
- If the intent was session-local, create the view in the session catalog instead: CREATE TEMPORARY VIEW tmp AS ... or omit the Iceberg catalog prefix.
- If defining multiple persistent views from temp views, create them bottom-up: first persist the base temp view, then create dependent views.
Example fix
// before (fails) CREATE TEMPORARY VIEW tmp_filtered AS SELECT * FROM events WHERE day = '2026-01-01'; CREATE VIEW iceberg.db.daily AS SELECT * FROM tmp_filtered; // after (works) CREATE TABLE iceberg.db.daily_base AS SELECT * FROM events WHERE day = '2026-01-01'; CREATE VIEW iceberg.db.daily AS SELECT * FROM iceberg.db.daily_base;
Defensive patterns
Strategy: validation
Validate before calling
// Spark 3.5 (Scala): check plan for temp views before CREATE VIEW on a view catalog
val analyzed = spark.sessionState.executePlan(df.queryExecution.logical).analyzed
val usesTemp = analyzed.flatMap {
case r: org.apache.spark.sql.catalyst.analysis.UnresolvedRelation
if spark.sessionState.catalog.isTempView(r.multipartIdentifier) => true
case _ => false
}.nonEmpty
if (usesTemp) throw new IllegalStateException("view body references temp views; persist them first") Type guard
def referencesTempView(sql: String, spark: SparkSession): Boolean = spark.sessionState.catalog.listTempViews().exists(v => sql.contains(v.name))
Prevention
- Never reference CREATE TEMPORARY VIEW objects inside CREATE VIEW statements targeting an Iceberg/view catalog.
- Persist intermediate results as tables or permanent views before building dependent views.
- Register shared UDFs as permanent catalog functions, not temporary ones.
- In notebooks, keep a convention: temp views are staging only; final views must inline or reference catalog objects.
- Test view creation in a fresh session — anything that fails there will hit this error.
When it happens
Trigger: Running `CREATE VIEW iceberg_catalog.db.permanent_view AS SELECT ... FROM temp_view` where temp_view was created via `CREATE TEMPORARY VIEW`, or `CREATE VIEW cat.db.v AS SELECT temp_fn(col) FROM t` where temp_fn is a session temporary function. The message names the offending object and whether it was a temporary view or function.
Common situations: Developers migrate a session temp view to a persistent Iceberg view by re-running the definition with CREATE VIEW but forgetting the body still reads from a temp view or uses a temp UDF. Also common in notebooks where setup code creates temp views, then a persistent view is defined on top of them; works in dev session, fails on restart.
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
- Cannot move view between catalogs: from=${oldCatalog.name} a
- View not found: ${ident.quoted}
- Cannot move view between catalogs: from=${oldCatalog.name} a
AI-assisted analysis of apache/iceberg@86d9c8fc54 (2026-09-12).
Data as JSON: /api/errors/4e7fda19e491446b.
Report an issue: GitHub.