{"record":{"id":"d1bcefe209c76ab4","repo":"apache/druid","slug":"comparing-arrays-of-quantiles-is-not-supported-d1bcef","errorCode":null,"errorMessage":"Comparing arrays of quantiles is not supported","messagePattern":"Comparing arrays of quantiles 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/DoublesSketchToQuantilesPostAggregator.java","lineNumber":97,"sourceCode":"    return fractions;\n  }\n\n  @Override\n  public Object compute(final Map<String, Object> combinedAggregators)\n  {\n    final DoublesSketch sketch = (DoublesSketch) 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/quantiles/DoublesSketchToQuantilesPostAggregator.java#L79-L115","documentation":"DoublesSketchToQuantilesPostAggregator returns an array of quantile values (double[]). Since arrays of quantiles have no natural ordering, getComparator() throws IllegalArgumentException('Comparing arrays of quantiles is not supported') whenever the engine requests a comparator for this output.","triggerScenarios":"Referencing the quantiles post-aggregator output in an ORDER BY clause, as a topN metric, or in a groupBy limitSpec sorting column.","commonSituations":"Trying to order query results by the quantiles array; copying a limitSpec that named the sketch column without realizing the post-agg output is an array.","solutions":["Order by a single scalar value instead (e.g. DoublesSketchToQuantilePostAggregator for one fraction).","Remove the sorting spec that references the quantiles post-aggregator.","Sort client-side after retrieving results."],"exampleFix":"// before\n{\"orderByColumn\":\"quantiles\"} // array output, throws\n// after\n{\"orderByColumn\":\"median\"} // quantilesDoublesSketchToQuantile post-agg (scalar)","handlingStrategy":"validation","validationCode":"if (orderByColumns.contains(quantilesPostAggName)) { throw new IllegalArgumentException(\"Cannot ORDER BY quantiles array output; use a scalar quantile post-agg\"); }","typeGuard":null,"tryCatchPattern":"try { druidClient.run(query); } catch (IllegalArgumentException e) { if (e.getMessage().contains(\"Comparing arrays of quantiles\")) { /* replace sort key */ } }","preventionTips":["Use DoublesSketchToQuantile (singular) when a sortable scalar is needed.","Keep quantiles array output out of limitSpec/orderBy."],"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"}