{"record":{"id":"377069a634e458fe","repo":"apache/druid","slug":"approximatehistogrambufferaggregator-does-not-supp-377069","errorCode":null,"errorMessage":"ApproximateHistogramBufferAggregator does not support getLong()","messagePattern":"ApproximateHistogramBufferAggregator does not support getLong\\(\\)","errorType":"exception","errorClass":"java.lang.UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"extensions-core/histogram/src/main/java/org/apache/druid/query/aggregation/histogram/ApproximateHistogramBufferAggregator.java","lineNumber":70,"sourceCode":"  }\n\n  @Override\n  public Object get(ByteBuffer buf, int position)\n  {\n    return innerAggregator.get(buf, position);\n  }\n\n  @Override\n  public float getFloat(ByteBuffer buf, int position)\n  {\n    throw new UnsupportedOperationException(\"ApproximateHistogramBufferAggregator does not support getFloat()\");\n  }\n\n\n  @Override\n  public long getLong(ByteBuffer buf, int position)\n  {\n    throw new UnsupportedOperationException(\"ApproximateHistogramBufferAggregator does not support getLong()\");\n  }\n\n  @Override\n  public double getDouble(ByteBuffer buf, int position)\n  {\n    throw new UnsupportedOperationException(\"ApproximateHistogramBufferAggregator 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":52,"sourceCodeEnd":88,"githubUrl":"https://github.com/apache/druid/blob/9b90983fd291f26935af934383ce360473179e4d/extensions-core/histogram/src/main/java/org/apache/druid/query/aggregation/histogram/ApproximateHistogramBufferAggregator.java#L52-L88","documentation":"ApproximateHistogramBufferAggregator.getLong() is intentionally unimplemented: the aggregator produces an ApproximateHistogram object, not a long, so there is no valid long representation to return. Calling it always throws UnsupportedOperationException. This is part of Druid's pattern where non-numeric aggregators reject primitive getters.","triggerScenarios":"Calling ApproximateHistogramBufferAggregator.getLong(ByteBuffer, int), or a query/engine path that requests a long-typed value from a buffer-aggregated approxHistogram column.","commonSituations":"Generic aggregation code assuming all aggregators support getLong; queries mixing histogram aggregators with long-valued metric expectations; custom accessor code reading histogram segments as numeric metrics.","solutions":["Use histogram post-aggregators (quantile, min, max, etc.) to derive numeric values from the histogram.","Aggregate the underlying numeric column with a long-capable aggregator (longSum) if a long output is required.","Guard generic code with a capability check / try-catch for UnsupportedOperationException before invoking getLong."],"exampleFix":"// before\nlong v = bufferAggregator.getLong(buf, position);\n// after\n// use a histogram post-agg in the query, e.g.:\n// {\"type\": \"quantile\", \"fieldName\": \"approxHist\", \"probability\": 0.95}\nlong v = (long) quantilePostAggResult;","handlingStrategy":"validation","validationCode":"// Verify numeric support before calling getLong:\nif (aggregator.getClass().getSimpleName().startsWith(\"ApproximateHistogram\")) {\n  throw new IllegalStateException(\"use histogram post-aggregators, not getLong()\");\n}","typeGuard":"boolean supportsLong(Object agg) {\n  return !(agg instanceof org.apache.druid.query.aggregation.histogram.ApproximateHistogramBufferAggregator);\n}","tryCatchPattern":"try {\n  value = aggregator.getLong(buf, position);\n} catch (UnsupportedOperationException e) {\n  value = deriveFromHistogramPostAgg();\n}","preventionTips":["Treat histogram aggregators as object-valued, never long-valued.","Document in query-building code which aggregator types support primitive getters.","Prefer explicit post-aggregators over raw buffer access."],"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"}