{"record":{"id":"92c1d22c79f386a4","repo":"apache/druid","slug":"comparing-histograms-is-not-supported-92c1d2","errorCode":null,"errorMessage":"Comparing histograms is not supported","messagePattern":"Comparing histograms is not supported","errorType":"exception","errorClass":"org.apache.druid.java.util.common.IAE","httpStatus":null,"severity":"error","filePath":"extensions-core/datasketches/src/main/java/org/apache/druid/query/aggregation/datasketches/quantiles/DoublesSketchToHistogramPostAggregator.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/quantiles/DoublesSketchToHistogramPostAggregator.java#L137-L173","documentation":"Like the CDF post-aggregator, the histogram output (double[]) has no defined total ordering, so DoublesSketchToHistogramPostAggregator.getComparator() always throws IllegalArgumentException('Comparing histograms is not supported'). Reaching it means the engine tried to sort or compare results by the histogram column.","triggerScenarios":"Using the histogram post-aggregator's output as an ORDER BY key, topN metric, or limit-spec sorting column in a native query.","commonSituations":"ORDER BY on a histogram column in SQL, topN with the histogram as metric, or groupBy limit spec sorting on the histogram.","solutions":["Sort by a scalar post-aggregator (e.g. a quantile) on the same sketch instead of the histogram.","Remove the sorting reference to the histogram column entirely.","Fetch unsorted rows and sort client-side if needed."],"exampleFix":"// before\n{\"queryType\":\"groupBy\",\"limitSpec\":{\"columns\":[{\"dimension\":\"hist\"}]}} // throws\n// after\n{\"queryType\":\"groupBy\",\"limitSpec\":{\"columns\":[{\"dimension\":\"q50\"}]}} // scalar post-agg","handlingStrategy":"validation","validationCode":"if (sortColumns.stream().anyMatch(histogramPostAggNames::contains)) { throw new IllegalArgumentException(\"Cannot sort by histogram post-aggregator output\"); }","typeGuard":null,"tryCatchPattern":"try { druidClient.run(query); } catch (IllegalArgumentException e) { if (e.getMessage().contains(\"Comparing histograms\")) { /* remove sorting reference and rerun */ } }","preventionTips":["Treat double[] post-agg outputs (CDF, histogram, quantiles) as non-sortable.","Use quantile post-aggs for sort keys."],"tags":["druid","datasketches","unsupported-operation","sorting"],"backgroundTag":"operation-not-supported","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"}