{"record":{"id":"761a713bb67cd4c6","repo":"apache/druid","slug":"approximatehistogramfoldingaggregator-does-not-sup-761a71","errorCode":null,"errorMessage":"ApproximateHistogramFoldingAggregator does not support getLong()","messagePattern":"ApproximateHistogramFoldingAggregator 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/ApproximateHistogramFoldingAggregator.java","lineNumber":78,"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(\"ApproximateHistogramFoldingAggregator does not support getFloat()\");\n  }\n\n  @Override\n  public long getLong()\n  {\n    throw new UnsupportedOperationException(\"ApproximateHistogramFoldingAggregator does not support getLong()\");\n  }\n\n  @Override\n  public double getDouble()\n  {\n    throw new UnsupportedOperationException(\"ApproximateHistogramFoldingAggregator does not support getDouble()\");\n  }\n\n  @Override\n  public void close()\n  {\n    // no resources to cleanup\n  }\n}\n","sourceCodeStart":60,"sourceCodeEnd":93,"githubUrl":"https://github.com/apache/druid/blob/9b90983fd291f26935af934383ce360473179e4d/extensions-core/histogram/src/main/java/org/apache/druid/query/aggregation/histogram/ApproximateHistogramFoldingAggregator.java#L60-L93","documentation":"ApproximateHistogramFoldingAggregator.getLong() throws UnsupportedOperationException by design: the folded result is an ApproximateHistogram object and no long representation is defined. Any attempt to read the aggregation as a long fails.","triggerScenarios":"Calling ApproximateHistogramFoldingAggregator.getLong(), or queries that treat approxHistogramFold output as a long-typed metric.","commonSituations":"Framework code assuming getLong() exists on all aggregators; queries mixing histogram folds with long metric accessors; custom extensions extracting values from aggregator results generically.","solutions":["Derive numbers with histogram post-aggregators (quantile, min, max) instead of getLong().","Use a long-capable aggregator (e.g. longSum) on the raw column when a long is required.","Add a capability check or try/catch around getLong() in generic code paths."],"exampleFix":"// before\nlong v = foldingAggregator.getLong();\n// after\n// use post-aggregation in the query:\n// {\"type\": \"max\", \"fieldName\": \"histFold\"}\nlong v = (long) maxPostAggResult;","handlingStrategy":"validation","validationCode":"// Check type before getLong:\nboolean isFoldAgg = aggregator instanceof org.apache.druid.query.aggregation.histogram.ApproximateHistogramFoldingAggregator;\nif (!isFoldAgg) { value = aggregator.getLong(); }","typeGuard":"boolean supportsLong(Object agg) {\n  return !(agg instanceof org.apache.druid.query.aggregation.histogram.ApproximateHistogramFoldingAggregator);\n}","tryCatchPattern":"try {\n  value = aggregator.getLong();\n} catch (UnsupportedOperationException e) {\n  value = (long) histogramMax(aggregator.get());\n}","preventionTips":["Use longSum/longMax for long outputs; reserve approxHistogramFold for histogram analytics.","Never assume getLong() exists on every Aggregator implementation.","Add unit coverage for query plans that combine histogram folds with numeric accessors."],"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"}