{"record":{"id":"cb5caf3f7bbb2043","repo":"apache/druid","slug":"comparing-histograms-is-not-supported-cb5caf","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/KllFloatsSketchToCDFPostAggregator.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 float[] 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/kll/KllFloatsSketchToCDFPostAggregator.java#L79-L115","documentation":"The KLL sketch to CDF post-aggregator produces a cumulative distribution array of doubles, which has no meaningful ordering. Druid's post-aggregator interface requires getComparator() to be implemented; this class intentionally throws IAE because two histograms/CDFs cannot be compared. It surfaces only if a query tries to order, compare, or use this post-aggregator where a Comparator is required.","triggerScenarios":"Using KLL_SKETCH_TO_CDF as an ORDER BY expression, in a comparison, or anywhere Druid calls PostAggregator.getComparator() (e.g. order-by specs, having clauses referencing the post-aggregator, or nested aggregations that need comparison).","commonSituations":"Developers write an ORDER BY on the output column computed by the CDF post-aggregator, or build a query generator that automatically assigns comparators to all post-aggregators, unaware that array-valued post-aggregators (CDFs, histograms, quantiles) are not comparable.","solutions":["Remove any ORDER BY / sort expression that references the CDF post-aggregator output; sort by a scalar column instead.","If sorting is needed, compute a scalar value (e.g. a specific CDF rank via KLL_SKETCH_TO_QUANTILE) and order on that.","Do not use this post-aggregator in contexts that require a Comparator (having-clause comparisons, ordered aggregations)."],"exampleFix":"// before\n... ORDER BY \"cdf_output\" ASC\n\n// after\n... ORDER BY \"myScalarColumn\" ASC","handlingStrategy":"validation","validationCode":"if (postAgg instanceof KllFloatsSketchToCDFPostAggregator && requiresComparator(querySpec)) {\n  throw new IllegalArgumentException(\"KLL_SKETCH_TO_CDF output is not comparable; do not use in ORDER BY/having\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never place array-valued post-aggregators (CDF, histogram, quantiles) in ORDER BY or having clauses.","Order by a scalar quantile expression when a ranking is needed.","Review generated queries for auto-assigned comparators on post-aggregators."],"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"}