{"record":{"id":"e56e8de4e239afe0","repo":"apache/druid","slug":"given-precision-d-must-be-in-the-range-of-0-3","errorCode":null,"errorMessage":"given precision[%d] must be in the range of [0,3]","messagePattern":"given precision\\[(.+?)\\] must be in the range of \\[0,3\\]","errorType":"validation","errorClass":"ExpressionValidationException","httpStatus":400,"severity":"error","filePath":"processing/src/main/java/org/apache/druid/math/expr/Function.java","lineNumber":4697,"sourceCode":"            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\n    public ExpressionType getOutputType(Expr.InputBindingInspector inputTypes, List<Expr> args)\n    {\n      return ExpressionType.STRING;\n    }","sourceCodeStart":4679,"sourceCodeEnd":4715,"githubUrl":"https://github.com/apache/druid/blob/9b90983fd291f26935af934383ce360473179e4d/processing/src/main/java/org/apache/druid/math/expr/Function.java#L4679-L4715","documentation":"Thrown when HUMAN_READABLE_BYTES_FORMAT receives a precision LONG outside the supported range. The function formats byte counts with decimal/binary unit systems and only supports 0 to 3 fractional digits, so any precision < 0 or > 3 is rejected.","triggerScenarios":"Calling human_readable_bytes_format(b, 5) or human_readable_bytes_format(b, -1), or a computed precision expression that evaluates outside [0,3].","commonSituations":"Porting code where other formatting APIs accept arbitrary precision; computed precision columns producing unexpected values; users expecting 4+ decimal places.","solutions":["Clamp the precision to the supported range, e.g. GREATEST(0, LEAST(3, prec)).","Use a precision of 0, 1, 2, or 3 — 2 is the default.","Round/format to more digits in SQL after the function call if you need finer display.","Validate precision inputs at the application layer before building the query."],"exampleFix":"// before\nhuman_readable_bytes_format(b, 5)\n// after\nhuman_readable_bytes_format(b, 3)","handlingStrategy":"validation","validationCode":"GREATEST(0, LEAST(3, precision_expr)) -- clamp before use","typeGuard":"if (p < 0 || p > 3) throw new IllegalArgumentException(\"precision must be in [0,3]\");","tryCatchPattern":null,"preventionTips":["Clamp computed precision values to [0,3]","Validate precision at the application layer","Remember 2 is the default if you need no customization"],"tags":["druid","expressions","validation","argument-out-of-range"],"backgroundTag":"value-out-of-range","analyzedSha":"9b90983fd291f26935af934383ce360473179e4d","analyzedAt":"2026-09-07T13:32:30.957Z","contentChangedAt":"2026-09-07T13:32:30.957Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}