{"record":{"id":"a3df6a43b6a267b8","repo":"apache/druid","slug":"sketches-have-different-number-of-values-d-and","errorCode":null,"errorMessage":"Sketches have different number of values: %d and %d","messagePattern":"Sketches have different number of values: (.+?) and (.+?)","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"extensions-core/datasketches/src/main/java/org/apache/druid/query/aggregation/datasketches/tuple/ArrayOfDoublesSketchTTestPostAggregator.java","lineNumber":72,"sourceCode":"    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\n    final int numberOfValues = sketch1.getNumValues();\n    final double[] pValues = new double[numberOfValues];\n    final TTest test = new TTest();\n    for (int i = 0; i < pValues.length; i++) {\n      pValues[i] = test.tTest(stats1[i], stats2[i]);\n    }\n    return pValues;\n  }\n","sourceCodeStart":54,"sourceCodeEnd":90,"githubUrl":"https://github.com/apache/druid/blob/9b90983fd291f26935af934383ce360473179e4d/extensions-core/datasketches/src/main/java/org/apache/druid/query/aggregation/datasketches/tuple/ArrayOfDoublesSketchTTestPostAggregator.java#L54-L90","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Configure both ArrayOfDoublesSketch aggregator factories with the same numberOfValues","Re-ingest or re-serialize the mismatched sketch data with the correct numValues","Verify which fields the post-aggregator references point to; fix any wrong field name"],"exampleFix":"// before\nnew ArrayOfDoublesSketchAggregatorFactory(\"sk1\", \"metrics\", 2)\nnew ArrayOfDoublesSketchAggregatorFactory(\"sk2\", \"metrics\", 4)\n// after\nnew ArrayOfDoublesSketchAggregatorFactory(\"sk1\", \"metrics\", 4)\nnew ArrayOfDoublesSketchAggregatorFactory(\"sk2\", \"metrics\", 4)","handlingStrategy":"validation","validationCode":"if (sketch1.getNumValues() != sketch2.getNumValues()) {\n  throw new IllegalArgumentException(\"numValues mismatch: \" + sketch1.getNumValues() + \" vs \" + sketch2.getNumValues());\n}\n// or, at query build time:\nif (factory1.getNumValues() != factory2.getNumValues()) { throw ... }","typeGuard":null,"tryCatchPattern":"try {\n  return postAggregator.compute(row);\n} catch (IllegalArgumentException e) {\n  if (e.getMessage() != null && e.getMessage().contains(\"different number of values\")) {\n    throw new SketchSchemaMismatchException(\"Re-ingest sketches with matching numberOfValues\", e);\n  }\n  throw e;\n}","preventionTips":["Keep numberOfValues consistent across all ArrayOfDoublesSketchAggregatorFactory instances in a datasource schema","Verify sketch compatibility programmatically via getNumValues() before pairing","Document schema changes that alter numValues so downstream queries are updated in lockstep"],"tags":["druid","datasketches","query-execution"],"backgroundTag":"incompatible-source-type","analyzedSha":"9b90983fd291f26935af934383ce360473179e4d","analyzedAt":"2026-09-07T13:32:30.957Z","contentChangedAt":"2026-09-07T13:32:30.957Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}