{"record":{"id":"7a74110a3ec1ff12","repo":"apache/druid","slug":"approximatehistogramaggregator-does-not-support-ge-7a7411","errorCode":null,"errorMessage":"ApproximateHistogramAggregator does not support getLong()","messagePattern":"ApproximateHistogramAggregator 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/ApproximateHistogramAggregator.java","lineNumber":75,"sourceCode":"    }\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\n  }\n}\n","sourceCodeStart":57,"sourceCodeEnd":90,"githubUrl":"https://github.com/apache/druid/blob/9b90983fd291f26935af934383ce360473179e4d/extensions-core/histogram/src/main/java/org/apache/druid/query/aggregation/histogram/ApproximateHistogramAggregator.java#L57-L90","documentation":"ApproximateHistogramAggregator produces its value as a double or complex histogram object; getLong() is intentionally unsupported and always throws UnsupportedOperationException. A histogram summary cannot be represented as a long.","triggerScenarios":"A query pipeline calls aggregator.getLong() on an approximate histogram aggregation — e.g. the metric is declared with type 'long' or a coercer requests the long accessor.","commonSituations":"Aggregation spec declaring the output metric as 'long' instead of 'approxHistogram'; result coercion to LONG in a query; sorting/limit code treating all metric columns as long.","solutions":["Use getDouble() or getComplexValue()/the finalizer output instead of getLong()","Fix the aggregation spec type to approxHistogram/quantiles rather than long","If integral output is required, cast the finalized double in the post-aggregation/finalizer"],"exampleFix":"// before\nAggregatorFactory agg = new ApproximateHistogramAggregatorFactory(\"h\", \"col\", null, null, null, false);\nlong l = aggregator.getLong(); // throws\n// after\ndouble d = aggregator.getDouble();","handlingStrategy":"type-guard","validationCode":"if (aggregator instanceof ApproximateHistogramAggregator) { use getDouble()/getComplexValue(); }","typeGuard":"long safeGetLong(Aggregator agg) {\n  if (agg instanceof ApproximateHistogramAggregator) {\n    throw new UnsupportedOperationException(\"histograms do not support getLong()\" );\n  }\n  return agg.getLong();\n}","tryCatchPattern":"try {\n  value = aggregator.getLong();\n} catch (UnsupportedOperationException e) {\n  value = (long) aggregator.getDouble();\n}","preventionTips":["Declare histogram aggregations with type approxHistogram, not long","Extract numeric summaries via the quantiles post-aggregator","Check AggregatorFactory.getType() before choosing an accessor"],"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"}