{"record":{"id":"536dc0e798655a13","repo":"apache/druid","slug":"approximatehistogrambufferaggregator-does-not-supp","errorCode":null,"errorMessage":"ApproximateHistogramBufferAggregator does not support getFloat()","messagePattern":"ApproximateHistogramBufferAggregator does not support getFloat\\(\\)","errorType":"exception","errorClass":"java.lang.UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"extensions-core/histogram/src/main/java/org/apache/druid/query/aggregation/histogram/ApproximateHistogramBufferAggregator.java","lineNumber":63,"sourceCode":"  @Override\n  public void aggregate(ByteBuffer buf, int position)\n  {\n    if (selector.isNull()) {\n      return;\n    }\n    innerAggregator.aggregate(buf, position, selector.getFloat());\n  }\n\n  @Override\n  public Object get(ByteBuffer buf, int position)\n  {\n    return innerAggregator.get(buf, position);\n  }\n\n  @Override\n  public float getFloat(ByteBuffer buf, int position)\n  {\n    throw new UnsupportedOperationException(\"ApproximateHistogramBufferAggregator does not support getFloat()\");\n  }\n\n\n  @Override\n  public long getLong(ByteBuffer buf, int position)\n  {\n    throw new UnsupportedOperationException(\"ApproximateHistogramBufferAggregator does not support getLong()\");\n  }\n\n  @Override\n  public double getDouble(ByteBuffer buf, int position)\n  {\n    throw new UnsupportedOperationException(\"ApproximateHistogramBufferAggregator does not support getDouble()\");\n  }\n\n  @Override\n  public void close()\n  {","sourceCodeStart":45,"sourceCodeEnd":81,"githubUrl":"https://github.com/apache/druid/blob/9b90983fd291f26935af934383ce360473179e4d/extensions-core/histogram/src/main/java/org/apache/druid/query/aggregation/histogram/ApproximateHistogramBufferAggregator.java#L45-L81","documentation":"ApproximateHistogramBufferAggregator aggregates ApproximateHistogram objects into a ByteBuffer during segment-level aggregation. Histograms are not scalar values, so the numeric extraction methods getFloat/getLong/getDouble are intentionally unimplemented; calling getFloat() throws UnsupportedOperationException because a histogram cannot be meaningfully represented as a float. Druid's aggregator contract allows these methods to be unsupported when the aggregation's final output type is not a primitive number.","triggerScenarios":"Calling ApproximateHistogramBufferAggregator.getFloat(ByteBuffer, int) directly, or running a query whose engine invokes getFloat on a buffer-aggregated histogram column (e.g. requesting a float-typed output/accessor for the approxHistogram aggregator).","commonSituations":"A query or custom code tries to extract a numeric value from an approxHistogram aggregation instead of a scalar aggregator (e.g. using histogram output where a double/float metric was expected), or code written generically over AggregatorFactory iterates accessors assuming getFloat works for every aggregator.","solutions":["Use post-aggregators designed for histograms (e.g. approxHistogramFold with 'quantile', 'quantiles', 'min', 'max', or custom histogram post-ags) instead of reading the raw aggregate as a float.","If a numeric metric is needed, aggregate the raw numeric column with doubleSum/doubleMax etc., and keep approxHistogram only where the histogram itself is the output.","Wrap the call in try/catch for UnsupportedOperationException only if your engine must tolerate non-numeric aggregators and skip them."],"exampleFix":"// before\nfloat v = bufferAggregator.getFloat(buf, position);\n// after\n// extract via histogram post-aggregation, e.g. in the query JSON:\n// {\"type\": \"quantile\", \"fieldName\": \"approxHist\", \"probability\": 0.5}\nfloat v = quantilePostAggResult;","handlingStrategy":"validation","validationCode":"// Before using a buffer aggregator's primitive getters, verify it supports them:\nif (aggregator.getClass().getSimpleName().contains(\"ApproximateHistogram\")) {\n  // do not call getFloat/getLong/getDouble; use histogram post-aggregators instead\n}","typeGuard":"boolean supportsNumericGetters(Object agg) {\n  return !(agg instanceof org.apache.druid.query.aggregation.histogram.ApproximateHistogramBufferAggregator);\n}","tryCatchPattern":"try {\n  value = aggregator.getFloat(buf, position);\n} catch (UnsupportedOperationException e) {\n  // fall back to object/histogram-based access or skip this aggregator\n}","preventionTips":["Never request float/long/double accessors from histogram aggregators; they only produce histogram objects.","Always pair approxHistogram aggregations with quantile/min/max/custom histogram post-aggregators in queries.","Check the aggregator factory's type before writing generic numeric extraction code."],"tags":["java","druid","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-14T05:17:10.506Z"}