{"record":{"id":"4848fb637a06b1d0","repo":"apache/druid","slug":"comparing-arrays-of-quantiles-is-not-supported-4848fb","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/KllDoublesSketchToQuantilesPostAggregator.java","lineNumber":97,"sourceCode":"    return fractions;\n  }\n\n  @Override\n  public Object compute(final Map<String, Object> combinedAggregators)\n  {\n    final KllDoublesSketch sketch = (KllDoublesSketch) field.compute(combinedAggregators);\n    if (sketch.isEmpty()) {\n      final double[] quantiles = new double[fractions.length];\n      Arrays.fill(quantiles, Double.NaN);\n      return quantiles;\n    }\n    return sketch.getQuantiles(fractions);\n  }\n\n  @Override\n  public Comparator<double[]> 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/KllDoublesSketchToQuantilesPostAggregator.java#L79-L115","documentation":"KllDoublesSketchToQuantilesPostAggregator.getComparator always throws IllegalArgumentException because an array of quantile values has no defined comparison semantics. The method exists to satisfy the post-aggregator interface but intentionally rejects any ordering request.","triggerScenarios":"Ordering or ranking on the output of kllDoublesSketchToQuantiles, e.g. ORDER BY on its result column, or framework code that calls getComparator() on all post-aggregators.","commonSituations":"Trying to sort results by quantile arrays; building generic UI sort controls over all post-aggregator columns; SQL queries that attempt to order on array-typed post-aggregator output.","solutions":["Order by a specific scalar quantile instead: use kllDoublesSketchToQuantile (singular) with a single fraction","Avoid ORDER BY on the quantiles array column","Skip comparison-requiring paths for this post-aggregator in generic processing code"],"exampleFix":"// before\n{\"type\":\"kllDoublesSketchToQuantiles\",\"name\":\"qs\",\"field\":f,\"fractions\":[0.5]} ... ORDER BY qs\n// after\n{\"type\":\"kllDoublesSketchToQuantile\",\"name\":\"median\",\"field\":f,\"fraction\":0.5} ... ORDER BY median","handlingStrategy":"validation","validationCode":"if (postAgg instanceof KllDoublesSketchToQuantilesPostAggregator) {\n  throw new IllegalArgumentException(\"Quantiles array output is not sortable; use kllDoublesSketchToQuantile\");\n}","typeGuard":null,"tryCatchPattern":"try { cmp = postAgg.getComparator(); } catch (IllegalArgumentException e) { cmp = null; }","preventionTips":["Prefer kllDoublesSketchToQuantile (single fraction) when ordering is needed","Avoid ORDER BY on multi-value quantile arrays","Flag array-valued post-aggregators as non-sortable in tooling"],"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"}