apache/druid · error · UnsupportedOperationException

HistogramAggregator does not support getLong()

Error message

HistogramAggregator does not support getLong()

What it means

Apache Druid's HistogramAggregator only supports its native aggregate type (a Histogram object) via agg.get(). The Aggregator interface exposes getFloat/getLong/getDouble, and HistogramAggregator deliberately throws UnsupportedOperationException from these because a histogram cannot be meaningfully coerced to a single scalar numeric value. The error means your query is asking a 'histogram' aggregator to deliver its result as a long.

Source

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

    histogram.offer(selector.getFloat());
  }

  @Override
  public Object get()
  {
    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. Do not access the histogram aggregator's result via getLong(); use agg.get() which returns the Histogram object.
  2. Use an aggregator whose output is numeric (e.g. longSum, doubleSum, filtered aggregators) if a LONG result is needed.
  3. If you need statistics from the histogram, wrap it with post-aggregators designed for histograms or compute bins after retrieval.
  4. If the metric was misconfigured as 'histogram' in the ingestion/query spec, correct the aggregator type.

Example fix

// before
AggregatorFactory factory = new HistogramAggregatorFactory("h", "col", breaks);
long value = selectorFor("h").getLong(); // throws
// after
Histogram hist = (Histogram) agg.get();
long approxCount = (long) hist.count();
Defensive patterns

Strategy: type-guard

Validate before calling

if (aggregator instanceof HistogramAggregator) {
  // must use agg.get(); never call getLong()
}

Type guard

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

Try / catch

try {
  value = agg.getLong();
} catch (UnsupportedOperationException e) {
  Histogram h = (Histogram) agg.get();
}

Prevention

When it happens

Trigger: A native query or SQL query uses a 'histogram' aggregator with a post-aggregator, SQL layer, or result format that requests the metric as a LONG (e.g. SQL type coercion of the aggregation output to BIGINT, or 'longLast'/'longFirst' style accessors, or a numeric post-aggregator applied to a histogram metric).

Common situations: Running SQL like SELECT HISTOGRAM(col) ... CAST/numeric aggregation over it; using a histogram aggregator in a groupBy with a numeric post-aggregator (arithmetic, greatest, etc.); older configs migrating from numeric aggregators to histogram; query layers that assume every aggregator can yield long/double/float.

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