{"record":{"id":"60a9722535a20e47","repo":"apache/druid","slug":"expected-a-number-but-received-s-of-type-s","errorCode":null,"errorMessage":"Expected a Number, but received [%s] of type [%s]","messagePattern":"Expected a Number, but received \\[(.+?)\\] of type \\[(.+?)\\]","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"extensions-contrib/spectator-histogram/src/main/java/org/apache/druid/spectator/histogram/SpectatorHistogramAggregateHelper.java","lineNumber":53,"sourceCode":"\n  public void init(ByteBuffer buffer, int position)\n  {\n    SpectatorHistogram emptyCounts = new SpectatorHistogram();\n    addToCache(buffer, position, emptyCounts);\n  }\n\n  /**\n   * Merge obj ({@link SpectatorHistogram} or {@link Number}) into {@param current}.\n   */\n  public void merge(SpectatorHistogram current, Object obj)\n  {\n    if (obj instanceof SpectatorHistogram) {\n      SpectatorHistogram other = (SpectatorHistogram) obj;\n      current.merge(other);\n    } else if (obj instanceof Number) {\n      current.insert((Number) obj);\n    } else {\n      throw new IAE(\n          \"Expected a Number, but received [%s] of type [%s]\",\n          obj,\n          obj.getClass()\n      );\n    }\n  }\n\n  /**\n   * Merge {@param value} into {@param current}.\n   */\n  public void merge(SpectatorHistogram current, long value)\n  {\n    current.insert(value);\n  }\n\n  /**\n   * Fetches the SpectatorHistogram at the given buffer/position pair in the cache\n   */","sourceCodeStart":35,"sourceCodeEnd":71,"githubUrl":"https://github.com/apache/druid/blob/9b90983fd291f26935af934383ce360473179e4d/extensions-contrib/spectator-histogram/src/main/java/org/apache/druid/spectator/histogram/SpectatorHistogramAggregateHelper.java#L35-L71","documentation":"SpectatorHistogramAggregateHelper.merge combines the aggregator's current histogram with either another SpectatorHistogram or a single Number sample. Any other object type is unsupported and throws IAE naming the received value and its class. It is the helper's type contract for what can be folded into the aggregation.","triggerScenarios":"A column or post-aggregator input yields a non-numeric, non-histogram object (e.g. String, Map, null-wrapped complex value) and the helper's merge(obj) is invoked on it during aggregation.","commonSituations":"Pointing the aggregator at a column of the wrong type (strings/dimensions instead of numeric metrics or histogram sketches); a serializer delivering a different sketch class; upstream filters or transforms emitting complex objects into the metric slot.","solutions":["Verify the input column is numeric or of the spectator-histogram sketch type before aggregating.","Cast or convert the object to Number / SpectatorHistogram before calling merge, or reject the row upstream.","Check for serialization mismatches between writer and reader versions of the extension."],"exampleFix":"// before\nhelper.merge(current, row.getRaw(\"metric\")); // may be a String\n// after\nObject v = row.getRaw(\"metric\");\nif (v instanceof SpectatorHistogram || v instanceof Number) {\n  helper.merge(current, v);\n} else {\n  throw new IAE(\"Unsupported metric type: \" + v.getClass());\n}","handlingStrategy":"validation","validationCode":"static boolean isMergeable(Object o) {\n  return o instanceof SpectatorHistogram || o instanceof Number;\n}","typeGuard":"static boolean isHistogramOrNumber(Object o) {\n  return o instanceof SpectatorHistogram || o instanceof Number;\n}","tryCatchPattern":"try {\n  helper.merge(current, obj);\n} catch (IllegalArgumentException e) {\n  if (e.getMessage().startsWith(\"Expected a Number\")) {\n    log.warn(\"Skipping non-numeric input of type %s\", obj.getClass());\n    return;\n  }\n  throw e;\n}","preventionTips":["Bind the aggregator only to numeric metric columns or spectator-histogram sketch columns.","Sanitize/transform rows so complex values never reach the metric slot.","Add a pre-merge instanceof check in custom helpers."],"tags":["illegal-argument","type-mismatch","aggregation"],"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"}