apache/druid · error · java.lang.UnsupportedOperationException

ApproximateHistogramBufferAggregator does not support getFlo

Error message

ApproximateHistogramBufferAggregator does not support getFloat()

What it means

ApproximateHistogramBufferAggregator aggregates ApproximateHistogram objects into a ByteBuffer during segment-level aggregation. Histograms are not scalar values, so the numeric extraction methods getFloat/getLong/getDouble are intentionally unimplemented; calling getFloat() throws UnsupportedOperationException because a histogram cannot be meaningfully represented as a float. Druid's aggregator contract allows these methods to be unsupported when the aggregation's final output type is not a primitive number.

Source

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

  @Override
  public void aggregate(ByteBuffer buf, int position)
  {
    if (selector.isNull()) {
      return;
    }
    innerAggregator.aggregate(buf, position, selector.getFloat());
  }

  @Override
  public Object get(ByteBuffer buf, int position)
  {
    return innerAggregator.get(buf, position);
  }

  @Override
  public float getFloat(ByteBuffer buf, int position)
  {
    throw new UnsupportedOperationException("ApproximateHistogramBufferAggregator does not support getFloat()");
  }


  @Override
  public long getLong(ByteBuffer buf, int position)
  {
    throw new UnsupportedOperationException("ApproximateHistogramBufferAggregator does not support getLong()");
  }

  @Override
  public double getDouble(ByteBuffer buf, int position)
  {
    throw new UnsupportedOperationException("ApproximateHistogramBufferAggregator does not support getDouble()");
  }

  @Override
  public void close()
  {

View on GitHub (pinned to 9b90983fd2)

Solutions

  1. Use post-aggregators designed for histograms (e.g. approxHistogramFold with 'quantile', 'quantiles', 'min', 'max', or custom histogram post-ags) instead of reading the raw aggregate as a float.
  2. If a numeric metric is needed, aggregate the raw numeric column with doubleSum/doubleMax etc., and keep approxHistogram only where the histogram itself is the output.
  3. Wrap the call in try/catch for UnsupportedOperationException only if your engine must tolerate non-numeric aggregators and skip them.

Example fix

// before
float v = bufferAggregator.getFloat(buf, position);
// after
// extract via histogram post-aggregation, e.g. in the query JSON:
// {"type": "quantile", "fieldName": "approxHist", "probability": 0.5}
float v = quantilePostAggResult;
Defensive patterns

Strategy: validation

Validate before calling

// Before using a buffer aggregator's primitive getters, verify it supports them:
if (aggregator.getClass().getSimpleName().contains("ApproximateHistogram")) {
  // do not call getFloat/getLong/getDouble; use histogram post-aggregators instead
}

Type guard

boolean supportsNumericGetters(Object agg) {
  return !(agg instanceof org.apache.druid.query.aggregation.histogram.ApproximateHistogramBufferAggregator);
}

Try / catch

try {
  value = aggregator.getFloat(buf, position);
} catch (UnsupportedOperationException e) {
  // fall back to object/histogram-based access or skip this aggregator
}

Prevention

When it happens

Trigger: Calling ApproximateHistogramBufferAggregator.getFloat(ByteBuffer, int) directly, or running a query whose engine invokes getFloat on a buffer-aggregated histogram column (e.g. requesting a float-typed output/accessor for the approxHistogram aggregator).

Common situations: A query or custom code tries to extract a numeric value from an approxHistogram aggregation instead of a scalar aggregator (e.g. using histogram output where a double/float metric was expected), or code written generically over AggregatorFactory iterates accessors assuming getFloat works for every aggregator.

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/536dc0e798655a13. Report an issue: GitHub.