apache/iceberg · error
CREATE_VIEW_COLUMN_ARITY_MISMATCH.TOO_MANY_DATA_COLUMNS
CREATE_VIEW_COLUMN_ARITY_MISMATCH.TOO_MANY_DATA_COLUMNS
Error message
[CREATE_VIEW_COLUMN_ARITY_MISMATCH.TOO_MANY_DATA_COLUMNS]
What it means
Mirror case of the NOT_ENOUGH_DATA_COLUMNS check: if a CREATE VIEW statement's explicit column list has fewer names than the query's output columns, CheckViews throws Spark's CREATE_VIEW_COLUMN_ARITY_MISMATCH.TOO_MANY_DATA_COLUMNS. Each declared view column must map to exactly one query output column.
Source
Thrown at spark/v4.0/spark-extensions/src/main/scala/org/apache/spark/sql/catalyst/analysis/CheckViews.scala:84
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(", ")))
} else if (columns.length < query.output.length) {
throw new AnalysisException(
errorClass = "CREATE_VIEW_COLUMN_ARITY_MISMATCH.TOO_MANY_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(", ")))
}
}
}
private def checkCyclicViewReference(
viewIdent: Seq[String],
plan: LogicalPlan,
cyclePath: Seq[Seq[String]]): Unit = {
plan match {
case sub @ SubqueryAlias(_, Project(_, _)) =>
val currentViewIdent: Seq[String] = sub.identifier.qualifier :+ sub.identifier.name
checkIfRecursiveView(viewIdent, currentViewIdent, cyclePath, sub.children)
case v1View: View =>View on GitHub (pinned to 86d9c8fc54)
Solutions
- Add the missing column names to the explicit view column list
- Reduce the SELECT to only the columns the view should expose
- Drop the explicit column list entirely
Example fix
// before CREATE VIEW v (a) AS SELECT x, y FROM t // after CREATE VIEW v (a, b) AS SELECT x, y FROM t
Defensive patterns
Strategy: validation
Validate before calling
val queryOutput = spark.sql(viewQuery).schema.length
if (declaredColumns.length < queryOutput) {
throw new IllegalArgumentException("Query output has more columns than declared view columns")
} Try / catch
try {
spark.sql(createViewDdl)
} catch {
case e: AnalysisException if e.getErrorClass.contains("TOO_MANY_DATA_COLUMNS") =>
logError(s"Declared too few view columns: $createViewDdl", e)
} Prevention
- Alias all SELECT columns explicitly and mirror them in the column list
- Recompute the column list whenever the SELECT changes
- Prefer omitting the column list and relying on SELECT aliases
When it happens
Trigger: CREATE VIEW v (a) AS SELECT x, y FROM t — the query produces 2 columns but only 1 view column is declared.
Common situations: Forgetting to alias extra SELECT columns or omitting them from the column list; schema drift in the underlying query adding columns; templated DDL generated with a stale column list.
Understand the failure class
Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.
Related errors
- CREATE_VIEW_COLUMN_ARITY_MISMATCH.NOT_ENOUGH_DATA_COLUMNS
- Renaming a view is not supported by catalog: ${catalogName}
- Unsupported Spark view dependency: ${dependency.getClass().g
- Failed to write Spark view dependencies
- Failed to parse Spark view dependencies
AI-assisted analysis of apache/iceberg@86d9c8fc54 (2026-09-12).
Data as JSON: /api/errors/00247965e41db58b.
Report an issue: GitHub.