apache/druid · error · UnsupportedOperationException
Casting to float type is not supported
Error message
Casting to float type is not supported
What it means
The tdigestsketch aggregator's result is a TDigestSketch (a distribution), which cannot be meaningfully cast to a single float. getFloat() therefore always throws UnsupportedOperationException, indicating the requested SQL/output type is incompatible with the aggregation.
Source
Thrown at extensions-contrib/tdigestsketch/src/main/java/org/apache/druid/query/aggregation/tdigestsketch/TDigestSketchAggregator.java:91
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");
}
@Override
public long getLong()
{
throw new UnsupportedOperationException("Casting to long type is not supported");
}
@Override
public synchronized void close()
{
histogram = null;
}
}
View on GitHub (pinned to 9b90983fd2)
Solutions
- Extract a scalar via TDigestSketchQuantilePostAggregator, or min/max post-aggregators instead of casting the sketch.
- Remove the cast to FLOAT on the sketch column.
- If a number is wanted, aggregate the underlying numeric column directly, not the sketch.
Example fix
// SQL before SELECT CAST(sketch_col AS FLOAT) FROM t // after SELECT TDIGEST_QUANTILE(sketch_col, 0.5) FROM t
Defensive patterns
Strategy: type-guard
Validate before calling
if (factory instanceof TDigestSketchAggregatorFactory && outputType.equals("FLOAT")) { throw new IllegalArgumentException("tdigestsketch cannot be cast to FLOAT; use quantile/min/max post-aggregators"); } Try / catch
try { result = agg.getFloat(); } catch (UnsupportedOperationException e) { result = (float) quantilePostAggregator.compute(agg.getObject()); } Prevention
- Never CAST sketch columns to FLOAT/BIGINT in SQL.
- Extract scalars with TDIGEST_QUANTILE or min/max post-aggregators.
- Check expected output types when writing native queries against sketch metrics.
When it happens
Trigger: Running a query that requests FLOAT output for a tdigestsketch aggregate, e.g. SQL casting the sketch column to FLOAT, or native query with a float post-aggregator / float output type.
Common situations: SQL like SELECT CAST(tdigest_col AS FLOAT) ...; using the sketch in a query expecting a scalar numeric result instead of going through sketch accessor post-aggregators (quantile, min, max).
Understand the failure class
Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.
Related errors
- Casting to long type is not supported
- Expected a number or an instance of MergingDigest, but recei
- AggregatorFactoryNotMergeableException
- Cannot deserialize type[%s] to an RoaringBitmap64Counter:
- Index[%d] >= size[%d]
AI-assisted analysis of apache/druid@9b90983fd2 (2026-09-07).
Data as JSON: /api/errors/5ce3c161590bd042.
Report an issue: GitHub.