{"record":{"id":"7ed807361a2ea1e5","repo":"apache/druid","slug":"requires-d-arguments","errorCode":null,"errorMessage":"requires %d arguments","messagePattern":"requires (.+?) arguments","errorType":"validation","errorClass":"ExpressionValidationException","httpStatus":400,"severity":"error","filePath":"processing/src/main/java/org/apache/druid/math/expr/NamedFunction.java","lineNumber":75,"sourceCode":"  }\n\n  default ExpressionProcessingException processingFailed(Throwable e, String reasonFormat, Object... args)\n  {\n    throw new ExpressionProcessingException(this, e, reasonFormat, args);\n  }\n\n  /**\n   * Helper method for implementors performing validation to check if the argument count is expected\n   */\n  default void validationHelperCheckArgumentCount(List<Expr> args, int count)\n  {\n    if (args.size() != count) {\n      if (count == 0) {\n        throw validationFailed(\"does not accept arguments\");\n      } else if (count == 1) {\n        throw validationFailed(\"requires 1 argument\");\n      }\n      throw validationFailed(\"requires %d arguments\", count);\n    }\n  }\n\n  /**\n   * Helper method for implementors performing validation to check if there are at least as many arguments as specified\n   */\n  default void validationHelperCheckMinArgumentCount(List<Expr> args, int count)\n  {\n    if (args.size() < count) {\n      if (count == 1) {\n        throw validationFailed(\"requires at least 1 argument\");\n      }\n      throw validationFailed(\"requires at least %d arguments\", count);\n    }\n  }\n\n  default void validationHelperCheckArgumentRange(List<Expr> args, int start, int end)\n  {","sourceCodeStart":57,"sourceCodeEnd":93,"githubUrl":"https://github.com/apache/druid/blob/9b90983fd291f26935af934383ce360473179e4d/processing/src/main/java/org/apache/druid/math/expr/NamedFunction.java#L57-L93","documentation":"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.","triggerScenarios":"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.","commonSituations":"Misremembering a function signature, SQL-to-native-expr translation bugs, generated expressions where an optional operand was omitted.","solutions":["Supply exactly N arguments as declared by the function","Read the function's validationHelperCheckArgumentCount call to learn N","Use validationHelperCheckArgumentRange/MinArgumentCount-style functions if variable arity is intended"],"exampleFix":"// before\nposition = locate(needle)  // requires 2\n// after\nposition = locate(needle, haystack)","handlingStrategy":"validation","validationCode":"if (args.size() != expectedCount) { throw new IllegalArgumentException(funcName + \" requires exactly \" + expectedCount + \" arguments, got \" + args.size()); }","typeGuard":"boolean hasExactArity(List<Expr> args, int n) { return args != null && args.size() == n; }","tryCatchPattern":"try { expr = Parser.parse(exprString); } catch (ExpressionValidationException e) { // surface arity message with function name and expected count }","preventionTips":["Keep a signature reference for multi-argument functions","Test generated expressions with known arity","Validate user-supplied expressions in a dry-run parse"],"tags":["expression","argument-count","validation"],"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-14T05:17:10.506Z"}