apache/druid · error · IllegalArgumentException
Expected a number or an instance of MergingDigest, but recei
Error message
Expected a number or an instance of MergingDigest, but received [%s] of type [%s]
What it means
TDigestSketchAggregator's aggregate() accepts only numeric values (added as double data points) or MergingDigest instances (merged whole sketches). Any other object type in the selector is rejected with this IAE naming the value and its class.
Source
Thrown at extensions-contrib/tdigestsketch/src/main/java/org/apache/druid/query/aggregation/tdigestsketch/TDigestSketchAggregator.java:73
}
@Override
public void aggregate()
{
Object obj = selector.getObject();
if (obj == null) {
return;
}
if (obj instanceof Number) {
synchronized (this) {
histogram.add(((Number) obj).doubleValue());
}
} else if (obj instanceof MergingDigest) {
synchronized (this) {
histogram.add((MergingDigest) obj);
}
} else {
throw new IAE(
"Expected a number or an instance of MergingDigest, but received [%s] of type [%s]",
obj,
obj.getClass()
);
}
}
@Nullable
@Override
public synchronized Object get()
{
return histogram;
}
@Override
public float getFloat()
{
throw new UnsupportedOperationException("Casting to float type is not supported");View on GitHub (pinned to 9b90983fd2)
Solutions
- Point the aggregator at a column of type tdigestsketch (MergingDigest values) or a numeric column.
- If the value is serialized bytes, deserialize it first via TDigestSketchAggregatorFactory.deserialize / the sqlTypeName coercion.
- Remove or fix the expression/post-aggregator that is emitting an unexpected type.
- Check the input column's actual types with a small sample query before aggregating.
Example fix
// before
new TDigestSketchAggregatorFactory("sk", "someStringColumn", 100);
// after
new TDigestSketchAggregatorFactory("sk", "tdigestColumn", 100); Defensive patterns
Strategy: type-guard
Validate before calling
if (!(v instanceof Number || v instanceof MergingDigest)) { throw new IllegalArgumentException("column must be numeric or tdigestsketch, got: " + v.getClass()); } Type guard
boolean isAggregateable(Object v) { return v instanceof Number || v instanceof MergingDigest; } Try / catch
try { agg.aggregate(selector); } catch (IAE e) { log.error("bad input to tdigest aggregator: %s", e.getMessage()); } Prevention
- Bind the aggregator only to numeric or tdigestsketch-typed columns.
- Sample the input column's types before running aggregations.
- Avoid expressions that emit strings/arrays into sketch aggregators.
- Deserialize serialized sketches before aggregating.
When it happens
Trigger: Feeding the tdigestsketch aggregator a column or expression that yields non-numeric, non-MergingDigest objects, e.g. string fields, HyperLogLog sketches, arrays, or serialized (non-deserialized) sketch representations.
Common situations: Pointing the aggregator at a raw string/complex column instead of a tdigestsketch column; a post-aggregator or expression outputting the wrong type; mixing aggregation on deserialized vs serialized sketch objects.
Understand the failure class
Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.
Related errors
- Cannot deserialize type[%s] to an RoaringBitmap64Counter:
- Casting to float type is not supported
- Casting to long type is not supported
- AggregatorFactoryNotMergeableException
- Incompatible type for metric[%s], expected a ApproximateHist
AI-assisted analysis of apache/druid@9b90983fd2 (2026-09-07).
Data as JSON: /api/errors/fa4c78adedea5a11.
Report an issue: GitHub.