apache/druid · error · java.lang.UnsupportedOperationException

HyperUniquesAggregator does not support getDouble()

Error message

HyperUniquesAggregator does not support getDouble()

What it means

HyperUniquesAggregator's getDouble() throws UnsupportedOperationException. Although the sketch estimate is conceptually a double, the aggregator exposes it only through the sketch result path, so direct primitive accessors are deliberately unimplemented.

Solutions

  1. Use the sketch-based estimate (get()/getHyperLogLogCollector().estimateCardinality()) instead of getDouble()
  2. Use UniquesAggregatorFactory's supported result/post-aggregator path for a double estimate
  3. Branch on the aggregator factory's type name before numeric access
  4. Prefer SQL APPROX_COUNT_DISTINCT_DS_HLL for a typed double result

Example fix

// before
double d = agg.getDouble(); // throws
// after
HyperLogLogCollector hll = ((HyperUniquesAggregator) agg).getHyperLogLogCollector();
double d2 = hll == null ? 0.0 : hll.estimateCardinality();
Defensive patterns

Strategy: type-guard

Validate before calling

if ("hyperUnique".equals(factory.getTypeName())) { estimate = ((HyperUniquesAggregator) agg).getHyperLogLogCollector().estimateCardinality(); }

Type guard

static Double safeDouble(Aggregator a) { try { return a.getDouble(); } catch (UnsupportedOperationException e) { return null; } }

Try / catch

try { d = agg.getDouble(); } catch (UnsupportedOperationException e) { d = estimateFromSketch(agg); }

Prevention

When it happens

Trigger: Calling getDouble() on a HyperUniquesAggregator during generic numeric result extraction.

Common situations: Custom merge/extraction layers summing metrics as doubles; query engines or tools built against numeric-only aggregators being pointed at hyperUnique metrics.

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

Appendix: source

Thrown at processing/src/main/java/org/apache/druid/query/aggregation/hyperloglog/HyperUniquesAggregator.java:81

    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)