apache/druid · error · IllegalArgumentException

Comparing arrays of variance values is not supported

Error message

Comparing arrays of variance values is not supported

What it means

ArrayOfDoublesSketchToVariancesPostAggregator outputs a double[] of per-column variances. Variance arrays have no defined comparison, so getComparator() throws IAE unconditionally to block sorting on this output.

Solutions

  1. Sort on an individual variance value exposed via a numeric post-aggregator or expression
  2. Remove ordering clauses on this post-aggregator
  3. Rank in application code with a custom comparator

Example fix

// before
.addOrderBy(new OrderByColumnSpec("variances"))
// after
.addOrderBy(new OrderByColumnSpec("varianceOfFirst")) // numeric expression
Defensive patterns

Strategy: try-catch

Validate before calling

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

Try / catch

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

Prevention

When it happens

Trigger: Calling getComparator(), e.g. referencing this post-aggregator in an orderBy spec or generic code that obtains comparators for all post-aggregators.

Common situations: Users ranking rows by variance vectors; query builders that attach sort clauses to 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/9bebf2904c4d7de0. Report an issue: GitHub.

Appendix: source

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

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

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

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

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

}

View on GitHub (pinned to 9b90983fd2)