{"record":{"id":"e9f244459f22139b","repo":"apache/druid","slug":"lambda-expression-argument-count-of-d-does-not-ma","errorCode":null,"errorMessage":"lambda expression argument count of %d does not match the %d arguments passed to it","messagePattern":"lambda expression argument count of (.+?) does not match the (.+?) arguments passed to it","errorType":"validation","errorClass":"DruidException","httpStatus":null,"severity":"error","filePath":"processing/src/main/java/org/apache/druid/math/expr/NamedFunction.java","lineNumber":172,"sourceCode":"   * To compensate for this, the error message will indicate that at least count + 1 arguments are required to count\n   * the lambda.\n   */\n  default void validationHelperCheckMinArgumentCount(LambdaExpr lambdaExpr, List<Expr> args, int count)\n  {\n    if (args.size() < count) {\n      throw validationFailed(\"requires at least %d arguments\", count + 1);\n    }\n    validationHelperCheckLambaArgumentCount(lambdaExpr, args);\n  }\n\n  /**\n   * Helper method for implementors performing validation to check that the {@link LambdaExpr#identifierCount()}\n   * matches the number of arguments being passed to it\n   */\n  default void validationHelperCheckLambaArgumentCount(LambdaExpr lambdaExpr, List<Expr> args)\n  {\n    if (args.size() != lambdaExpr.identifierCount()) {\n      throw validationFailed(\n          \"lambda expression argument count of %d does not match the %d arguments passed to it\",\n          lambdaExpr.identifierCount(),\n          args.size()\n      );\n    }\n  }\n}\n","sourceCodeStart":154,"sourceCodeEnd":180,"githubUrl":"https://github.com/apache/druid/blob/9b90983fd291f26935af934383ce360473179e4d/processing/src/main/java/org/apache/druid/math/expr/NamedFunction.java#L154-L180","documentation":"For lambda functions, the lambda's number of identifiers must equal the number of non-lambda arguments (the arrays being iterated). validationHelperCheckLambaArgumentCount throws this when they diverge, e.g. a 2-identifier lambda over one array.","triggerScenarios":"MAP((x, y) -> ..., single_array), or FILTER((x) -> ..., arr1, arr2) — identifier count != array count.","commonSituations":"Rewriting single-array lambdas into multi-array form without updating the lambda signature, copy-paste between MAP/FILter/REDUCE variants.","solutions":["Align the lambda's parameter list with the number of array arguments","Add or remove array arguments to match lambda identifiers","Use LambdaExpr.identifierCount() when building expressions programmatically"],"exampleFix":"// before\nmap((x, y) -> x + y, arr1)\n// after\nmap((x) -> x * 2, arr1)  // or map((x, y) -> x + y, arr1, arr2)","handlingStrategy":"validation","validationCode":"if (lambdaExpr.identifierCount() != arrays.size()) { throw new IllegalArgumentException(\"lambda takes \" + lambdaExpr.identifierCount() + \" identifiers but \" + arrays.size() + \" arrays were given\"); }","typeGuard":"boolean lambdaMatchesArrays(LambdaExpr lambda, List<Expr> arrays) { return lambda.identifierCount() == arrays.size(); }","tryCatchPattern":"try { expr = Parser.parse(exprString); } catch (ExpressionValidationException e) { // fix lambda signature to match array count }","preventionTips":["Keep lambda parameters and iterated arrays in lockstep","Use identifierCount() when constructing LambdaExpr","Review copy-pasted MAP/FILTER/REDUCE expressions for signature drift"],"tags":["expression","lambda","argument-count"],"backgroundTag":"missing-required-argument","analyzedSha":"9b90983fd291f26935af934383ce360473179e4d","analyzedAt":"2026-09-07T13:32:30.957Z","contentChangedAt":"2026-09-07T13:32:30.957Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}