apache/iceberg · error

Too many arguments for procedure

Error message

Too many arguments for procedure

What it means

Analysis-time validation in ResolveProcedures (Spark extensions): a CALL statement passed more positional arguments than the procedure declares parameters. It fires during analysis while binding procedure arguments — before execution — so the SQL itself must be corrected (drop extra arguments or use valid named arguments).

Solutions

  1. Remove the extra arguments so the count matches the procedure's declared parameters
  2. Switch to named arguments to make each value's target parameter explicit and catch the mismatch immediately
  3. Verify the procedure signature on your installed Iceberg version — it may differ from the documentation you copied

Example fix

// before
CALL catalog.system.expire_snapshots('db.t', TIMESTAMP '2020-01-01', 100, true)
// after
CALL catalog.system.expire_snapshots(table => 'db.t', older_than => TIMESTAMP '2020-01-01')
Defensive patterns

Strategy: validation

Validate before calling

val positionalArgs = callArgs.filterNot(_.isInstanceOf[NamedArgument])
require(positionalArgs.size <= procedureParams.size,
  s"${positionalArgs.size} args for ${procedureParams.size} params")

Try / catch

try { spark.sql(callSql) } catch { case e: AnalysisException if e.getMessage == "Too many arguments for procedure" => // drop extras or use named args }

Prevention

When it happens

Trigger: CALL catalog.system.proc(a, b, c) against a procedure that declares only 2 parameters, using positional (unnamed) arguments.

Common situations: Copy-pasted CALL statements from docs for a different procedure version; invoking a procedure on an older Iceberg/Spark build whose signature has fewer parameters.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


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

Appendix: source

Thrown at spark/v3.5/spark-extensions/src/main/scala/org/apache/spark/sql/catalyst/analysis/ResolveProcedures.scala:157

    val validationErrors = namedArgs.groupBy(_.name).collect {
      case (name, matchingArgs) if matchingArgs.size > 1 => s"Duplicate procedure argument: $name"
      case (name, _) if !nameToPositionMap.contains(name) => s"Unknown argument: $name"
    }

    if (validationErrors.nonEmpty) {
      throw new AnalysisException(
        s"Could not build name to arg map: ${validationErrors.mkString(", ")}")
    }

    namedArgs.map(arg => arg.name -> arg).toMap
  }

  private def buildNameToArgMapUsingPositions(
      args: Seq[CallArgument],
      params: Seq[ProcedureParameter]): Map[String, CallArgument] = {

    if (args.size > params.size) {
      throw new AnalysisException("Too many arguments for procedure")
    }

    args.zipWithIndex.map { case (arg, position) =>
      val param = params(position)
      param.name -> arg
    }.toMap
  }

  private def normalizeParams(params: Seq[ProcedureParameter]): Seq[ProcedureParameter] = {
    params.map {
      case param if param.required =>
        val normalizedName = param.name.toLowerCase(Locale.ROOT)
        ProcedureParameter.required(normalizedName, param.dataType)
      case param =>
        val normalizedName = param.name.toLowerCase(Locale.ROOT)
        ProcedureParameter.optional(normalizedName, param.dataType)
    }
  }

View on GitHub (pinned to 86d9c8fc54)