apache/druid · error · java.lang.UnsupportedOperationException

CardinalityBufferAggregator does not support getLong()

Error message

CardinalityBufferAggregator does not support getLong()

What it means

Sentinel guard in the buffer-based cardinality aggregator's typed read API: a cardinality/HyperUnique sketch is a probabilistic distinct-count structure with no long representation, so getLong() is deliberately unimplemented. It fires only when a query or column type binding asks for a primitive long read of a cardinality aggregator's output; callers must use get() (which returns the sketch object) or getFloat()/getDouble()-compatible aggregators instead.

Source

Thrown at processing/src/main/java/org/apache/druid/query/aggregation/cardinality/CardinalityBufferAggregator.java:92

  }

  @Override
  public Object get(ByteBuffer buf, int position)
  {
    return HyperUniquesBufferAggregator.doGet(buf, position);
  }

  @Override
  public float getFloat(ByteBuffer buf, int position)
  {
    throw new UnsupportedOperationException("CardinalityBufferAggregator does not support getFloat()");
  }


  @Override
  public long getLong(ByteBuffer buf, int position)
  {
    throw new UnsupportedOperationException("CardinalityBufferAggregator does not support getLong()");
  }

  @Override
  public double getDouble(ByteBuffer buf, int position)
  {
    throw new UnsupportedOperationException("CardinalityBufferAggregators does not support getDouble()");
  }

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

  @Override
  public void inspectRuntimeShape(RuntimeShapeInspector inspector)
  {
    for (int i = 0; i < selectorPluses.length; i++) {

View on GitHub (pinned to 9b90983fd2)

Solutions

  1. Read the sketch via get(buf, position) instead of getLong()
  2. Use a numeric long aggregator if a long result is required
  3. Finalize the sketch into an estimate before numeric consumption

Example fix

// before
long v = bufferAggregator.getLong(buf, position);
// after
Object v = bufferAggregator.get(buf, position); // HLL sketch
Defensive patterns

Strategy: type-guard

Validate before calling

if (!(aggFactory instanceof CardinalityAggregatorFactory)) { long v = bufferAggregator.getLong(buf, position); }

Type guard

if (factory instanceof CardinalityAggregatorFactory) {
    Object v = bufferAggregator.get(buf, position);
} else {
    long v = bufferAggregator.getLong(buf, position);
}

Try / catch

try {
    v = bufferAggregator.getLong(buf, position);
} catch (UnsupportedOperationException e) {
    v = 0L;
}

Prevention

When it happens

Trigger: Calling bufferAggregator.getLong(buf, position) on a cardinality buffer aggregator when a long-typed result is assumed.

Common situations: Vectorized long extraction on cardinality aggregations; generic aggregation code that calls getLong for all columns.

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