{"record":{"id":"e579e7e82c7d721f","repo":"apache/druid","slug":"needs-a-long-as-its-second-argument-but-got-s-ins","errorCode":null,"errorMessage":"needs a LONG as its second argument but got %s instead","messagePattern":"needs a LONG as its second argument but got (.+?) instead","errorType":"validation","errorClass":"ExpressionValidationException","httpStatus":400,"severity":"error","filePath":"processing/src/main/java/org/apache/druid/math/expr/Function.java","lineNumber":4693,"sourceCode":"       */\n      if (valueParam.value() != null && !valueParam.type().anyOf(ExprType.LONG, ExprType.DOUBLE)) {\n        throw validationFailed(\n            \"needs a number as its first argument but got %s instead\",\n            valueParam.type()\n        );\n      }\n\n      /**\n       * By default, precision is 2\n       */\n      long precision = 2;\n      if (args.size() > 1) {\n        ExprEval precisionParam = args.get(1).eval(bindings);\n        if (precisionParam.value() == null) {\n          throw validationFailed(\"needs a LONG as its second argument but got null\");\n        }\n        if (!precisionParam.type().is(ExprType.LONG)) {\n          throw validationFailed(\"needs a LONG as its second argument but got %s instead\", precisionParam.type());\n        }\n        precision = precisionParam.asLong();\n        if (precision < 0 || precision > 3) {\n          throw validationFailed(\"given precision[%d] must be in the range of [0,3]\", precision);\n        }\n      }\n\n      return ExprEval.ofString(HumanReadableBytes.format(valueParam.asLong(), precision, this.getUnitSystem()));\n    }\n\n    @Override\n    public void validateArguments(List<Expr> args)\n    {\n      validationHelperCheckAnyOfArgumentCount(args, 1, 2);\n    }\n\n    @Nullable\n    @Override","sourceCodeStart":4675,"sourceCodeEnd":4711,"githubUrl":"https://github.com/apache/druid/blob/9b90983fd291f26935af934383ce360473179e4d/processing/src/main/java/org/apache/druid/math/expr/Function.java#L4675-L4711","documentation":"Thrown when HUMAN_READABLE_BYTES_FORMAT's optional second argument (precision) is present but not of type LONG. Precision must be an integer in [0,3]; STRING, DOUBLE, or other types are rejected with this message.","triggerScenarios":"Calling human_readable_bytes_format(value, '2') with a string precision, or a DOUBLE column/literal like 2.0 as the second argument.","commonSituations":"Clients sending precision as a JSON string; columns typed as DOUBLE or VARCHAR in the datasource; confusion with languages where 2.0 is a valid int.","solutions":["Pass an integer literal: human_readable_bytes_format(b, 2).","Cast the argument: CAST(prec AS BIGINT).","Change the datasource/schema so the precision column is BIGINT.","Remove the argument to accept the default precision of 2."],"exampleFix":"// before\nhuman_readable_bytes_format(b, '2')\n// after\nhuman_readable_bytes_format(b, 2)","handlingStrategy":"type-guard","validationCode":"CAST(precision_expr AS BIGINT) -- ensure integer type","typeGuard":"if (!(p instanceof Integer || p instanceof Long)) throw new IllegalArgumentException(\"precision must be a LONG\");","tryCatchPattern":null,"preventionTips":["Pass precision as an integer literal (2), not '2' or 2.0","Keep precision columns typed BIGINT in the schema","Beware JSON clients sending numbers as strings"],"tags":["druid","expressions","type-mismatch","validation"],"backgroundTag":"type-mismatch","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"}