apache/druid · error · UnsupportedOperationException

HistogramAggregator does not support getDouble()

Error message

HistogramAggregator does not support getDouble()

What it means

Apache Druid's HistogramAggregator throws UnsupportedOperationException from getDouble() because its aggregate is a Histogram object, not a scalar double. The interface permits double-valued retrieval, but this implementation cannot honor it, so any code path requesting the histogram metric as a double fails. It is an intentional design contract, not a data or environment problem.

Source

Thrown at processing/src/main/java/org/apache/druid/query/aggregation/HistogramAggregator.java:80

    return this.histogram;
  }

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

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

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

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

View on GitHub (pinned to 9b90983fd2)

Solutions

  1. Access the histogram via agg.get() and handle the Histogram object instead of calling getDouble().
  2. Replace the histogram aggregator with a numeric one (doubleSum, doubleMean, etc.) if a double result is required.
  3. Remove numeric post-aggregators applied to the histogram metric, or compute them over numeric aggregators.
  4. Update custom aggregator-consuming code to check the result type before choosing getDouble() vs get().

Example fix

// before
double d = agg.getDouble(); // throws for HistogramAggregator
// after
Object val = agg.get();
if (val instanceof Histogram) {
  double max = ((Histogram) val).max();
}
Defensive patterns

Strategy: type-guard

Validate before calling

if (aggregator instanceof HistogramAggregator) {
  // use agg.get() (Histogram), not getDouble()
}

Type guard

boolean supportsDouble(Aggregator agg) {
  return !(agg instanceof HistogramAggregator);
}

Try / catch

try {
  value = agg.getDouble();
} catch (UnsupportedOperationException e) {
  Object h = agg.get();
}

Prevention

When it happens

Trigger: A query or post-aggregator requests the result of a 'histogram' aggregator as a DOUBLE, e.g. a double-typed post-aggregator (arithmetic, doubleMean), SQL coercion to DOUBLE, or a result format that calls agg.getDouble() on the metric.

Common situations: Applying numeric post-aggregators to histogram metrics; SQL queries where Calcite infers DOUBLE for the aggregation output; custom code iterating aggregators and calling getDouble() unconditionally; switching a metric from doubleSum to histogram without updating downstream accessors.

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