apache/druid · error · ExpressionValidationException

requires %d arguments

Error message

requires %d arguments

What it means

Same validation as the fixed-count check, but for counts other than 0 or 1: a NamedFunction requiring exactly N arguments received fewer or more, and the message interpolates N. Thrown during expression validation before evaluation.

Source

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

  }

  default ExpressionProcessingException processingFailed(Throwable e, String reasonFormat, Object... args)
  {
    throw new ExpressionProcessingException(this, e, reasonFormat, args);
  }

  /**
   * Helper method for implementors performing validation to check if the argument count is expected
   */
  default void validationHelperCheckArgumentCount(List<Expr> args, int count)
  {
    if (args.size() != count) {
      if (count == 0) {
        throw validationFailed("does not accept arguments");
      } else if (count == 1) {
        throw validationFailed("requires 1 argument");
      }
      throw validationFailed("requires %d arguments", count);
    }
  }

  /**
   * Helper method for implementors performing validation to check if there are at least as many arguments as specified
   */
  default void validationHelperCheckMinArgumentCount(List<Expr> args, int count)
  {
    if (args.size() < count) {
      if (count == 1) {
        throw validationFailed("requires at least 1 argument");
      }
      throw validationFailed("requires at least %d arguments", count);
    }
  }

  default void validationHelperCheckArgumentRange(List<Expr> args, int start, int end)
  {

View on GitHub (pinned to 9b90983fd2)

Solutions

  1. Supply exactly N arguments as declared by the function
  2. Read the function's validationHelperCheckArgumentCount call to learn N
  3. Use validationHelperCheckArgumentRange/MinArgumentCount-style functions if variable arity is intended

Example fix

// before
position = locate(needle)  // requires 2
// after
position = locate(needle, haystack)
Defensive patterns

Strategy: validation

Validate before calling

if (args.size() != expectedCount) { throw new IllegalArgumentException(funcName + " requires exactly " + expectedCount + " arguments, got " + args.size()); }

Type guard

boolean hasExactArity(List<Expr> args, int n) { return args != null && args.size() == n; }

Try / catch

try { expr = Parser.parse(exprString); } catch (ExpressionValidationException e) { // surface arity message with function name and expected count }

Prevention

When it happens

Trigger: Calling a function whose implementation declares validationHelperCheckArgumentCount(args, N) with N>1 with any other argument count, e.g. a two-argument function called with one or three arguments.

Common situations: Misremembering a function signature, SQL-to-native-expr translation bugs, generated expressions where an optional operand was omitted.

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/7ed807361a2ea1e5. Report an issue: GitHub.