apache/druid · error · java.lang.UnsupportedOperationException

CardinalityAggregator does not support getDouble()

Error message

CardinalityAggregator does not support getDouble()

What it means

Same unsupported-accessor guard for the double case: CardinalityAggregator.getDouble() always throws UnsupportedOperationException because a HyperLogLog sketch cannot yield a double; only the sketch object (get()) and its later estimateDouble() are meaningful.

Source

Thrown at processing/src/main/java/org/apache/druid/query/aggregation/cardinality/CardinalityAggregator.java:118

    return HyperLogLogCollector.makeCollectorSharingStorage(collector);
  }

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

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

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

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

View on GitHub (pinned to 9b90983fd2)

Solutions

  1. Use a HyperLogLogBucketConversion or finalizing post-aggregator that calls estimate on the sketch instead of getDouble().
  2. Keep cardinality aggregate columns typed as HLL sketch/complex in the plan.
  3. Report a planner bug if the engine coerces a cardinality aggregate to DOUBLE during aggregation.

Example fix

// before
double v = aggregator.getDouble();
// after
Object v = aggregator.get(); // HyperLogLogCollector / estimate
Defensive patterns

Strategy: validation

Validate before calling

if (!(aggFactory instanceof CardinalityAggregatorFactory)) { double v = aggregator.getDouble(); }

Type guard

if (aggregator instanceof CardinalityAggregator) {
    Object v = aggregator.get();
} else {
    double v = aggregator.getDouble();
}

Try / catch

try {
    v = aggregator.getDouble();
} catch (UnsupportedOperationException e) {
    v = Double.NaN; // or extract estimate from get()
}

Prevention

When it happens

Trigger: Calling aggregator.getDouble() on a CardinalityAggregator when a double-typed result is assumed by the caller.

Common situations: Treating cardinality aggregations as numeric in custom query code or post-aggregators; engine paths that request double output for all aggregations.

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