apache/druid · error · java.lang.UnsupportedOperationException
HyperUniquesAggregator does not support getLong()
Error message
HyperUniquesAggregator does not support getLong()
What it means
HyperUniquesAggregator cannot return a long: the aggregator's product is an HLL sketch whose cardinality estimate is a double obtained through the sketch, not a long primitive. getLong() throws UnsupportedOperationException to prevent silent precision/type errors.
Solutions
- Read the sketch via get()/getHyperLogLogCollector() and use its estimate (cast to long if integral output is desired)
- Keep using the native query uniques result/post-aggregator path (e.g. cardinality post-agg) instead of direct getLong
- Check the factory type name before calling getLong
- In SQL, use APPROX_COUNT_DISTINCT_DS_HLL which yields a BIGINT-typed result
Example fix
// before long l = agg.getLong(); // throws // after HyperLogLogCollector hll = ((HyperUniquesAggregator) agg).getHyperLogLogCollector(); long l2 = hll == null ? 0L : (long) hll.estimateCardinality();
Defensive patterns
Strategy: try-catch
Validate before calling
if (!"hyperUnique".equals(factory.getTypeName())) { l = agg.getLong(); } Type guard
static Long safeLong(Aggregator a) { try { return a.getLong(); } catch (UnsupportedOperationException e) { return null; } } Try / catch
try { l = agg.getLong(); } catch (UnsupportedOperationException e) { l = (long) sketchEstimate(agg); } Prevention
- Derive cardinality estimates from the HLL sketch, then cast to long if needed
- Check getTypeName() before integer access
- Update integrations when swapping count metrics for hyperUnique
When it happens
Trigger: Calling getLong() on a HyperUniquesAggregator when result extraction assumes integer metrics.
Common situations: Custom result serialization treating every aggregator as long; plugins replacing a count aggregator with hyperUnique without changing 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
- HyperUniquesAggregator does not support getDouble()
- HyperUniquesAggregator does not support getFloat()
- ApproximateHistogramBufferAggregator does not support…
- ApproximateHistogramBufferAggregator does not support…
- ApproximateHistogramBufferAggregator does not support…
AI-assisted analysis of apache/druid@9b90983fd2 (2026-09-07).
Data as JSON: /api/errors/38d38b59f0eb7d5e.
Report an issue: GitHub.
Appendix: source
Thrown at processing/src/main/java/org/apache/druid/query/aggregation/hyperloglog/HyperUniquesAggregator.java:75
{
if (collector == null) {
return null;
}
// Must make a new collector duplicating the underlying buffer to ensure the object from "get" is usable
// in a thread-safe manner.
return HyperLogLogCollector.makeCollectorSharingStorage(collector);
}
@Override
public float getFloat()
{
throw new UnsupportedOperationException("HyperUniquesAggregator does not support getFloat()");
}
@Override
public long getLong()
{
throw new UnsupportedOperationException("HyperUniquesAggregator does not support getLong()");
}
@Override
public double getDouble()
{
throw new UnsupportedOperationException("HyperUniquesAggregator does not support getDouble()");
}
@Override
public void close()
{
// no resources to cleanup
}
}
View on GitHub (pinned to 9b90983fd2)