{"record":{"id":"68187b22bac380a0","repo":"apache/druid","slug":"hyperuniquesbufferaggregator-does-not-support-getf","errorCode":null,"errorMessage":"HyperUniquesBufferAggregator does not support getFloat()","messagePattern":"HyperUniquesBufferAggregator 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/HyperUniquesBufferAggregator.java","lineNumber":99,"sourceCode":"    try {\n      HyperLogLogCollector.makeCollector(buf).fold(collector);\n    }\n    finally {\n      buf.limit(oldLimit);\n      buf.position(oldPosition);\n    }\n  }\n\n  @Override\n  public Object get(ByteBuffer buf, int position)\n  {\n    return doGet(buf, position);\n  }\n\n  @Override\n  public float getFloat(ByteBuffer buf, int position)\n  {\n    throw new UnsupportedOperationException(\"HyperUniquesBufferAggregator does not support getFloat()\");\n  }\n\n\n  @Override\n  public long getLong(ByteBuffer buf, int position)\n  {\n    throw new UnsupportedOperationException(\"HyperUniquesBufferAggregator does not support getLong()\");\n  }\n\n  @Override\n  public double getDouble(ByteBuffer buf, int position)\n  {\n    throw new UnsupportedOperationException(\"HyperUniquesBufferAggregator does not support getDouble()\");\n  }\n\n  @Override\n  public void close()\n  {","sourceCodeStart":81,"sourceCodeEnd":117,"githubUrl":"https://github.com/apache/druid/blob/9b90983fd291f26935af934383ce360473179e4d/processing/src/main/java/org/apache/druid/query/aggregation/hyperloglog/HyperUniquesBufferAggregator.java#L81-L117","documentation":"HyperUniquesBufferAggregator is the buffer-backed variant of the hyperUnique aggregator: it materializes a sketch from the ByteBuffer via doGet and supports only get()/sketch access. getFloat(ByteBuffer,int) throws UnsupportedOperationException because a sketch is not a float.","triggerScenarios":"Calling getFloat(buf, position) on a HyperUniquesBufferAggregator, typically from generic buffer-aggregator result loops that assume numeric metrics.","commonSituations":"Custom group-by engines or extension code reading buffer aggregators numerically; benchmarks/tests exercising all accessors on every BufferAggregator implementation.","solutions":["Use get(buf, position) (the HLL sketch) and compute the estimate from it","Use a float-typed aggregator when a primitive float is required","Gate numeric accessor calls on the factory's type name (\"hyperUnique\")","In SQL, use APPROX_COUNT_DISTINCT_DS_HLL for a numeric result"],"exampleFix":"// before\nfloat f = bufAgg.getFloat(buf, position); // throws\n// after\nObject o = bufAgg.get(buf, position); // HyperLogLogCollector sketch\ndouble est = o == null ? 0.0 : ((HyperLogLogCollector) o).estimateCardinality();","handlingStrategy":"type-guard","validationCode":"if (\"hyperUnique\".equals(factory.getTypeName())) { Object o = bufAgg.get(buf, pos); /* sketch */ }","typeGuard":"static boolean supportsFloat(BufferAggregator a, AggregatorFactory f) { return \"float\".equals(f.getTypeName()); }","tryCatchPattern":"try { f = bufAgg.getFloat(buf, pos); } catch (UnsupportedOperationException e) { f = Float.NaN; }","preventionTips":["Read sketches via get(buf, position) and compute estimates explicitly","Type-dispatch buffer-aggregator result extraction by factory type","Keep hyperUnique metrics out of float-only result pipelines"],"tags":["java","druid","hyperloglog","buffer-aggregator","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"}