apache/druid · error · java.lang.UnsupportedOperationException

ApproximateHistogramBufferAggregator does not support getLon

Error message

ApproximateHistogramBufferAggregator does not support getLong()

What it means

ApproximateHistogramBufferAggregator.getLong() is intentionally unimplemented: the aggregator produces an ApproximateHistogram object, not a long, so there is no valid long representation to return. Calling it always throws UnsupportedOperationException. This is part of Druid's pattern where non-numeric aggregators reject primitive getters.

Source

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

  }

  @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()
  {
    // no resources to cleanup
  }

  @Override
  public void inspectRuntimeShape(RuntimeShapeInspector inspector)
  {
    inspector.visit("selector", selector);

View on GitHub (pinned to 9b90983fd2)

Solutions

  1. Use histogram post-aggregators (quantile, min, max, etc.) to derive numeric values from the histogram.
  2. Aggregate the underlying numeric column with a long-capable aggregator (longSum) if a long output is required.
  3. Guard generic code with a capability check / try-catch for UnsupportedOperationException before invoking getLong.

Example fix

// before
long v = bufferAggregator.getLong(buf, position);
// after
// use a histogram post-agg in the query, e.g.:
// {"type": "quantile", "fieldName": "approxHist", "probability": 0.95}
long v = (long) quantilePostAggResult;
Defensive patterns

Strategy: validation

Validate before calling

// Verify numeric support before calling getLong:
if (aggregator.getClass().getSimpleName().startsWith("ApproximateHistogram")) {
  throw new IllegalStateException("use histogram post-aggregators, not getLong()");
}

Type guard

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

Try / catch

try {
  value = aggregator.getLong(buf, position);
} catch (UnsupportedOperationException e) {
  value = deriveFromHistogramPostAgg();
}

Prevention

When it happens

Trigger: Calling ApproximateHistogramBufferAggregator.getLong(ByteBuffer, int), or a query/engine path that requests a long-typed value from a buffer-aggregated approxHistogram column.

Common situations: Generic aggregation code assuming all aggregators support getLong; queries mixing histogram aggregators with long-valued metric expectations; custom accessor code reading histogram segments as numeric metrics.

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/377069a634e458fe. Report an issue: GitHub.