{"record":{"id":"80b792e9f685331a","repo":"apache/druid","slug":"histogrambufferaggregator-does-not-support-getlong","errorCode":null,"errorMessage":"HistogramBufferAggregator does not support getLong()","messagePattern":"HistogramBufferAggregator does not support getLong\\(\\)","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"processing/src/main/java/org/apache/druid/query/aggregation/HistogramBufferAggregator.java","lineNumber":99,"sourceCode":"    ByteBuffer mutationBuffer = buf.duplicate();\n    mutationBuffer.position(position);\n    mutationBuffer.asLongBuffer().get(bins);\n\n    float min = mutationBuffer.getFloat(position + minOffset);\n    float max = mutationBuffer.getFloat(position + maxOffset);\n    return new Histogram(breaks, bins, min, max);\n  }\n\n  @Override\n  public float getFloat(ByteBuffer buf, int position)\n  {\n    throw new UnsupportedOperationException(\"HistogramBufferAggregator does not support getFloat()\");\n  }\n\n  @Override\n  public long getLong(ByteBuffer buf, int position)\n  {\n    throw new UnsupportedOperationException(\"HistogramBufferAggregator does not support getLong()\");\n  }\n\n  @Override\n  public double getDouble(ByteBuffer buf, int position)\n  {\n    throw new UnsupportedOperationException(\"HistogramBufferAggregator does not support getDouble\");\n  }\n\n  @Override\n  public void close()\n  {\n    // no resources to cleanup\n  }\n\n  @Override\n  public void inspectRuntimeShape(RuntimeShapeInspector inspector)\n  {\n    inspector.visit(\"selector\", selector);","sourceCodeStart":81,"sourceCodeEnd":117,"githubUrl":"https://github.com/apache/druid/blob/9b90983fd291f26935af934383ce360473179e4d/processing/src/main/java/org/apache/druid/query/aggregation/HistogramBufferAggregator.java#L81-L117","documentation":"HistogramBufferAggregator.getLong() throws UnsupportedOperationException by design: the aggregator's result is a Histogram object stored in an off-heap buffer, and it cannot be converted to a single long. Druid's BufferAggregator interface offers getLong(), but the histogram implementation rejects it. Seeing this means a query path requested LONG access on a histogram metric.","triggerScenarios":"A groupBy/timeseries query with a 'histogram' aggregator whose metric is read via getLong(ByteBuffer, int); LONG coercion of the histogram column in SQL; long-typed post-aggregators (arithmetic with long ops, longGreatest) applied to the histogram metric.","commonSituations":"Migrating queries from longSum to histogram without adjusting output handling; SQL planning that assigns BIGINT to the aggregation expression; custom aggregation pipelines that call getLong() generically on all buffer aggregators.","solutions":["Use get(ByteBuffer, int) to obtain the Histogram and process it as an object result.","Choose a long-producing aggregator (longSum, longMax) if a BIGINT result is required.","Remove LONG-typed post-aggregators or casts from the histogram metric in the query spec.","Adjust custom code to branch on aggregator type before calling getLong()."],"exampleFix":"// before\nlong l = bufferAgg.getLong(buf, position); // throws\n// after\nObject val = bufferAgg.get(buf, position);\nif (val instanceof Histogram) {\n  int binCount = ((Histogram) val).bins.length;\n}","handlingStrategy":"type-guard","validationCode":"if (bufferAggregator instanceof HistogramBufferAggregator) {\n  // use get(buf, position) (Histogram), not getLong()\n}","typeGuard":"boolean supportsLong(BufferAggregator agg) {\n  return !(agg instanceof HistogramBufferAggregator);\n}","tryCatchPattern":"try {\n  value = agg.getLong(buf, position);\n} catch (UnsupportedOperationException e) {\n  Histogram h = (Histogram) agg.get(buf, position);\n}","preventionTips":["Avoid BIGINT coercion of histogram columns in SQL","Match the aggregator type to the expected output type in ingestion specs","Handle Histogram results as objects in custom extraction code","Review post-aggregator chains for long-typed ops over histogram metrics"],"tags":["druid","aggregation","unsupported-operation","buffer-aggregator"],"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"}