{"record":{"id":"095405600dbaa33f","repo":"apache/druid","slug":"approximatehistogramaggregator-does-not-support-ge-095405","errorCode":null,"errorMessage":"ApproximateHistogramAggregator does not support getDouble()","messagePattern":"ApproximateHistogramAggregator does not support getDouble\\(\\)","errorType":"exception","errorClass":"java.lang.UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"extensions-core/histogram/src/main/java/org/apache/druid/query/aggregation/histogram/ApproximateHistogramAggregator.java","lineNumber":81,"sourceCode":"    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\n  }\n}\n","sourceCodeStart":63,"sourceCodeEnd":90,"githubUrl":"https://github.com/apache/druid/blob/9b90983fd291f26935af934383ce360473179e4d/extensions-core/histogram/src/main/java/org/apache/druid/query/aggregation/histogram/ApproximateHistogramAggregator.java#L63-L90","documentation":"Despite histograms logically being doubles, ApproximateHistogramAggregator explicitly throws UnsupportedOperationException from getDouble() as well in this code path — the aggregate is exposed via getComplexValue() (the ApproximateHistogram object) and finalized later; the primitive accessors are not supported.","triggerScenarios":"A query or result-coercion layer calls aggregator.getDouble() on an approximate histogram aggregation, e.g. metric declared with type 'double' instead of 'approxHistogram'.","commonSituations":"Aggregation spec declaring the output metric as 'double'; downstream code assuming all aggregators expose primitives; direct programmatic use of the aggregator outside the finalized query path.","solutions":["Retrieve the value with getComplexValue() (the ApproximateHistogram) and use its finalized form (getQuantiles, getMin/getMax)","Declare the aggregation as approxHistogram in the spec so the complex finalizer is used","Use the quantiles post-aggregator to extract numeric summaries instead of the primitive accessors"],"exampleFix":"// before\nAggregatorFactory agg = new ApproximateHistogramAggregatorFactory(\"h\", \"col\", null, null, null, false);\ndouble d = aggregator.getDouble(); // throws\n// after\nApproximateHistogram hist = (ApproximateHistogram) aggregator.getComplexValue();\nfloat[] quantiles = hist.getQuantiles(0.5f, 0.95f);","handlingStrategy":"type-guard","validationCode":"if (aggregator instanceof ApproximateHistogramAggregator) {\n  Object v = aggregator.getComplexValue(); // ApproximateHistogram\n}","typeGuard":"double histogramSummary(Aggregator agg) {\n  if (agg instanceof ApproximateHistogramAggregator) {\n    return ((ApproximateHistogram) agg.getComplexValue()).getQuantiles(0.5f)[0];\n  }\n  return agg.getDouble();\n}","tryCatchPattern":"try {\n  value = aggregator.getDouble();\n} catch (UnsupportedOperationException e) {\n  ApproximateHistogram h = (ApproximateHistogram) aggregator.getComplexValue();\n  value = h.getQuantiles(0.5f)[0].doubleValue();\n}","preventionTips":["Read histogram output through getComplexValue()/finalizers","Declare output as approxHistogram so the complex finalizer runs","Use quantiles post-aggregators for numeric values"],"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"}