{"record":{"id":"d43801933f7caa2e","repo":"apache/druid","slug":"expected-a-number-or-an-instance-of-ddsketch-but","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/DDSketchAggregator.java","lineNumber":68,"sourceCode":"    double effectiveRelativeError = relativeError != null ? relativeError : DDSketchAggregatorFactory.DEFAULT_RELATIVE_ERROR;\n    this.selector = selector;\n    this.histogram = DDSketches.collapsingLowestDense(effectiveRelativeError, effectiveNumBins);\n  }\n\n  @Override\n  public void aggregate()\n  {\n    Object obj = selector.getObject();\n    if (obj == null) {\n      return;\n    }\n    synchronized (this) {\n      if (obj instanceof Number) {\n        this.histogram.accept(((Number) obj).doubleValue());\n      } else if (obj instanceof DDSketch) {\n        this.histogram.mergeWith((DDSketch) obj);\n      } else {\n        throw new IAE(\n            \"Expected a number or an instance of DDSketch, but received [%s] of type [%s]\",\n            obj,\n            obj.getClass()\n        );\n      }\n    }\n  }\n\n  @Nullable\n  @Override\n  public synchronized Object get()\n  {\n    return histogram;\n  }\n\n  @Override\n  public float getFloat()\n  {","sourceCodeStart":50,"sourceCodeEnd":86,"githubUrl":"https://github.com/apache/druid/blob/9b90983fd291f26935af934383ce360473179e4d/extensions-contrib/ddsketch/src/main/java/org/apache/druid/query/aggregation/ddsketch/DDSketchAggregator.java#L50-L86","documentation":"DDSketchAggregator.aggregate() only accepts input values that are Numbers or existing DDSketch sketches; anything else (e.g. String, null-like sentinel objects) throws this IAE. It typically indicates the selector/field expression produced an unexpected type, or sketches were combined across incompatible columns.","triggerScenarios":"Aggregating on a column whose selector returns a non-numeric object (e.g. String from a dimension), applying the ddsketch aggregator to a field that yields an unsupported type, or feeding a post-aggregator of the wrong type into another ddsketch aggregator.","commonSituations":"Wrong fieldName pointing at a string dimension instead of a numeric/sketch column, using ddsketch on nested/array values, or mismatched input/output types in a complex aggregation chain.","solutions":["Point the aggregator's fieldName at a numeric column or a column holding DDSketch objects.","Add an expression selector that casts the value to a number, e.g. type 'expression' with expression \"CAST(\\\"col\\\" AS DOUBLE)\" or \"atoi(col)\".","Verify the upstream column type with a small query before wiring the aggregation.","If aggregating existing sketches, ensure the source was produced by ddsketch, not another sketch type (e.g. HLL, quantiles)."],"exampleFix":"// before\n{\"type\": \"ddsketch\", \"fieldName\": \"tags\"} // tags is a string dimension\n// after\n{\"type\": \"ddsketch\", \"fieldExpression\": {\"type\": \"expression\", \"expression\": \"CAST(\\\"value\\\" AS DOUBLE)\"}}","handlingStrategy":"type-guard","validationCode":"// verify the input column type via segment metadata query before configuring the aggregator\n// SELECT column, dataType FROM sys.segments WHERE ... (inspect dataType is NUMERIC or COMPLEX<ddsketch>)","typeGuard":"Object v = selector.get();\nif (!(v instanceof Number) && !(v instanceof DDSketch)) {\n  throw new IllegalArgumentException(\"ddsketch input must be Number or DDSketch, got \" + (v == null ? \"null\" : v.getClass()));\n}","tryCatchPattern":"try {\n  agg.aggregate(val);\n} catch (IllegalArgumentException e) {\n  log.warn(e, \"skipping non-numeric value for ddsketch: %s\", val);\n}","preventionTips":["Check column data types (segment metadata) before wiring aggregations.","Cast string columns to numbers via an expression aggregator.","Only merge sketches produced by ddsketch itself."],"tags":["aggregation","ddsketch","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"}