{"record":{"id":"797baf7b76869719","repo":"apache/druid","slug":"hyperuniquesaggregator-does-not-support-getfloat","errorCode":null,"errorMessage":"HyperUniquesAggregator does not support getFloat()","messagePattern":"HyperUniquesAggregator does not support getFloat\\(\\)","errorType":"exception","errorClass":"java.lang.UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"processing/src/main/java/org/apache/druid/query/aggregation/hyperloglog/HyperUniquesAggregator.java","lineNumber":69,"sourceCode":"    collector.fold((HyperLogLogCollector) object);\n  }\n\n  @Nullable\n  @Override\n  public synchronized Object get()\n  {\n    if (collector == null) {\n      return null;\n    }\n    // Must make a new collector duplicating the underlying buffer to ensure the object from \"get\" is usable\n    // in a thread-safe manner.\n    return HyperLogLogCollector.makeCollectorSharingStorage(collector);\n  }\n\n  @Override\n  public float getFloat()\n  {\n    throw new UnsupportedOperationException(\"HyperUniquesAggregator does not support getFloat()\");\n  }\n\n  @Override\n  public long getLong()\n  {\n    throw new UnsupportedOperationException(\"HyperUniquesAggregator does not support getLong()\");\n  }\n\n  @Override\n  public double getDouble()\n  {\n    throw new UnsupportedOperationException(\"HyperUniquesAggregator does not support getDouble()\");\n  }\n\n  @Override\n  public void close()\n  {\n    // no resources to cleanup","sourceCodeStart":51,"sourceCodeEnd":87,"githubUrl":"https://github.com/apache/druid/blob/9b90983fd291f26935af934383ce360473179e4d/processing/src/main/java/org/apache/druid/query/aggregation/hyperloglog/HyperUniquesAggregator.java#L51-L87","documentation":"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.","triggerScenarios":"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.","commonSituations":"Custom post-aggregators or exporters iterating aggregators numerically; older integrations expecting cardinality results as primitives directly from the aggregator; test harnesses probing all accessors.","solutions":["Obtain the estimate via get()/sketch (HyperLogLogCollector) and call estimator.getEstimate(), typically wrapped by the HyperUniqueAddingPostAggregator or UniquesAggregatorFactory's result path","Use a float/double aggregator if a primitive is required from the aggregator itself","Gate numeric accessor calls on the aggregator factory's type name (\"hyperUnique\")","Use SQL APPROX_COUNT_DISTINCT_DS_HLL which returns the estimate as a numeric column"],"exampleFix":"// before\nfloat f = agg.getFloat(); // throws\n// after\nHyperLogLogCollector hll = ((HyperUniquesAggregator) agg).getHyperLogLogCollector();\ndouble estimate = hll == null ? 0.0 : hll.estimateCardinalityRound();","handlingStrategy":"try-catch","validationCode":"if (\"hyperUnique\".equals(factory.getTypeName())) { /* use sketch/get() path */ }","typeGuard":"static boolean isHyperUnique(AggregatorFactory f) { return \"hyperUnique\".equals(f.getTypeName()); }","tryCatchPattern":"try { f = agg.getFloat(); } catch (UnsupportedOperationException e) { /* fall back to sketch estimate */ }","preventionTips":["Access hyperUnique results through sketch estimate/post-aggregators, never primitive getters","Use APPROX_COUNT_DISTINCT_DS_HLL in SQL for typed numeric output","Enumerate aggregator types in generic result code instead of assuming numerics"],"tags":["java","druid","hyperloglog","aggregation","unsupported-operation"],"backgroundTag":"unsupported-operation","analyzedSha":"9b90983fd291f26935af934383ce360473179e4d","analyzedAt":"2026-09-07T13:32:30.957Z","contentChangedAt":"2026-09-07T13:32:30.957Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}