{"record":{"id":"e11b13d3c438e662","repo":"apache/druid","slug":"comparing-histograms-is-not-supported-e11b13","errorCode":null,"errorMessage":"Comparing histograms is not supported","messagePattern":"Comparing histograms is not supported","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":500,"severity":"error","filePath":"extensions-core/datasketches/src/main/java/org/apache/druid/query/aggregation/datasketches/kll/KllDoublesSketchToHistogramPostAggregator.java","lineNumber":155,"sourceCode":"\n  @JsonProperty\n  @JsonInclude(JsonInclude.Include.NON_NULL)\n  public double[] getSplitPoints()\n  {\n    return splitPoints;\n  }\n\n  @JsonProperty\n  @JsonInclude(JsonInclude.Include.NON_NULL)\n  public Integer getNumBins()\n  {\n    return numBins;\n  }\n\n  @Override\n  public Comparator<double[]> getComparator()\n  {\n    throw new IAE(\"Comparing histograms is not supported\");\n  }\n\n  @Override\n  public Set<String> getDependentFields()\n  {\n    return field.getDependentFields();\n  }\n\n  @Override\n  public String toString()\n  {\n    return getClass().getSimpleName() + \"{\" +\n        \"name='\" + name + '\\'' +\n        \", field=\" + field +\n        \", splitPoints=\" + Arrays.toString(splitPoints) +\n        \", numBins=\" + numBins +\n        \"}\";\n  }","sourceCodeStart":137,"sourceCodeEnd":173,"githubUrl":"https://github.com/apache/druid/blob/9b90983fd291f26935af934383ce360473179e4d/extensions-core/datasketches/src/main/java/org/apache/druid/query/aggregation/datasketches/kll/KllDoublesSketchToHistogramPostAggregator.java#L137-L173","documentation":"KllDoublesSketchToHistogramPostAggregator.getComparator always throws IllegalArgumentException because a histogram (array of bin counts) has no defined ordering. The post-aggregator interface requires a comparator, but comparing histograms is intentionally unsupported.","triggerScenarios":"Any code path that requests ordering of this post-aggregator's output, e.g. ORDER BY on the histogram column, or framework code that calls getComparator() to sort results.","commonSituations":"Sorting query output by the histogram column; generic post-aggregator processing that assumes every comparator is valid; building derived queries that order on array-valued post-aggregators.","solutions":["Do not sort on the histogram output; sort by a scalar such as a quantile or the underlying metric","Compute a single statistic (e.g. kllDoublesSketchToQuantiles with a fraction) and order by that","Guard generic code: check whether the post-aggregator supports comparison before calling getComparator"],"exampleFix":"// before\nORDER BY histogramOutput\n// after\nORDER BY median  -- from kllDoublesSketchToQuantiles with fraction 0.5","handlingStrategy":"validation","validationCode":"if (postAgg instanceof KllDoublesSketchToHistogramPostAggregator) {\n  throw new IllegalArgumentException(\"Histogram output is not sortable\");\n}","typeGuard":null,"tryCatchPattern":"try { cmp = postAgg.getComparator(); } catch (IllegalArgumentException e) { cmp = null; /* disable sorting for this column */ }","preventionTips":["Order by scalar statistics (quantiles, medians) instead of histograms","Keep array-valued outputs out of ORDER BY clauses","Handle comparator-throwing post-aggregators gracefully in frameworks"],"tags":["druid","datasketches","kll","post-aggregator","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"}