apache/druid · error · IllegalArgumentException

Sketches have different number of values: %d and %d

Error message

Sketches have different number of values: %d and %d

What it means

A two-sample t-test requires both sketches to have the same number of values per summary row. compute() checks getNumValues() on both ArrayOfDoublesSketch instances and throws IAE when they differ, because the paired t-test math cannot operate on mismatched vectors.

Source

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

    super(name, fields);
    if (fields.size() != 2) {
      throw new IAE("Illegal number of fields[%d], must be 2", fields.size());
    }
  }

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

  @Override
  public double[] compute(final Map<String, Object> combinedAggregators)
  {
    final ArrayOfDoublesSketch sketch1 = (ArrayOfDoublesSketch) getFields().get(0).compute(combinedAggregators);
    final ArrayOfDoublesSketch sketch2 = (ArrayOfDoublesSketch) getFields().get(1).compute(combinedAggregators);
    if (sketch1.getNumValues() != sketch2.getNumValues()) {
      throw new IAE(
          "Sketches have different number of values: %d and %d",
          sketch1.getNumValues(),
          sketch2.getNumValues()
      );
    }

    final SummaryStatistics[] stats1 = getStats(sketch1);
    final SummaryStatistics[] stats2 = getStats(sketch2);

    final int numberOfValues = sketch1.getNumValues();
    final double[] pValues = new double[numberOfValues];
    final TTest test = new TTest();
    for (int i = 0; i < pValues.length; i++) {
      pValues[i] = test.tTest(stats1[i], stats2[i]);
    }
    return pValues;
  }

View on GitHub (pinned to 9b90983fd2)

Solutions

  1. Configure both ArrayOfDoublesSketch aggregator factories with the same numberOfValues
  2. Re-ingest or re-serialize the mismatched sketch data with the correct numValues
  3. Verify which fields the post-aggregator references point to; fix any wrong field name

Example fix

// before
new ArrayOfDoublesSketchAggregatorFactory("sk1", "metrics", 2)
new ArrayOfDoublesSketchAggregatorFactory("sk2", "metrics", 4)
// after
new ArrayOfDoublesSketchAggregatorFactory("sk1", "metrics", 4)
new ArrayOfDoublesSketchAggregatorFactory("sk2", "metrics", 4)
Defensive patterns

Strategy: validation

Validate before calling

if (sketch1.getNumValues() != sketch2.getNumValues()) {
  throw new IllegalArgumentException("numValues mismatch: " + sketch1.getNumValues() + " vs " + sketch2.getNumValues());
}
// or, at query build time:
if (factory1.getNumValues() != factory2.getNumValues()) { throw ... }

Try / catch

try {
  return postAggregator.compute(row);
} catch (IllegalArgumentException e) {
  if (e.getMessage() != null && e.getMessage().contains("different number of values")) {
    throw new SketchSchemaMismatchException("Re-ingest sketches with matching numberOfValues", e);
  }
  throw e;
}

Prevention

When it happens

Trigger: Calling compute() (during query execution) where field 0 and field 1 evaluate to ArrayOfDoublesSketch objects created with different numValues settings, e.g. sketch aggregators configured with different 'numberOfValues' parameters or created against different metric arrays.

Common situations: Two sub-aggregations built with different ArrayOfDoublesSketchAggregatorFactory numValues configs; sketches produced by different ingestion jobs with changed schema; copy-pasted query where one field points at the wrong aggregator.

Understand the failure class

Background: "is not a compatible type" / "cannot merge" errors: when a value's type doesn't match what the library requires — this error's family across 65 libraries.

Related errors


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