apache/iceberg · error

CREATE_VIEW_COLUMN_ARITY_MISMATCH.NOT_ENOUGH_DATA_COLUMNS

CREATE_VIEW_COLUMN_ARITY_MISMATCH.NOT_ENOUGH_DATA_COLUMNS

Error message

[CREATE_VIEW_COLUMN_ARITY_MISMATCH.NOT_ENOUGH_DATA_COLUMNS]

What it means

When a CREATE VIEW statement specifies an explicit column list, Iceberg's CheckViews verifies the column count matches the query output. If the user names more view columns than the query produces, Spark's CREATE_VIEW_COLUMN_ARITY_MISMATCH.NOT_ENOUGH_DATA_COLUMNS error is raised with the view and query column lists in the message.

Source

Thrown at spark/v4.0/spark-extensions/src/main/scala/org/apache/spark/sql/catalyst/analysis/CheckViews.scala:77

            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(", ")))
      } 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],

View on GitHub (pinned to 86d9c8fc54)

Solutions

  1. Match the explicit column list length to the query's output column count
  2. Remove the explicit column list to let view columns inherit query output names
  3. Adjust the SELECT to produce as many columns as the view declares

Example fix

// before
CREATE VIEW v (a, b, c) 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("Declared view columns exceed query output columns")
}

Try / catch

try {
  spark.sql(createViewDdl)
} catch {
  case e: AnalysisException if e.getErrorClass.exists(_.startsWith("CREATE_VIEW_COLUMN_ARITY_MISMATCH")) =>
    logError(s"Column list mismatch in: $createViewDdl", e)
}

Prevention

When it happens

Trigger: CREATE VIEW v (a, b, c) AS SELECT x, y FROM t — the explicit column list (3) exceeds query output columns (2).

Common situations: Typos or stale column lists after the underlying SELECT changed; copying view DDL from another table with a wider schema; aliased-column refactors.

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


AI-assisted analysis of apache/iceberg@86d9c8fc54 (2026-09-12). Data as JSON: /api/errors/c5d0914cd445ae2e. Report an issue: GitHub.