apache/druid · error · java.lang.UnsupportedOperationException

ApproximateHistogramAggregator does not support getLong()

Error message

ApproximateHistogramAggregator does not support getLong()

What it means

ApproximateHistogramAggregator produces its value as a double or complex histogram object; getLong() is intentionally unsupported and always throws UnsupportedOperationException. A histogram summary cannot be represented as a long.

Solutions

  1. Use getDouble() or getComplexValue()/the finalizer output instead of getLong()
  2. Fix the aggregation spec type to approxHistogram/quantiles rather than long
  3. If integral output is required, cast the finalized double in the post-aggregation/finalizer

Example fix

// before
AggregatorFactory agg = new ApproximateHistogramAggregatorFactory("h", "col", null, null, null, false);
long l = aggregator.getLong(); // throws
// after
double d = aggregator.getDouble();
Defensive patterns

Strategy: type-guard

Validate before calling

if (aggregator instanceof ApproximateHistogramAggregator) { use getDouble()/getComplexValue(); }

Type guard

long safeGetLong(Aggregator agg) {
  if (agg instanceof ApproximateHistogramAggregator) {
    throw new UnsupportedOperationException("histograms do not support getLong()" );
  }
  return agg.getLong();
}

Try / catch

try {
  value = aggregator.getLong();
} catch (UnsupportedOperationException e) {
  value = (long) aggregator.getDouble();
}

Prevention

When it happens

Trigger: A query pipeline calls aggregator.getLong() on an approximate histogram aggregation — e.g. the metric is declared with type 'long' or a coercer requests the long accessor.

Common situations: Aggregation spec declaring the output metric as 'long' instead of 'approxHistogram'; result coercion to LONG in a query; sorting/limit code treating all metric columns as long.

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

Appendix: source

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

    }
  }

  @Override
  public Object get()
  {
    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)