apache/druid · error · UnsupportedOperationException

ApproximateHistogramAggregator does not support getFloat()

Error message

ApproximateHistogramAggregator does not support getFloat()

What it means

ApproximateHistogramAggregator only supports producing its histogram as a double (via getDouble()/getComplexValue()). Calling getFloat() is unsupported by design and always throws UnsupportedOperationException. The histogram's summary cannot be meaningfully represented as a float.

Solutions

  1. Use getDouble() or getComplexValue()/the histogram finalizer instead of getFloat()
  2. Declare the aggregation with type approxHistogram (or quantiles/digestedHistogram as appropriate), not float
  3. If a numeric summary is needed, configure the finalizer (e.g. quantiles) so the output is a double

Example fix

// before
AggregatorFactory agg = new ApproximateHistogramAggregatorFactory("h", "col", null, null, null, false);
float f = aggregator.getFloat(); // throws
// after
double d = aggregator.getDouble();
// or read the histogram object via getComplexValue()
Defensive patterns

Strategy: type-guard

Validate before calling

if (!(aggregator instanceof ApproximateHistogramAggregator)) { /* float ok */ } else { use getDouble()/getComplexValue(); }

Type guard

float safeGetFloat(Aggregator agg) {
  if (agg instanceof ApproximateHistogramAggregator) {
    throw new UnsupportedOperationException("use getDouble()/getComplexValue() for histograms");
  }
  return agg.getFloat();
}

Try / catch

try {
  value = aggregator.getFloat();
} catch (UnsupportedOperationException e) {
  value = (float) aggregator.getDouble();
}

Prevention

When it happens

Trigger: A query/aggregation pipeline calls aggregator.getFloat() on an approximate histogram aggregation — e.g. the column selector or result coercer treats the output as a FLOAT metric instead of a complex/double value.

Common situations: Defining the metric with type 'float' instead of 'approxHistogram'/'quantiles' in the aggregation spec; SQL layers coercing the histogram output to a FLOAT column; older/other query engines invoking the float accessor.

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


AI-assisted analysis of apache/druid@9b90983fd2 (2026-09-07). Data as JSON: /api/errors/edf2f40453e0a790. Report an issue: GitHub.

Appendix: source

Thrown at extensions-core/histogram/src/main/java/org/apache/druid/query/aggregation/histogram/ApproximateHistogramAggregator.java:69

  @Override
  public void aggregate()
  {
    if (!selector.isNull()) {
      histogram.offer(selector.getFloat());
    }
  }

  @Override
  public Object get()
  {
    return histogram;
  }

  @Override
  public float getFloat()
  {
    throw new UnsupportedOperationException("ApproximateHistogramAggregator does not support getFloat()");
  }

  @Override
  public long getLong()
  {
    throw new UnsupportedOperationException("ApproximateHistogramAggregator does not support getLong()");
  }

  @Override
  public double getDouble()
  {
    throw new UnsupportedOperationException("ApproximateHistogramAggregator does not support getDouble()");
  }

  @Override
  public void close()
  {
    // no resources to cleanup

View on GitHub (pinned to 9b90983fd2)