{"record":{"id":"6f31dbe9bda2c7f8","repo":"apache/druid","slug":"comparing-arrays-of-quantiles-is-not-supported-6f31db","errorCode":null,"errorMessage":"Comparing arrays of quantiles is not supported","messagePattern":"Comparing arrays of quantiles 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/KllFloatsSketchToQuantilesPostAggregator.java","lineNumber":97,"sourceCode":"    return fractions;\n  }\n\n  @Override\n  public Object compute(final Map<String, Object> combinedAggregators)\n  {\n    final KllFloatsSketch sketch = (KllFloatsSketch) field.compute(combinedAggregators);\n    if (sketch.isEmpty()) {\n      final float[] quantiles = new float[fractions.length];\n      Arrays.fill(quantiles, Float.NaN);\n      return quantiles;\n    }\n    return sketch.getQuantiles(fractions);\n  }\n\n  @Override\n  public Comparator<float[]> getComparator()\n  {\n    throw new IAE(\"Comparing arrays of quantiles 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        \", fractions=\" + Arrays.toString(fractions) +\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/KllFloatsSketchToQuantilesPostAggregator.java#L79-L115","documentation":"KLL_SKETCH_TO_QUANTILES returns an array of floats (one quantile per requested fraction). Arrays of quantiles have no defined total ordering, so getComparator() intentionally throws IAE if Druid ever needs to compare two results.","triggerScenarios":"Using the KLL_SKETCH_TO_QUANTILES post-aggregator in an ORDER BY expression, a having clause, or any API path that calls getComparator() on it.","commonSituations":"Trying to sort results by the quantiles array, or building queries programmatically where a comparator is requested for every post-aggregator.","solutions":["Order by a scalar column or a single-quantile post-aggregator (KLL_SKETCH_TO_QUANTILE) instead.","Remove the post-aggregator from any comparison/ordering context and post-process the array client-side.","If you need a single comparable value, request a single fraction and index into the returned array."],"exampleFix":"// before\n... ORDER BY \"quantiles_output\"\n\n// after\n... ORDER BY quantileExpression -- e.g. KLL_SKETCH_TO_QUANTILE with a single fraction","handlingStrategy":"validation","validationCode":"if (postAgg instanceof KllFloatsSketchToQuantilesPostAggregator && requiresComparator(querySpec)) {\n  throw new IllegalArgumentException(\"Quantiles array is not comparable; order by a single quantile instead\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use KLL_SKETCH_TO_QUANTILE (single value) when ordering is needed.","Never sort by multi-value arrays in Druid.","Post-process quantile arrays client-side."],"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-17T15:17:12.973Z"}