{"record":{"id":"f5207146b1bb0ba7","repo":"apache/druid","slug":"expected-key-s-to-be-in-float-format-but-got","errorCode":null,"errorMessage":"Expected key [%s] to be in float format, but got [%s]","messagePattern":"Expected key \\[(.+?)\\] to be in float format, but got \\[(.+?)\\]","errorType":"validation","errorClass":"BadQueryContextException","httpStatus":null,"severity":"error","filePath":"processing/src/main/java/org/apache/druid/query/QueryContexts.java","lineNumber":456,"sourceCode":"    return val == null ? defaultValue : val;\n  }\n\n  /**\n   * Get the value of a context value as an {@code Float}. The value is expected\n   * to be {@code null}, a string or a {@code Number} object.\n   */\n  public static Float getAsFloat(final String key, final Object value)\n  {\n    if (value == null) {\n      return null;\n    } else if (value instanceof Number) {\n      return ((Number) value).floatValue();\n    } else if (value instanceof String) {\n      try {\n        return Float.parseFloat((String) value);\n      }\n      catch (NumberFormatException ignored) {\n        throw badValueException(key, \"in float format\", value);\n      }\n    }\n    throw badTypeException(key, \"a Float\", value);\n  }\n\n  public static float getAsFloat(\n      final String key,\n      final Object value,\n      final float defaultValue\n  )\n  {\n    Float val = getAsFloat(key, value);\n    return val == null ? defaultValue : val;\n  }\n\n  public static HumanReadableBytes getAsHumanReadableBytes(\n      final String key,\n      final Object value,","sourceCodeStart":438,"sourceCodeEnd":474,"githubUrl":"https://github.com/apache/druid/blob/9b90983fd291f26935af934383ce360473179e4d/processing/src/main/java/org/apache/druid/query/QueryContexts.java#L438-L474","documentation":"QueryContexts.getAsFloat(key, value) throws badValueException with this message when the context value is a String that Float.parseFloat cannot parse. Unlike the int/long getters there is no BigDecimal fallback: any non-float string (including \"1,5\", \"12.5f\", \"\", or values with units) is rejected. The error names the key and the offending string.","triggerScenarios":"Calling QueryContexts.getAsFloat(key, value) or query.getContextValue(key, float default) with a String context value such as \"abc\", \"12.5%\", \"1,5\", or an empty string where a float is required.","commonSituations":"Percentage or ratio parameters supplied with a '%' sign or comma decimal separator; locale-formatted decimals; fractional thresholds written with units (\"0.5x\").","solutions":["Send the value as a JSON number or a canonical float string: {\"key\": 0.75} or \"0.75\".","Use '.' as the decimal separator and strip '%' and other decorations at the client.","If an integer is what the engine actually needs, use an integer-typed context key instead.","Catch the exception around getContextValue and fall back to the default."],"exampleFix":"// before\n{\"partitioningThreshold\": \"50%\"}  // -> IAE\n// after\n{\"partitioningThreshold\": 0.5}","handlingStrategy":"validation","validationCode":"Object v = context.get(key);\nif (v instanceof String) {\n  try { Float.parseFloat((String) v); }\n  catch (NumberFormatException e) { throw new IllegalArgumentException(\"Context key '\" + key + \"' must be a float, got: \" + v); }\n}","typeGuard":"boolean isParsableFloat(Object v) {\n  if (!(v instanceof String)) return v instanceof Number || v == null;\n  try { Float.parseFloat((String) v); return true; } catch (NumberFormatException e) { return false; }\n}","tryCatchPattern":"try {\n  return query.getContextValue(key, defaultFloat);\n} catch (IllegalArgumentException e) {\n  LOG.warn(e, \"Non-float value for context key [%s], using default\", key);\n  return defaultFloat;\n}","preventionTips":["Use '.' as the decimal separator; strip '%' and units from ratio strings.","Prefer JSON numbers over strings for float context values.","Note there is no BigDecimal fallback for floats — strings must parse exactly with Float.parseFloat."],"tags":["druid","query-context","float","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"}