apache/druid · error · java.lang.UnsupportedOperationException

HyperUniquesAggregator does not support getFloat()

Error message

HyperUniquesAggregator does not support getFloat()

What it means

HyperUniquesAggregator computes approximate distinct counts with HyperLogLogCollector sketches; its result is a sketch/estimate accessible via get() and getHyperLogLogCollector. Numeric getters other than the sketch path are unsupported, so getFloat() throws UnsupportedOperationException.

Solutions

  1. Obtain the estimate via get()/sketch (HyperLogLogCollector) and call estimator.getEstimate(), typically wrapped by the HyperUniqueAddingPostAggregator or UniquesAggregatorFactory's result path
  2. Use a float/double aggregator if a primitive is required from the aggregator itself
  3. Gate numeric accessor calls on the aggregator factory's type name ("hyperUnique")
  4. Use SQL APPROX_COUNT_DISTINCT_DS_HLL which returns the estimate as a numeric column

Example fix

// before
float f = agg.getFloat(); // throws
// after
HyperLogLogCollector hll = ((HyperUniquesAggregator) agg).getHyperLogLogCollector();
double estimate = hll == null ? 0.0 : hll.estimateCardinalityRound();
Defensive patterns

Strategy: try-catch

Validate before calling

if ("hyperUnique".equals(factory.getTypeName())) { /* use sketch/get() path */ }

Type guard

static boolean isHyperUnique(AggregatorFactory f) { return "hyperUnique".equals(f.getTypeName()); }

Try / catch

try { f = agg.getFloat(); } catch (UnsupportedOperationException e) { /* fall back to sketch estimate */ }

Prevention

When it happens

Trigger: Calling getFloat() on a HyperUniquesAggregator, e.g. when generic result code reads every aggregator as a float, or when a query spec combines a uniques metric with float-typed result extraction.

Common situations: Custom post-aggregators or exporters iterating aggregators numerically; older integrations expecting cardinality results as primitives directly from the aggregator; test harnesses probing all 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


AI-assisted analysis of apache/druid@9b90983fd2 (2026-09-07). Data as JSON: /api/errors/797baf7b76869719. Report an issue: GitHub.

Appendix: source

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

    collector.fold((HyperLogLogCollector) object);
  }

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