apache/druid · error · IllegalArgumentException
Expected a number or an instance of DDSketch, but received [
Error message
Expected a number or an instance of DDSketch, but received [%s] of type [%s]
What it means
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.
Source
Thrown at extensions-contrib/ddsketch/src/main/java/org/apache/druid/query/aggregation/ddsketch/DDSketchAggregator.java:68
double effectiveRelativeError = relativeError != null ? relativeError : DDSketchAggregatorFactory.DEFAULT_RELATIVE_ERROR;
this.selector = selector;
this.histogram = DDSketches.collapsingLowestDense(effectiveRelativeError, effectiveNumBins);
}
@Override
public void aggregate()
{
Object obj = selector.getObject();
if (obj == null) {
return;
}
synchronized (this) {
if (obj instanceof Number) {
this.histogram.accept(((Number) obj).doubleValue());
} else if (obj instanceof DDSketch) {
this.histogram.mergeWith((DDSketch) obj);
} else {
throw new IAE(
"Expected a number or an instance of DDSketch, but received [%s] of type [%s]",
obj,
obj.getClass()
);
}
}
}
@Nullable
@Override
public synchronized Object get()
{
return histogram;
}
@Override
public float getFloat()
{View on GitHub (pinned to 9b90983fd2)
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).
Example fix
// before
{"type": "ddsketch", "fieldName": "tags"} // tags is a string dimension
// after
{"type": "ddsketch", "fieldExpression": {"type": "expression", "expression": "CAST(\"value\" AS DOUBLE)"}} Defensive patterns
Strategy: type-guard
Validate before calling
// verify the input column type via segment metadata query before configuring the aggregator // SELECT column, dataType FROM sys.segments WHERE ... (inspect dataType is NUMERIC or COMPLEX<ddsketch>)
Type guard
Object v = selector.get();
if (!(v instanceof Number) && !(v instanceof DDSketch)) {
throw new IllegalArgumentException("ddsketch input must be Number or DDSketch, got " + (v == null ? "null" : v.getClass()));
} Try / catch
try {
agg.aggregate(val);
} catch (IllegalArgumentException e) {
log.warn(e, "skipping non-numeric value for ddsketch: %s", val);
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- Expected a number or an instance of DDSketch, but received [
- Casting to float type is not supported
- Casting to long type is not supported
- Not implemented
- Expected a Number, but received [%s] of type [%s]
AI-assisted analysis of apache/druid@9b90983fd2 (2026-09-07).
Data as JSON: /api/errors/d43801933f7caa2e.
Report an issue: GitHub.