{"record":{"id":"b08c60de13a38335","repo":"apache/druid","slug":"comparing-histograms-is-not-supported-b08c60","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/DoublesSketchToCDFPostAggregator.java","lineNumber":97,"sourceCode":"    return ColumnType.DOUBLE_ARRAY;\n  }\n\n  @JsonProperty\n  public PostAggregator getField()\n  {\n    return field;\n  }\n\n  @JsonProperty\n  public double[] getSplitPoints()\n  {\n    return splitPoints;\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        \"}\";\n  }\n","sourceCodeStart":79,"sourceCodeEnd":115,"githubUrl":"https://github.com/apache/druid/blob/9b90983fd291f26935af934383ce360473179e4d/extensions-core/datasketches/src/main/java/org/apache/druid/query/aggregation/datasketches/quantiles/DoublesSketchToCDFPostAggregator.java#L79-L115","documentation":"DoublesSketchToCDFPostAggregator produces a cumulative distribution histogram (double[]). Druid's PostAggregator contract requires getComparator() for sorting/comparing results, but comparing two CDF arrays has no meaningful ordering, so the implementation always throws IllegalArgumentException('Comparing histograms is not supported').","triggerScenarios":"Using DoublesSketchToCDFPostAggregator in any context where the engine requests its comparator: ORDER BY on the post-aggregator output, topN metric on it, or sorting via having/limit specs that compare the column.","commonSituations":"Trying to ORDER BY a CDF/histogram column in SQL or native topN, or using the histogram as a sorting metric in a groupBy limit spec.","solutions":["Remove the ORDER BY / topN metric reference on the CDF post-aggregator; sort by the underlying doublesSketch aggregation's scalar post-agg or another scalar column instead.","Sort by an accompanying scalar post-aggregator (e.g. quantile) derived from the same sketch.","Do client-side sorting after retrieving rows."],"exampleFix":"// before\n{\"queryType\":\"topN\",\"metric\":\"myCdf\", ...} // throws\n// after\n{\"queryType\":\"topN\",\"metric\":\"myQuantile\", // scalar post-agg on same sketch\n \"postAggregators\":[{\"type\":\"quantilesDoublesSketchToQuantiles\", ...}]}","handlingStrategy":"validation","validationCode":"if (query.getOrderBy() != null && query.getOrderBy().contains(\"cdfPostAgg\")) { throw new IllegalArgumentException(\"Cannot order by DoublesSketchToCDF output\"); }","typeGuard":null,"tryCatchPattern":"try { druidClient.run(query); } catch (IllegalArgumentException e) { if (e.getMessage().contains(\"Comparing histograms\")) { /* strip ORDER BY on CDF and rerun */ } }","preventionTips":["Never reference array-valued post-aggregators in ORDER BY/topN metrics.","Order by scalar quantile post-aggs derived from the same sketch."],"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"}