{"record":{"id":"b738c4f44b4180fe","repo":"apache/druid","slug":"must-have-at-least-two-arguments","errorCode":null,"errorMessage":"must have at least two arguments","messagePattern":"must have at least two arguments","errorType":"validation","errorClass":"DruidException","httpStatus":null,"severity":"error","filePath":"processing/src/main/java/org/apache/druid/query/expression/NestedDataExpressions.java","lineNumber":129,"sourceCode":"    @Inject\n    public JsonMergeExprMacro(\n        @Json ObjectMapper jsonMapper\n    )\n    {\n      this.jsonMapper = jsonMapper;\n    }\n\n    @Override\n    public String name()\n    {\n      return NAME;\n    }\n\n    @Override\n    public Expr apply(List<Expr> args)\n    {\n      if (args.size() < 2) {\n        throw validationFailed(\"must have at least two arguments\");\n      }\n\n      final class ParseJsonExpr extends ExprMacroTable.BaseScalarMacroFunctionExpr\n      {\n        public ParseJsonExpr(List<Expr> args)\n        {\n          super(JsonMergeExprMacro.this, args);\n        }\n\n        @Override\n        public ExprEval<?> eval(ObjectBinding bindings)\n        {\n          final Object retVal = getArgAsObject(args.get(0).eval(bindings), true);\n\n          if (retVal == null) {\n            // If any argument is null, the return of the entire function is null.\n            return ExprEval.ofComplex(ExpressionType.NESTED_DATA, null);\n          }","sourceCodeStart":111,"sourceCodeEnd":147,"githubUrl":"https://github.com/apache/druid/blob/9b90983fd291f26935af934383ce360473179e4d/processing/src/main/java/org/apache/druid/query/expression/NestedDataExpressions.java#L111-L147","documentation":"Druid's PARSE_JSON-like nested-data expression macro requires at least two arguments when applied. The macro's apply() validates arity up front and throws a validation failure (ExpressionValidationException) if fewer than two argument expressions are supplied, because the function cannot be meaningfully evaluated without them.","triggerScenarios":"Calling the expression macro (e.g. via JSON_QUERY/JSON_VALUE style native expressions or the ExprMacroTable) with 0 or 1 arguments, e.g. writing PARSE_JSON(x) when the macro's signature requires two, or an SQL planner lowering a function call that dropped an argument.","commonSituations":"Hand-written native JSON expressions with missing arguments; copy-pasted expression strings from older Druid versions where the macro accepted fewer args; programmatically building Expr argument lists and forgetting an element.","solutions":["Add the missing second argument to the expression call so it has at least two","Check the macro's documented signature in NestedDataExpressions and match argument count","If building args programmatically, assert args.size() >= 2 before calling Expr.apply"],"exampleFix":"// before\nExpr expr = macro.apply(Collections.singletonList(jsonColumnExpr));\n// after\nExpr expr = macro.apply(Arrays.asList(jsonColumnExpr, pathExpr));","handlingStrategy":"validation","validationCode":"if (args == null || args.size() < 2) {\n  throw new IllegalArgumentException(\"expression macro requires at least two arguments\");\n}","typeGuard":null,"tryCatchPattern":"try {\n  Expr expr = macro.apply(args);\n} catch (ExpressionValidationException e) {\n  log.error(\"Invalid expression arity: %s\", e.getMessage());\n}","preventionTips":["Count arguments against the macro signature before calling apply","Validate expression strings with Parser.parse before submission","Cover macro arity in unit tests"],"tags":["druid","expression","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-14T05:17:10.506Z"}