apache/druid · error · java.lang.UnsupportedOperationException

ApproximateHistogramAggregator does not support getDouble()

Error message

ApproximateHistogramAggregator does not support getDouble()

What it means

Despite histograms logically being doubles, ApproximateHistogramAggregator explicitly throws UnsupportedOperationException from getDouble() as well in this code path — the aggregate is exposed via getComplexValue() (the ApproximateHistogram object) and finalized later; the primitive accessors are not supported.

Solutions

  1. Retrieve the value with getComplexValue() (the ApproximateHistogram) and use its finalized form (getQuantiles, getMin/getMax)
  2. Declare the aggregation as approxHistogram in the spec so the complex finalizer is used
  3. Use the quantiles post-aggregator to extract numeric summaries instead of the primitive accessors

Example fix

// before
AggregatorFactory agg = new ApproximateHistogramAggregatorFactory("h", "col", null, null, null, false);
double d = aggregator.getDouble(); // throws
// after
ApproximateHistogram hist = (ApproximateHistogram) aggregator.getComplexValue();
float[] quantiles = hist.getQuantiles(0.5f, 0.95f);
Defensive patterns

Strategy: type-guard

Validate before calling

if (aggregator instanceof ApproximateHistogramAggregator) {
  Object v = aggregator.getComplexValue(); // ApproximateHistogram
}

Type guard

double histogramSummary(Aggregator agg) {
  if (agg instanceof ApproximateHistogramAggregator) {
    return ((ApproximateHistogram) agg.getComplexValue()).getQuantiles(0.5f)[0];
  }
  return agg.getDouble();
}

Try / catch

try {
  value = aggregator.getDouble();
} catch (UnsupportedOperationException e) {
  ApproximateHistogram h = (ApproximateHistogram) aggregator.getComplexValue();
  value = h.getQuantiles(0.5f)[0].doubleValue();
}

Prevention

When it happens

Trigger: A query or result-coercion layer calls aggregator.getDouble() on an approximate histogram aggregation, e.g. metric declared with type 'double' instead of 'approxHistogram'.

Common situations: Aggregation spec declaring the output metric as 'double'; downstream code assuming all aggregators expose primitives; direct programmatic use of the aggregator outside the finalized query path.

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/095405600dbaa33f. Report an issue: GitHub.

Appendix: source

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

    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)