{"record":{"id":"111d82a3d289cb32","repo":"apache/iceberg","slug":"could-not-build-name-to-arg-map-validationerror","errorCode":null,"errorMessage":"Could not build name to arg map: ${validationErrors.mkString(\", \")}","messagePattern":"Could not build name to arg map: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"spark/v3.5/spark-extensions/src/main/scala/org/apache/spark/sql/catalyst/analysis/ResolveProcedures.scala","lineNumber":145,"sourceCode":"      buildNameToArgMapUsingNames(args, nameToPositionMap)\n    } else {\n      buildNameToArgMapUsingPositions(args, params)\n    }\n  }\n\n  private def buildNameToArgMapUsingNames(\n      args: Seq[CallArgument],\n      nameToPositionMap: Map[String, Int]): Map[String, CallArgument] = {\n\n    val namedArgs = args.asInstanceOf[Seq[NamedArgument]]\n\n    val validationErrors = namedArgs.groupBy(_.name).collect {\n      case (name, matchingArgs) if matchingArgs.size > 1 => s\"Duplicate procedure argument: $name\"\n      case (name, _) if !nameToPositionMap.contains(name) => s\"Unknown argument: $name\"\n    }\n\n    if (validationErrors.nonEmpty) {\n      throw new AnalysisException(\n        s\"Could not build name to arg map: ${validationErrors.mkString(\", \")}\")\n    }\n\n    namedArgs.map(arg => arg.name -> arg).toMap\n  }\n\n  private def buildNameToArgMapUsingPositions(\n      args: Seq[CallArgument],\n      params: Seq[ProcedureParameter]): Map[String, CallArgument] = {\n\n    if (args.size > params.size) {\n      throw new AnalysisException(\"Too many arguments for procedure\")\n    }\n\n    args.zipWithIndex.map { case (arg, position) =>\n      val param = params(position)\n      param.name -> arg\n    }.toMap","sourceCodeStart":127,"sourceCodeEnd":163,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/spark/v3.5/spark-extensions/src/main/scala/org/apache/spark/sql/catalyst/analysis/ResolveProcedures.scala#L127-L163","documentation":"Thrown by ResolveProcedures when named CALL arguments fail validation: the same name is supplied twice (\"Duplicate procedure argument: X\") or a supplied name matches no procedure parameter (\"Unknown argument: X\"). All validation errors are aggregated into one message.","triggerScenarios":"CALL proc(a => 1, a => 2) (duplicate) or CALL proc(were => '...') (typo — name not in the procedure's parameter map).","commonSituations":"Typos in named arguments; pasting a CALL twice with an argument repeated; referencing parameters of a different procedure version whose names changed.","solutions":["Fix the names listed in the message: remove duplicates and correct unknown argument names to match the procedure's parameter names","List the procedure's parameters (catalog docs / DESCRIBE) and validate each named argument against them","Convert to positional arguments if names are uncertain"],"exampleFix":"// before\nCALL catalog.system.expire_snapshots(table => 'db.t', table => 'db.t')\n// after\nCALL catalog.system.expire_snapshots(table => 'db.t')","handlingStrategy":"validation","validationCode":"val names = namedArgs.map(_.name)\nval unknown = names.filterNot(paramNames.contains)\nval dupes = names.groupBy(identity).collect { case (n, l) if l.size > 1 => n }\nrequire(unknown.isEmpty && dupes.isEmpty, s\"unknown: $unknown, dupes: $dupes\")","typeGuard":null,"tryCatchPattern":"try { spark.sql(callSql) } catch { case e: AnalysisException if e.getMessage.startsWith(\"Could not build name to arg map\") => // fix names per message }","preventionTips":["Validate each named argument against the procedure's declared parameter names","Avoid building CALL SQL by string concatenation that can repeat arguments","Keep parameter names in sync when copying CALLs between procedures"],"tags":["spark","sql","call-procedure","named-arguments"],"backgroundTag":"invalid-argument-value","analyzedSha":"86d9c8fc543e7c56c9f624eb725f76c9baff9570","analyzedAt":"2026-09-12T00:46:39.097Z","contentChangedAt":"2026-09-12T00:46:39.097Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}