{"record":{"id":"9ea9313fa93ca761","repo":"apache/druid","slug":"expected-a-number-or-an-instance-of-ddsketch-but-9ea931","errorCode":null,"errorMessage":"Expected a number or an instance of DDSketch, but received [%s] of type [%s]","messagePattern":"Expected a number or an instance of DDSketch, but received \\[(.+?)\\] of type \\[(.+?)\\]","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"extensions-contrib/ddsketch/src/main/java/org/apache/druid/query/aggregation/ddsketch/DDSketchBufferAggregator.java","lineNumber":83,"sourceCode":"    mutationBuffer.position(position);\n    addToCache(buffer, position, sketch);\n  }\n\n  @Override\n  public void aggregate(ByteBuffer buffer, int position)\n  {\n    Object x = selector.getObject();\n    if (x == null) {\n      return;\n    }\n    DDSketch sketch = sketchCache.get(buffer).get(position);\n\n    if (x instanceof Number) {\n      sketch.accept(((Number) x).doubleValue());\n    } else if (x instanceof DDSketch) {\n      sketch.mergeWith((DDSketch) x);\n    } else {\n      throw new IAE(\n          \"Expected a number or an instance of DDSketch, but received [%s] of type [%s]\",\n          x,\n          x.getClass()\n      );\n    }\n  }\n\n  @Override\n  public Object get(final ByteBuffer buffer, final int position)\n  {\n    // sketchCache is an IdentityHashMap where the reference of buffer is used for equality checks.\n    // So the returned object isn't impacted by the changes in the buffer object made by concurrent threads.\n    DDSketch obj = sketchCache.get(buffer).get(position);\n    return obj;\n  }\n\n  @Override\n  public float getFloat(final ByteBuffer buffer, final int position)","sourceCodeStart":65,"sourceCodeEnd":101,"githubUrl":"https://github.com/apache/druid/blob/9b90983fd291f26935af934383ce360473179e4d/extensions-contrib/ddsketch/src/main/java/org/apache/druid/query/aggregation/ddsketch/DDSketchBufferAggregator.java#L65-L101","documentation":"DDSketchBufferAggregator.aggregate() only accepts Number or DDSketch inputs for the off-heap aggregation path; any other object type throws this IAE. It mirrors the non-buffer aggregator and signals the input selector produced an unexpected type during query execution.","triggerScenarios":"Aggregating a string or complex non-sketch column with the ddsketch aggregator when the buffer-based execution path is used, or feeding a wrong-typed post-aggregator result into a second ddsketch aggregation.","commonSituations":"fieldName pointing at a dimension/string metric, array or nested values, or mixing sketch types produced by other aggregators (e.g. datasketches quantiles) with ddsketch.","solutions":["Ensure the input field is numeric or a DDSketch object; fix the fieldName/column type.","Insert an expression aggregator that casts to double before the ddsketch aggregation.","Use ddsketch-produced sketches only; do not merge sketches from other libraries.","Validate column types via the segment metadata query before adding the aggregation."],"exampleFix":"// before\n{\"type\": \"ddsketch\", \"name\": \"sk\", \"fieldName\": \"eventValue\"} // eventValue is VARCHAR\n// after\n{\"type\": \"expression\", \"name\": \"valueNum\", \"expression\": \"CAST(\\\"eventValue\\\" AS DOUBLE)\", \"outputType\": \"DOUBLE\"} then ddsketch on valueNum","handlingStrategy":"type-guard","validationCode":"// before query: run segment metadata query to confirm the field is numeric or COMPLEX<ddsketch>","typeGuard":"Object x = selector.getObject();\nif (!(x instanceof Number) && !(x instanceof DDSketch)) {\n  log.warn(\"Ignoring non-numeric ddsketch input: %s\", x);\n  return;\n}","tryCatchPattern":"try {\n  agg.aggregate(x);\n} catch (IllegalArgumentException e) {\n  log.warn(e, \"Bad ddsketch input type, dropping value\");\n}","preventionTips":["Validate input column types during ingestion (make them DOUBLE or sketch-typed).","Avoid pointing ddsketch at string/array dimensions.","Keep sketch types consistent across aggregations."],"tags":["ddsketch","aggregation","type-mismatch"],"backgroundTag":"invalid-argument-value","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"}