apache/druid · error · DruidException

requires %s arguments

Error message

requires %s arguments

What it means

Generic argument-count guard used by Druid's named expression functions: validationHelperCheckAnyOfArgumentCount fires when a function that accepts several fixed possible argument counts (e.g. 1 or 2) is called with a count matching none of them. It is a sentinel message from the shared validation helper, listing the acceptable counts joined by 'or'; correct the function call so its argument count matches one of the allowed options.

Source

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

    if (args.size() < start || args.size() > end) {
      throw validationFailed("requires %d to %d arguments", start, end);
    }
  }

  /**
   * Helper method for implementors performing validation to check if argument count is any of specified counts
   */
  default void validationHelperCheckAnyOfArgumentCount(List<Expr> args, int... counts)
  {
    boolean satisfied = false;
    for (int count : counts) {
      if (args.size() == count) {
        satisfied = true;
        break;
      }
    }
    if (!satisfied) {
      throw validationFailed(
          "requires %s arguments",
          Strings.join(" or ", () -> Arrays.stream(counts).mapToObj(String::valueOf).iterator())
      );
    }
  }

  /**
   * Helper method for implementors performing validation to check that an argument is a literal
   */
  default void validationHelperCheckArgIsLiteral(Expr arg, String argName)
  {
    if (!arg.isLiteral()) {
      throw validationFailed(
          "%s argument must be a literal",
          argName
      );
    }
  }

View on GitHub (pinned to 9b90983fd2)

Solutions

  1. Pass exactly one of the accepted argument counts listed in the message
  2. Check the function source to see the accepted counts
  3. Use the matching overload or pad/trim arguments accordingly

Example fix

// before
x = timestamp_shift(d, p)  // accepts 3 or 4
// after
x = timestamp_shift(d, p, 'UTC')
Defensive patterns

Strategy: validation

Validate before calling

java.util.Arrays.sort(allowed); if (java.util.Arrays.binarySearch(allowed, args.size()) < 0) { throw new IllegalArgumentException(funcName + " accepts arguments counts " + java.util.Arrays.toString(allowed) + ", got " + args.size()); }

Type guard

boolean arityIsAnyOf(List<Expr> args, int... counts) { for (int c : counts) { if (args.size() == c) return true; } return false; }

Try / catch

try { expr = Parser.parse(exprString); } catch (ExpressionValidationException e) { // map to the closest supported overload }

Prevention

When it happens

Trigger: Calling a function declared with validationHelperCheckAnyOfArgumentCount(args, 1, 3) (say) with 2 arguments.

Common situations: Overload-style native functions where SQL translation picked the wrong overload shape, hand-written expressions guessing arity.

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