{"record":{"id":"f0bcd9ba700cb85c","repo":"apache/druid","slug":"histogramaggregator-does-not-support-getdouble","errorCode":null,"errorMessage":"HistogramAggregator does not support getDouble()","messagePattern":"HistogramAggregator does not support getDouble\\(\\)","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"processing/src/main/java/org/apache/druid/query/aggregation/HistogramAggregator.java","lineNumber":80,"sourceCode":"    return this.histogram;\n  }\n\n  @Override\n  public float getFloat()\n  {\n    throw new UnsupportedOperationException(\"HistogramAggregator does not support getFloat()\");\n  }\n\n  @Override\n  public long getLong()\n  {\n    throw new UnsupportedOperationException(\"HistogramAggregator does not support getLong()\");\n  }\n\n  @Override\n  public double getDouble()\n  {\n    throw new UnsupportedOperationException(\"HistogramAggregator does not support getDouble()\");\n  }\n\n  @Override\n  public void close()\n  {\n    // no resources to cleanup\n  }\n}\n","sourceCodeStart":62,"sourceCodeEnd":89,"githubUrl":"https://github.com/apache/druid/blob/9b90983fd291f26935af934383ce360473179e4d/processing/src/main/java/org/apache/druid/query/aggregation/HistogramAggregator.java#L62-L89","documentation":"Apache Druid's HistogramAggregator throws UnsupportedOperationException from getDouble() because its aggregate is a Histogram object, not a scalar double. The interface permits double-valued retrieval, but this implementation cannot honor it, so any code path requesting the histogram metric as a double fails. It is an intentional design contract, not a data or environment problem.","triggerScenarios":"A query or post-aggregator requests the result of a 'histogram' aggregator as a DOUBLE, e.g. a double-typed post-aggregator (arithmetic, doubleMean), SQL coercion to DOUBLE, or a result format that calls agg.getDouble() on the metric.","commonSituations":"Applying numeric post-aggregators to histogram metrics; SQL queries where Calcite infers DOUBLE for the aggregation output; custom code iterating aggregators and calling getDouble() unconditionally; switching a metric from doubleSum to histogram without updating downstream accessors.","solutions":["Access the histogram via agg.get() and handle the Histogram object instead of calling getDouble().","Replace the histogram aggregator with a numeric one (doubleSum, doubleMean, etc.) if a double result is required.","Remove numeric post-aggregators applied to the histogram metric, or compute them over numeric aggregators.","Update custom aggregator-consuming code to check the result type before choosing getDouble() vs get()."],"exampleFix":"// before\ndouble d = agg.getDouble(); // throws for HistogramAggregator\n// after\nObject val = agg.get();\nif (val instanceof Histogram) {\n  double max = ((Histogram) val).max();\n}","handlingStrategy":"type-guard","validationCode":"if (aggregator instanceof HistogramAggregator) {\n  // use agg.get() (Histogram), not getDouble()\n}","typeGuard":"boolean supportsDouble(Aggregator agg) {\n  return !(agg instanceof HistogramAggregator);\n}","tryCatchPattern":"try {\n  value = agg.getDouble();\n} catch (UnsupportedOperationException e) {\n  Object h = agg.get();\n}","preventionTips":["Avoid DOUBLE casts/coercions over histogram columns in SQL","Inspect the metric type column in the query spec before adding post-aggregators","Test queries against histogram aggregators with the actual result format","Prefer numeric aggregators when scalar results are expected"],"tags":["druid","aggregation","unsupported-operation","histogram"],"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"}