apache/druid · error · DruidException

lambda expression argument count of

Error message

lambda expression argument count of %d does not match the %d arguments passed to it

What it means

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.

Solutions

  1. Align the lambda's parameter list with the number of array arguments
  2. Add or remove array arguments to match lambda identifiers
  3. Use LambdaExpr.identifierCount() when building expressions programmatically

Example fix

// before
map((x, y) -> x + y, arr1)
// after
map((x) -> x * 2, arr1)  // or map((x, y) -> x + y, arr1, arr2)
Defensive patterns

Strategy: validation

Validate before calling

if (lambdaExpr.identifierCount() != arrays.size()) { throw new IllegalArgumentException("lambda takes " + lambdaExpr.identifierCount() + " identifiers but " + arrays.size() + " arrays were given"); }

Type guard

boolean lambdaMatchesArrays(LambdaExpr lambda, List<Expr> arrays) { return lambda.identifierCount() == arrays.size(); }

Try / catch

try { expr = Parser.parse(exprString); } catch (ExpressionValidationException e) { // fix lambda signature to match array count }

Prevention

When it happens

Trigger: MAP((x, y) -> ..., single_array), or FILTER((x) -> ..., arr1, arr2) — identifier count != array count.

Common situations: Rewriting single-array lambdas into multi-array form without updating the lambda signature, copy-paste between MAP/FILter/REDUCE variants.

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/druid@9b90983fd2 (2026-09-07). Data as JSON: /api/errors/e9f244459f22139b. Report an issue: GitHub.

Appendix: source

Thrown at processing/src/main/java/org/apache/druid/math/expr/NamedFunction.java:172

   * To compensate for this, the error message will indicate that at least count + 1 arguments are required to count
   * the lambda.
   */
  default void validationHelperCheckMinArgumentCount(LambdaExpr lambdaExpr, List<Expr> args, int count)
  {
    if (args.size() < count) {
      throw validationFailed("requires at least %d arguments", count + 1);
    }
    validationHelperCheckLambaArgumentCount(lambdaExpr, args);
  }

  /**
   * Helper method for implementors performing validation to check that the {@link LambdaExpr#identifierCount()}
   * matches the number of arguments being passed to it
   */
  default void validationHelperCheckLambaArgumentCount(LambdaExpr lambdaExpr, List<Expr> args)
  {
    if (args.size() != lambdaExpr.identifierCount()) {
      throw validationFailed(
          "lambda expression argument count of %d does not match the %d arguments passed to it",
          lambdaExpr.identifierCount(),
          args.size()
      );
    }
  }
}

View on GitHub (pinned to 9b90983fd2)