{"record":{"id":"d1fc4378ff372368","repo":"apache/druid","slug":"comparing-arrays-of-p-values-is-not-supported","errorCode":null,"errorMessage":"Comparing arrays of p values is not supported","messagePattern":"Comparing arrays of p values is not supported","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"extensions-core/datasketches/src/main/java/org/apache/druid/query/aggregation/datasketches/tuple/ArrayOfDoublesSketchTTestPostAggregator.java","lineNumber":63,"sourceCode":"public class ArrayOfDoublesSketchTTestPostAggregator extends ArrayOfDoublesSketchMultiPostAggregator\n{\n\n  @JsonCreator\n  public ArrayOfDoublesSketchTTestPostAggregator(\n      @JsonProperty(\"name\") final String name,\n      @JsonProperty(\"fields\") List<PostAggregator> fields\n  )\n  {\n    super(name, fields);\n    if (fields.size() != 2) {\n      throw new IAE(\"Illegal number of fields[%d], must be 2\", fields.size());\n    }\n  }\n\n  @Override\n  public Comparator<double[]> getComparator()\n  {\n    throw new IAE(\"Comparing arrays of p values is not supported\");\n  }\n\n  @Override\n  public double[] compute(final Map<String, Object> combinedAggregators)\n  {\n    final ArrayOfDoublesSketch sketch1 = (ArrayOfDoublesSketch) getFields().get(0).compute(combinedAggregators);\n    final ArrayOfDoublesSketch sketch2 = (ArrayOfDoublesSketch) getFields().get(1).compute(combinedAggregators);\n    if (sketch1.getNumValues() != sketch2.getNumValues()) {\n      throw new IAE(\n          \"Sketches have different number of values: %d and %d\",\n          sketch1.getNumValues(),\n          sketch2.getNumValues()\n      );\n    }\n\n    final SummaryStatistics[] stats1 = getStats(sketch1);\n    final SummaryStatistics[] stats2 = getStats(sketch2);\n","sourceCodeStart":45,"sourceCodeEnd":81,"githubUrl":"https://github.com/apache/druid/blob/9b90983fd291f26935af934383ce360473179e4d/extensions-core/datasketches/src/main/java/org/apache/druid/query/aggregation/datasketches/tuple/ArrayOfDoublesSketchTTestPostAggregator.java#L45-L81","documentation":"PostAggregator.getComparator() is used when Druid needs to order post-aggregated values (e.g. in an orderBy spec). The t-test post-aggregator outputs a double[] of p-values, which has no meaningful ordering defined, so it unconditionally throws IAE from getComparator().","triggerScenarios":"Any query or API path that calls getComparator() on an ArrayOfDoublesSketchTTestPostAggregator, e.g. ordering results by this post-aggregator in an OrderBySpec or using it in a topN dimension-spec sort.","commonSituations":"Users attempting to sort/limit results by t-test p-value directly; generic tooling that calls getComparator() on every post-aggregator in the spec.","solutions":["Remove any orderBy/sort clause referencing the tTest post-aggregator","Compute the t-test in a subquery, project the p-value as a column, then sort on that projected column","If ordering is essential, apply the sort in application code after receiving results"],"exampleFix":"// before\nqueryBuilder.addOrderBy(new OrderByColumnSpec(\"ttestPValue\"))\n// after\n// compute t-test in inner query, then sort on projected column in outer query\nGroupByQuery outer = builder.innerQuery(...).addOrderBy(new OrderByColumnSpec(\"pValue\"))","handlingStrategy":"try-catch","validationCode":"if (orderByColumns.stream().anyMatch(c -> \"tTestPValue\".equals(c.getDimension()))) {\n  throw new IllegalArgumentException(\"Sorting by tTest post-aggregator output is not supported\");\n}","typeGuard":null,"tryCatchPattern":"try {\n  return queryClient.run(query);\n} catch (IllegalArgumentException e) {\n  if (e.getMessage() != null && e.getMessage().contains(\"Comparing arrays of p values\")) {\n    return runWithoutOrderBy(query, results -> sortPValuesInApp(results));\n  }\n  throw e;\n}","preventionTips":["Never place array-valued post-aggregators in orderBy specs","Check PostAggregator.getComparator() support (or type) before generating sort specs","Compute t-tests in a subquery and sort on projected scalar columns"],"tags":["druid","datasketches","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"}