{"record":{"id":"edf2f40453e0a790","repo":"apache/druid","slug":"approximatehistogramaggregator-does-not-support-ge","errorCode":null,"errorMessage":"ApproximateHistogramAggregator does not support getFloat()","messagePattern":"ApproximateHistogramAggregator does not support getFloat\\(\\)","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"extensions-core/histogram/src/main/java/org/apache/druid/query/aggregation/histogram/ApproximateHistogramAggregator.java","lineNumber":69,"sourceCode":"\n  @Override\n  public void aggregate()\n  {\n    if (!selector.isNull()) {\n      histogram.offer(selector.getFloat());\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(\"ApproximateHistogramAggregator does not support getFloat()\");\n  }\n\n  @Override\n  public long getLong()\n  {\n    throw new UnsupportedOperationException(\"ApproximateHistogramAggregator does not support getLong()\");\n  }\n\n  @Override\n  public double getDouble()\n  {\n    throw new UnsupportedOperationException(\"ApproximateHistogramAggregator 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/extensions-core/histogram/src/main/java/org/apache/druid/query/aggregation/histogram/ApproximateHistogramAggregator.java#L51-L87","documentation":"ApproximateHistogramAggregator only supports producing its histogram as a double (via getDouble()/getComplexValue()). Calling getFloat() is unsupported by design and always throws UnsupportedOperationException. The histogram's summary cannot be meaningfully represented as a float.","triggerScenarios":"A query/aggregation pipeline calls aggregator.getFloat() on an approximate histogram aggregation — e.g. the column selector or result coercer treats the output as a FLOAT metric instead of a complex/double value.","commonSituations":"Defining the metric with type 'float' instead of 'approxHistogram'/'quantiles' in the aggregation spec; SQL layers coercing the histogram output to a FLOAT column; older/other query engines invoking the float accessor.","solutions":["Use getDouble() or getComplexValue()/the histogram finalizer instead of getFloat()","Declare the aggregation with type approxHistogram (or quantiles/digestedHistogram as appropriate), not float","If a numeric summary is needed, configure the finalizer (e.g. quantiles) so the output is a double"],"exampleFix":"// before\nAggregatorFactory agg = new ApproximateHistogramAggregatorFactory(\"h\", \"col\", null, null, null, false);\nfloat f = aggregator.getFloat(); // throws\n// after\ndouble d = aggregator.getDouble();\n// or read the histogram object via getComplexValue()","handlingStrategy":"type-guard","validationCode":"if (!(aggregator instanceof ApproximateHistogramAggregator)) { /* float ok */ } else { use getDouble()/getComplexValue(); }","typeGuard":"float safeGetFloat(Aggregator agg) {\n  if (agg instanceof ApproximateHistogramAggregator) {\n    throw new UnsupportedOperationException(\"use getDouble()/getComplexValue() for histograms\");\n  }\n  return agg.getFloat();\n}","tryCatchPattern":"try {\n  value = aggregator.getFloat();\n} catch (UnsupportedOperationException e) {\n  value = (float) aggregator.getDouble();\n}","preventionTips":["Declare histogram aggregations with type approxHistogram, not float","Use quantiles/finalizer post-aggregators for numeric output","Never assume every Aggregator implements all primitive accessors"],"tags":["histogram","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"}