{"record":{"id":"21f6a4dd5e973fd8","repo":"apache/druid","slug":"expected-key-s-to-be-a-human-readable-number-b","errorCode":null,"errorMessage":"Expected key [%s] to be a human readable number, but got [%s]","messagePattern":"Expected key \\[(.+?)\\] to be a human readable number, but got \\[(.+?)\\]","errorType":"validation","errorClass":"BadQueryContextException","httpStatus":null,"severity":"error","filePath":"processing/src/main/java/org/apache/druid/query/QueryContexts.java","lineNumber":487,"sourceCode":"    return val == null ? defaultValue : val;\n  }\n\n  public static HumanReadableBytes getAsHumanReadableBytes(\n      final String key,\n      final Object value,\n      final HumanReadableBytes defaultValue\n  )\n  {\n    if (null == value) {\n      return defaultValue;\n    } else if (value instanceof Number) {\n      return HumanReadableBytes.valueOf(Numbers.parseLong(value));\n    } else if (value instanceof String) {\n      try {\n        return HumanReadableBytes.valueOf(HumanReadableBytes.parse((String) value));\n      }\n      catch (IAE e) {\n        throw badValueException(key, \"a human readable number\", value);\n      }\n    }\n\n    throw badTypeException(key, \"a human readable number\", value);\n  }\n\n  /**\n   * Insert, update or remove a single key to produce an overridden context.\n   * Leaves the original context unchanged.\n   *\n   * @param context context to override\n   * @param key     key to insert, update or remove\n   * @param value   if {@code null}, remove the key. Otherwise, insert or replace\n   *                the key.\n   * @return a new context map\n   */\n  public static Map<String, Object> override(\n      final Map<String, Object> context,","sourceCodeStart":469,"sourceCodeEnd":505,"githubUrl":"https://github.com/apache/druid/blob/9b90983fd291f26935af934383ce360473179e4d/processing/src/main/java/org/apache/druid/query/QueryContexts.java#L469-L505","documentation":"QueryContexts.getAsHumanReadableBytes(key, value) throws badValueException with this message when the context value is a String that HumanReadableBytes.parse cannot interpret (e.g. not a number and not a valid size expression like \"200GB\"). The parse failure is caught and rethrown as this error naming the key and raw value. Number-typed values are accepted directly via Numbers.parseLong, so this path only triggers for malformed strings.","triggerScenarios":"Calling QueryContexts.getAsHumanReadableBytes(key, value) or query.getContextValue(key, HumanReadableBytes default) with a String such as \"abc\", \"100 MBs\", \"1,000KB\", or any string not matching HumanReadableBytes' supported format (plain long or <number><unit> like KB/MB/GB/TB, optionally KiB/MiB style).","commonSituations":"Users write byte sizes with unsupported unit spellings (\"mbit\", \"MBs\"), thousands separators, or extra spaces; copy-pasted configs with typos in unit names; values like \"unlimited\" or \"auto\" where only numeric byte expressions are supported.","solutions":["Rewrite the value in a supported form: a plain byte count (\"838860800\") or a valid unit expression (\"800MB\", \"1GB\", \"2KiB\").","Send it as a JSON number if the value is a raw byte count.","Check the HumanReadableBytes documentation for the accepted unit suffixes and remove separators/extra text.","Catch the exception around getContextValue and fall back to the default HumanReadableBytes."],"exampleFix":"// before\n{\"maxScatterGatherBytes\": \"800 MBs\"}  // unsupported unit -> IAE\n// after\n{\"maxScatterGatherBytes\": \"800MB\"}","handlingStrategy":"validation","validationCode":"Object v = context.get(key);\nif (v instanceof String) {\n  try { org.apache.druid.java.util.common.HumanReadableBytes.parse((String) v); }\n  catch (IllegalArgumentException e) { throw new IllegalArgumentException(\"Context key '\" + key + \"' must be a byte size like '800MB', got: \" + v); }\n}","typeGuard":"boolean isParsableBytes(Object v) {\n  if (!(v instanceof String)) return v instanceof Number || v == null;\n  try { org.apache.druid.java.util.common.HumanReadableBytes.parse((String) v); return true; } catch (IllegalArgumentException e) { return false; }\n}","tryCatchPattern":"try {\n  return query.getContextValue(key, HumanReadableBytes.ZERO);\n} catch (IllegalArgumentException e) {\n  LOG.warn(e, \"Invalid byte-size string for context key [%s], using default\", key);\n  return defaultBytes;\n}","preventionTips":["Use exact supported unit suffixes (KB/MB/GB/TB, or KiB/MiB binary forms) with no spaces or separators.","Prefer JSON numbers for raw byte counts.","Pre-validate size strings with HumanReadableBytes.parse in a dry run before submitting queries."],"tags":["druid","query-context","human-readable-bytes","parse-error"],"backgroundTag":"invalid-argument-format","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"}