{"record":{"id":"ea87ddc63ed99346","repo":"apache/druid","slug":"second-argument-should-be-a-long-but-got-s-instea","errorCode":null,"errorMessage":"second argument should be a LONG but got %s instead","messagePattern":"second argument should be a LONG but got (.+?) instead","errorType":"validation","errorClass":"ExpressionValidationException","httpStatus":400,"severity":"error","filePath":"processing/src/main/java/org/apache/druid/math/expr/Function.java","lineNumber":1524,"sourceCode":"      ExprEval value1 = args.get(0).eval(bindings);\n\n      if (value1.isNumericNull()) {\n        return ExprEval.ofLong(null);\n      }\n\n      if (!value1.type().anyOf(ExprType.LONG, ExprType.DOUBLE)) {\n        throw validationFailed(\n            \"first argument should be a LONG or DOUBLE but got %s instead\",\n            value1.type()\n        );\n      }\n\n      if (args.size() == 1) {\n        return eval(value1);\n      } else {\n        ExprEval value2 = args.get(1).eval(bindings);\n        if (!value2.type().is(ExprType.LONG)) {\n          throw validationFailed(\n              \"second argument should be a LONG but got %s instead\",\n              value2.type()\n          );\n        }\n        return eval(value1, value2.asInt());\n      }\n    }\n\n    @Override\n    public void validateArguments(List<Expr> args)\n    {\n      validationHelperCheckAnyOfArgumentCount(args, 1, 2);\n    }\n\n    @Nullable\n    @Override\n    public ExpressionType getOutputType(Expr.InputBindingInspector inspector, List<Expr> args)\n    {","sourceCodeStart":1506,"sourceCodeEnd":1542,"githubUrl":"https://github.com/apache/druid/blob/9b90983fd291f26935af934383ce360473179e4d/processing/src/main/java/org/apache/druid/math/expr/Function.java#L1506-L1542","documentation":"The same function family requires the second (optional) argument to be a LONG. If args[1] evaluates to STRING, DOUBLE, or another non-LONG type, the function throws this validation error instead of coercing.","triggerScenarios":"Passing a double literal or string as the second argument, e.g. FUNC(x, 2.0) or FUNC(x, '2'); passing a double-typed column as the second operand.","commonSituations":"Numeric literals written as 2.0 instead of 2; columns inferred as DOUBLE; quoting numbers in expression strings making them strings.","solutions":["Change the second argument to an integer literal: FUNC(x, 2) not FUNC(x, 2.0)","Cast explicitly: CAST(col AS BIGINT) when the operand is DOUBLE or STRING","Remove surrounding quotes so the argument is not parsed as a string","Check EXPLAIN PLAN for the second operand's inferred type"],"exampleFix":"// before: FUNC(x, 2.5) -> throws\n// after: FUNC(x, CAST(2.5 AS BIGINT)) or FUNC(x, 2)","handlingStrategy":"validation","validationCode":"ExprEval<?> v2 = args.get(1).eval(bindings);\nif (!v2.type().is(ExprType.LONG)) {\n  throw new IllegalArgumentException(\"second arg must be LONG, got \" + v2.type());\n}","typeGuard":"static boolean isSecondArgLong(ExprEval<?> e) {\n  return e.type().is(ExprType.LONG);\n}","tryCatchPattern":null,"preventionTips":["Write integer literals without decimals (2 not 2.0)","CAST DOUBLE/STRING operands to BIGINT","Avoid quoting numeric arguments in expression strings"],"tags":["druid","expressions","argument-type"],"backgroundTag":"type-mismatch","analyzedSha":"9b90983fd291f26935af934383ce360473179e4d","analyzedAt":"2026-09-07T13:32:30.957Z","contentChangedAt":"2026-09-07T13:32:30.957Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}