{"record":{"id":"48246c96724b4c2f","repo":"apache/druid","slug":"first-argument-should-be-a-long-or-double-but-got","errorCode":null,"errorMessage":"first argument should be a LONG or DOUBLE but got %s instead","messagePattern":"first argument should be a LONG or DOUBLE but got (.+?) instead","errorType":"validation","errorClass":"ExpressionValidationException","httpStatus":400,"severity":"error","filePath":"processing/src/main/java/org/apache/druid/math/expr/Function.java","lineNumber":1513,"sourceCode":"    public static final String NAME = \"round\";\n\n    @Override\n    public String name()\n    {\n      return NAME;\n    }\n\n    @Override\n    public ExprEval apply(List<Expr> args, Expr.ObjectBinding bindings)\n    {\n      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    }","sourceCodeStart":1495,"sourceCodeEnd":1531,"githubUrl":"https://github.com/apache/druid/blob/9b90983fd291f26935af934383ce360473179e4d/processing/src/main/java/org/apache/druid/math/expr/Function.java#L1495-L1531","documentation":"This two-argument math expression function requires its first argument to be numeric (LONG or DOUBLE). If args[0] evaluates to any other expression type (STRING, complex, array), validation fails with this message naming the actual type. Null is accepted (returns NULL).","triggerScenarios":"Evaluating the function where args[0] resolves to a non-numeric type, e.g. a string dimension or nested-data column.","commonSituations":"Using the function on a VARCHAR column without a cast; ingestion-spec expressions referencing the wrong input column; schema changes turning a numeric column into string.","solutions":["Wrap the first argument in CAST(... AS BIGINT) or CAST(... AS DOUBLE)","Verify the operand column's type with EXPLAIN PLAN and correct the column reference","Fix the ingestion/rollup spec so the source column is numeric","Handle string inputs explicitly; only nulls are tolerated without a cast"],"exampleFix":"// before: FUNC(stringCol, 2) -> throws\n// after: FUNC(CAST(stringCol AS DOUBLE), 2)","handlingStrategy":"validation","validationCode":"ExpressionType t = args.get(0).eval(bindings).type();\nif (!(t.anyOf(ExprType.LONG, ExprType.DOUBLE))) {\n  throw new IllegalArgumentException(\"first arg must be LONG/DOUBLE, got \" + t);\n}","typeGuard":"static boolean isFirstArgNumeric(ExprEval<?> e) {\n  return e.type().anyOf(ExprType.LONG, ExprType.DOUBLE);\n}","tryCatchPattern":null,"preventionTips":["CAST non-numeric first arguments explicitly","Confirm column types before writing expressions","Null is accepted; strings are not — handle strings separately"],"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"}