apache/druid · error · IllegalArgumentException

Comparing arrays of mean values is not supported

Error message

Comparing arrays of mean values is not supported

What it means

ArrayOfDoublesSketchToMeansPostAggregator outputs a double[] of per-value-column means. Since multi-element mean arrays have no defined comparison, getComparator() throws IAE unconditionally; sorting on this post-aggregator is unsupported.

Solutions

  1. Sort by an individual mean extracted via a different post-aggregator or expression (e.g. element access)
  2. Remove the ordering clause on this post-aggregator
  3. Perform ranking in application code with a custom comparator

Example fix

// before
.addOrderBy(new OrderByColumnSpec("means"))
// after
.addOrderBy(new OrderByColumnSpec("meanOfFirstValue")) // numeric post-agg/expression
Defensive patterns

Strategy: try-catch

Validate before calling

if (orderByColumns.stream().anyMatch(c -> "means".equals(c.getDimension()))) {
  throw new IllegalArgumentException("Cannot order by means array output");
}

Try / catch

try {
  return queryClient.run(query);
} catch (IllegalArgumentException e) {
  if (e.getMessage() != null && e.getMessage().contains("mean values")) {
    return runQueryWithAlternateOrdering(query, "meanOfFirstValue");
  }
  throw e;
}

Prevention

When it happens

Trigger: Calling getComparator(), typically when results are ordered by this post-aggregator in a groupBy orderBy spec or when framework code asks for a comparator for every post-aggregator.

Common situations: Users attempting to rank rows by mean vectors; generic query builders that add sort specs on all post-aggregators.

Understand the failure class

Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.

Related errors


AI-assisted analysis of apache/druid@9b90983fd2 (2026-09-07). Data as JSON: /api/errors/62102f074a9b128b. Report an issue: GitHub.

Appendix: source

Thrown at extensions-core/datasketches/src/main/java/org/apache/druid/query/aggregation/datasketches/tuple/ArrayOfDoublesSketchToMeansPostAggregator.java:81

      for (int i = 0; i < values.length; i++) {
        stats[i].addValue(values[i]);
      }
    }
    final double[] means = new double[sketch.getNumValues()];
    Arrays.setAll(means, i -> stats[i].getMean());
    return means;
  }

  @Override
  public ColumnType getType(ColumnInspector signature)
  {
    return ColumnType.DOUBLE_ARRAY;
  }

  @Override
  public Comparator<double[]> getComparator()
  {
    throw new IAE("Comparing arrays of mean values is not supported");
  }

  @Override
  public byte[] getCacheKey()
  {
    return new CacheKeyBuilder(AggregatorUtil.ARRAY_OF_DOUBLES_SKETCH_TO_MEANS_CACHE_TYPE_ID)
        .appendCacheable(getField())
        .build();
  }

}

View on GitHub (pinned to 9b90983fd2)