{"record":{"id":"77b033ddd14fbce2","repo":"apache/druid","slug":"expected-key-s-to-be-in-integer-format-but-got","errorCode":null,"errorMessage":"Expected key [%s] to be in integer format, but got [%s]","messagePattern":"Expected key \\[(.+?)\\] to be in integer format, but got \\[(.+?)\\]","errorType":"validation","errorClass":"BadQueryContextException","httpStatus":null,"severity":"error","filePath":"processing/src/main/java/org/apache/druid/query/QueryContexts.java","lineNumber":378,"sourceCode":"  {\n    if (value == null) {\n      return null;\n    } else if (value instanceof Number) {\n      return ((Number) value).intValue();\n    } else if (value instanceof String) {\n      try {\n        return Numbers.parseInt(value);\n      }\n      catch (NumberFormatException ignored) {\n\n        // Attempt to handle trivial decimal values: 12.00, etc.\n        // This mimics how Jackson will convert \"12.00\" to a Integer on request.\n        try {\n          return new BigDecimal((String) value).intValueExact();\n        }\n        catch (Exception nfe) {\n          // That didn't work either. Give up.\n          throw badValueException(key, \"in integer format\", value);\n        }\n      }\n    }\n\n    throw badTypeException(key, \"an Integer\", value);\n  }\n\n  /**\n   * Get the value of a context value as an {@code int}. The value is expected\n   * to be {@code null}, a string or a {@code Number} object.\n   */\n  public static int getAsInt(\n      final String key,\n      final Object value,\n      final int defaultValue\n  )\n  {\n    Integer val = getAsInt(key, value);","sourceCodeStart":360,"sourceCodeEnd":396,"githubUrl":"https://github.com/apache/druid/blob/9b90983fd291f26935af934383ce360473179e4d/processing/src/main/java/org/apache/druid/query/QueryContexts.java#L360-L396","documentation":"QueryContexts.getAsInt(key, value) throws badValueException with this message when the context value is a String that cannot be parsed as an integer. The getter first tries Numbers.parseInt and then a BigDecimal.intValueExact() (to accept trivial decimals like \"12.00\", mimicking Jackson); if both fail it gives up with this error. The key and the raw string value are reported.","triggerScenarios":"Calling QueryContexts.getAsInt(key, value) (directly or via query.getContextValue(key, int default)) with a String value such as \"12.5\", \"abc\", \"1e3\", \"\" or a value with whitespace/units that is not exactly representable as an int.","commonSituations":"Users put human-formatted values like \"100MB\", \"12.5\", or \"1,000\" into numeric context keys (e.g. timeout, maxMergingPullThreads); locale-formatted numbers with thousands separators; fractional values supplied where the engine requires an integer.","solutions":["Correct the context value to a plain integer string or JSON number: {\"key\": 100} or {\"key\": \"100\"}.","If a fractional value is intended, round it at the client (Math.round) or use a float-typed context key instead.","Strip units/separators before putting the value into the context.","Catch the exception around getContextValue and fall back to the documented default."],"exampleFix":"// before\n{\"timeout\": \"30s\"}        // units not parsed -> IAE\n// after\n{\"timeout\": 30000}         // milliseconds as a number\n// or\n{\"timeout\": \"30000\"}","handlingStrategy":"validation","validationCode":"Object v = context.get(key);\nif (v instanceof String) {\n  try { new java.math.BigDecimal((String) v).intValueExact(); }\n  catch (Exception e) { throw new IllegalArgumentException(\"Context key '\" + key + \"' must be an integer, got: \" + v); }\n}","typeGuard":"boolean isParsableInt(Object v) {\n  if (!(v instanceof String)) return v instanceof Number || v == null;\n  try { new java.math.BigDecimal((String) v).intValueExact(); return true; } catch (Exception e) { return false; }\n}","tryCatchPattern":"try {\n  return query.getContextValue(key, defaultInt);\n} catch (IllegalArgumentException e) {\n  LOG.warn(e, \"Non-integer value for context key [%s], using default\", key);\n  return defaultInt;\n}","preventionTips":["Send numeric context values as JSON numbers, not formatted strings.","Strip units, separators, and whitespace before putting numeric values into the context.","Remember fractional strings like \"12.5\" fail even though \"12.00\" passes (intValueExact)."],"tags":["druid","query-context","integer","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"}