apache/druid · error · IllegalArgumentException

Comparing arrays of estimate values is not supported

Error message

Comparing arrays of estimate values is not supported

What it means

ArrayOfDoublesSketchToMetricsSumEstimatePostAggregator emits a double[] (estimate plus error bounds of the summed metrics). Arrays of estimate values have no defined natural order, so getComparator() throws IAE unconditionally.

Solutions

  1. Sort on a single-value estimate post-aggregator or a plain numeric aggregator instead
  2. Remove any ordering spec referencing this post-aggregator
  3. Apply custom ordering in application code after fetching results

Example fix

// before
.addOrderBy(new OrderByColumnSpec("metricsSumEstimate"))
// after
.addOrderBy(new OrderByColumnSpec("sumEstimate")) // single-value post-agg
Defensive patterns

Strategy: try-catch

Validate before calling

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

Try / catch

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

Prevention

When it happens

Trigger: Calling getComparator(), e.g. using this post-aggregator as a sort key in an orderBy spec or in tooling that requests comparators for all post-aggregators in a query.

Common situations: Users sorting query output by the sum-estimate array; generic framework code sorting post-aggregator columns.

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/17db1c4c59e818b8. Report an issue: GitHub.

Appendix: source

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

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

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

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

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

View on GitHub (pinned to 9b90983fd2)