apache/druid · error · DruidException
must have at least two arguments
Error message
must have at least two arguments
What it means
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.
Source
Thrown at processing/src/main/java/org/apache/druid/query/expression/NestedDataExpressions.java:129
@Inject
public JsonMergeExprMacro(
@Json ObjectMapper jsonMapper
)
{
this.jsonMapper = jsonMapper;
}
@Override
public String name()
{
return NAME;
}
@Override
public Expr apply(List<Expr> args)
{
if (args.size() < 2) {
throw validationFailed("must have at least two arguments");
}
final class ParseJsonExpr extends ExprMacroTable.BaseScalarMacroFunctionExpr
{
public ParseJsonExpr(List<Expr> args)
{
super(JsonMergeExprMacro.this, args);
}
@Override
public ExprEval<?> eval(ObjectBinding bindings)
{
final Object retVal = getArgAsObject(args.get(0).eval(bindings), true);
if (retVal == null) {
// If any argument is null, the return of the entire function is null.
return ExprEval.ofComplex(ExpressionType.NESTED_DATA, null);
}View on GitHub (pinned to 9b90983fd2)
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
Example fix
// before Expr expr = macro.apply(Collections.singletonList(jsonColumnExpr)); // after Expr expr = macro.apply(Arrays.asList(jsonColumnExpr, pathExpr));
Defensive patterns
Strategy: validation
Validate before calling
if (args == null || args.size() < 2) {
throw new IllegalArgumentException("expression macro requires at least two arguments");
} Try / catch
try {
Expr expr = macro.apply(args);
} catch (ExpressionValidationException e) {
log.error("Invalid expression arity: %s", e.getMessage());
} Prevention
- Count arguments against the macro signature before calling apply
- Validate expression strings with Parser.parse before submission
- Cover macro arity in unit tests
When it happens
Trigger: 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.
Common situations: 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.
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
- Function[%s] %s
- must have an even number of arguments
- Expression %s has non-constant inputs.
- Failed to parse expression: %s
- Unable to transform apply function:[%s]
AI-assisted analysis of apache/druid@9b90983fd2 (2026-09-07).
Data as JSON: /api/errors/b738c4f44b4180fe.
Report an issue: GitHub.