{"record":{"id":"1e6d8f12a146f678","repo":"apache/druid","slug":"approximatehistogramfoldingaggregator-does-not-sup","errorCode":null,"errorMessage":"ApproximateHistogramFoldingAggregator does not support getFloat()","messagePattern":"ApproximateHistogramFoldingAggregator 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/ApproximateHistogramFoldingAggregator.java","lineNumber":72,"sourceCode":"    }\n\n    if (h.binCount() + histogram.binCount() <= tmpBufferB.length) {\n      histogram.foldFast(h, tmpBufferP, tmpBufferB);\n    } else {\n      histogram.foldFast(h);\n    }\n  }\n\n  @Override\n  public Object get()\n  {\n    return histogram;\n  }\n\n  @Override\n  public float getFloat()\n  {\n    throw new UnsupportedOperationException(\"ApproximateHistogramFoldingAggregator does not support getFloat()\");\n  }\n\n  @Override\n  public long getLong()\n  {\n    throw new UnsupportedOperationException(\"ApproximateHistogramFoldingAggregator does not support getLong()\");\n  }\n\n  @Override\n  public double getDouble()\n  {\n    throw new UnsupportedOperationException(\"ApproximateHistogramFoldingAggregator does not support getDouble()\");\n  }\n\n  @Override\n  public void close()\n  {\n    // no resources to cleanup","sourceCodeStart":54,"sourceCodeEnd":90,"githubUrl":"https://github.com/apache/druid/blob/9b90983fd291f26935af934383ce360473179e4d/extensions-core/histogram/src/main/java/org/apache/druid/query/aggregation/histogram/ApproximateHistogramFoldingAggregator.java#L54-L90","documentation":"ApproximateHistogramFoldingAggregator folds ApproximateHistogram objects at query time; its result is a histogram, not a primitive float. getFloat() is intentionally unimplemented and throws UnsupportedOperationException whenever called. Numeric values must be derived via post-aggregation on the folded histogram.","triggerScenarios":"Calling ApproximateHistogramFoldingAggregator.getFloat(), or a query path requesting a float accessor on an approxHistogramFold aggregation.","commonSituations":"Using approxHistogramFold where a float metric aggregator is expected; generic code that calls getFloat() on every Aggregator; older queries migrated from numeric aggregators to histogram aggregators without updating output handling.","solutions":["Use histogram post-aggregators (quantile, min, max, etc.) on the folded histogram to get numeric results.","Switch to a numeric aggregator (doubleSum, etc.) if a float/double output is actually needed.","Catch UnsupportedOperationException in generic aggregation loops and skip non-numeric aggregators."],"exampleFix":"// before\nfloat v = foldingAggregator.getFloat();\n// after\n// in query JSON use:\n// {\"type\": \"quantile\", \"fieldName\": \"histFold\", \"probability\": 0.5}\nfloat v = (float) quantileResult;","handlingStrategy":"validation","validationCode":"// Guard before calling getFloat on a folding aggregator:\nif (aggregator instanceof org.apache.druid.query.aggregation.histogram.ApproximateHistogramFoldingAggregator) {\n  // not supported; use post-aggregation instead\n}","typeGuard":"boolean supportsFloat(Object agg) {\n  return !(agg instanceof org.apache.druid.query.aggregation.histogram.ApproximateHistogramFoldingAggregator);\n}","tryCatchPattern":"try {\n  value = aggregator.getFloat();\n} catch (UnsupportedOperationException e) {\n  value = (float) histogramQuantile(aggregator.get());\n}","preventionTips":["Only query approxHistogramFold results through histogram post-aggregators.","When migrating queries from numeric aggregators, update all value-extraction paths, not just the aggregation spec.","Check AggregatorFactory.getType() before selecting an accessor."],"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"}