apache/iceberg · error
invalidViewNameError(name)
Error message
invalidViewNameError(name)
What it means
When resolving a view, Iceberg re-parses the stored view SQL text with Spark's SQL parser. If parsing fails with a ParseException, the error is reported as an invalid view name rather than leaking the parse exception, because a view whose text cannot be parsed under the current catalog/namespace context is effectively unresolvable. This guards users with a clearer message tied to the view name.
Solutions
- DROP and recreate the view with SQL that parses in the current Spark/catalog context
- Inspect the view's stored text (SHOW CREATE TABLE / metadata) and fix invalid syntax
- Align the Spark version or parser used to the one that created the view
- Qualify all references inside the view text so it parses regardless of current namespace
Example fix
-- before: query stale view SELECT * FROM catalog.db.old_view; -- ParseException internally -- after: recreate it DROP VIEW catalog.db.old_view; CREATE VIEW catalog.db.old_view AS SELECT id, ts FROM catalog.db.src;
Defensive patterns
Strategy: try-catch
Validate before calling
// verify the view resolves before querying
val exists = spark.catalog.tableExists("catalog", "db", "old_view")
if (!exists) throw new IllegalStateException("view missing; recreate it") Try / catch
try {
spark.sql(s"SELECT * FROM catalog.db.v")
} catch {
case e: AnalysisException if e.getMessage.contains("invalid view name") =>
// viewText no longer parses: recreate the view
spark.sql("CREATE VIEW catalog.db.v AS <valid SQL>")
} Prevention
- Fully qualify all table/catalog references inside view definitions
- Recreate views after Spark major upgrades and verify with a test query
- Avoid hand-editing view metadata
When it happens
Trigger: Querying or resolving a stored view whose viewText no longer parses in the current session/catalog context — e.g. the view SQL references identifiers, functions, or syntax invalid under the resolved catalog and namespace, or the view was created by an older/other engine with syntax the current parser rejects.
Common situations: Views created under a different Spark version whose SQL is no longer parseable; view text stored with dialect-specific syntax; corrupted or hand-edited view metadata; catalog/namespace change making an unqualified reference in viewText invalid.
Understand the failure class
Background: "invalid id" errors: invalid identifier format — why libraries reject IDs before lookup, and how to fix them — this error's family across 37 libraries.
Related errors
- ALTER VIEW AS is not supported. Use CREATE OR REPLACE VIEW…
- ALTER VIEW AS is not supported. Use CREATE OR REPLACE VIEW…
- ALTER VIEW AS is not supported. Use CREATE OR REPLACE VIEW…
- Altering a view is not supported by catalog
- Cannot move view between catalogs: from=
AI-assisted analysis of apache/iceberg@86d9c8fc54 (2026-09-12).
Data as JSON: /api/errors/ae6ed624ee3aa94a.
Report an issue: GitHub.
Appendix: source
Thrown at spark/v4.1/spark-extensions/src/main/scala/org/apache/spark/sql/catalyst/analysis/ResolveViews.scala:161
SparkSQLProperties.VIEW_SCHEMA_MODE_COMPENSATION
} else {
throw new IllegalArgumentException(
s"Invalid value for ${SparkSQLProperties.VIEW_SCHEMA_BINDING_MODE}: $mode, expected " +
s"${SparkSQLProperties.VIEW_SCHEMA_MODE_BINDING} or " +
s"${SparkSQLProperties.VIEW_SCHEMA_MODE_COMPENSATION}")
}
}
private def parseViewText(name: String, viewText: String): LogicalPlan = {
val origin = Origin(objectType = Some("VIEW"), objectName = Some(name))
try {
CurrentOrigin.withOrigin(origin) {
spark.sessionState.sqlParser.parseQuery(viewText)
}
} catch {
case _: ParseException =>
throw QueryCompilationErrors.invalidViewNameError(name)
}
}
private def rewriteIdentifiers(
plan: LogicalPlan,
catalogAndNamespace: Seq[String]): LogicalPlan = {
// Rewrite unresolved functions and relations
qualifyTableIdentifiers(
qualifyFunctionIdentifiers(CTESubstitution.apply(plan), catalogAndNamespace),
catalogAndNamespace)
}
private def qualifyFunctionIdentifiers(
plan: LogicalPlan,
catalogAndNamespace: Seq[String]): LogicalPlan = plan transformExpressions {
case u @ UnresolvedFunction(Seq(name), _, _, _, _, _, _) =>
if (!isBuiltinFunction(name)) {
u.copy(nameParts = catalogAndNamespace :+ name)View on GitHub (pinned to 86d9c8fc54)