{"record":{"id":"8b93fc3c9025254e","repo":"apache/druid","slug":"illegal-number-of-fields-d-must-be-2","errorCode":null,"errorMessage":"Illegal number of fields[%d], must be 2","messagePattern":"Illegal number of fields\\[(.+?)\\], must be 2","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":56,"sourceCode":"import java.util.Map;\n\n/**\n * Performs Student's t-test and returns a list of p-values given two instances of {@link ArrayOfDoublesSketch}.\n * The result will be N double values, where N is the number of double values kept in the sketch per key.\n * See <a href=http://commons.apache.org/proper/commons-math/javadocs/api-3.4/org/apache/commons/math3/stat/inference/TTest.html>Student's t-test</a>\n */\npublic class ArrayOfDoublesSketchTTestPostAggregator extends ArrayOfDoublesSketchMultiPostAggregator\n{\n\n  @JsonCreator\n  public ArrayOfDoublesSketchTTestPostAggregator(\n      @JsonProperty(\"name\") final String name,\n      @JsonProperty(\"fields\") List<PostAggregator> fields\n  )\n  {\n    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(),","sourceCodeStart":38,"sourceCodeEnd":74,"githubUrl":"https://github.com/apache/druid/blob/9b90983fd291f26935af934383ce360473179e4d/extensions-core/datasketches/src/main/java/org/apache/druid/query/aggregation/datasketches/tuple/ArrayOfDoublesSketchTTestPostAggregator.java#L38-L74","documentation":"The ArrayOfDoublesSketchTTestPostAggregator performs a two-sample Student's t-test, which by definition requires exactly two sketch inputs. The constructor validates the 'fields' list at query-spec parse time and throws this IllegalArgumentException when the count is anything other than 2, failing fast before query execution.","triggerScenarios":"Submitting a native query or SQL query whose JSON post-aggregator spec for 'tTest' supplies fewer than 2 fields (e.g. only one sketch aggregator reference) or more than 2 fields (e.g. three sketch references).","commonSituations":"Hand-written query JSON missing one field; programmatic query builders appending fields in a loop; copying a t-test spec from an ANOVA-style example with multiple sketches; users assuming t-test generalizes to >2 samples.","solutions":["Ensure the post-aggregator 'fields' list contains exactly two ArrayOfDoublesSketch aggregator references","If comparing more than two sketches, run separate tTest post-aggregators for each pair instead of one with N fields","Validate the count of postAggregator.fields in client code before deserializing/submitting the query"],"exampleFix":"// before\n\"postAggregators\": [{ \"type\": \"tTest\", \"fields\": [\"sketchA\"] }]\n// after\n\"postAggregators\": [{ \"type\": \"tTest\", \"fields\": [\"sketchA\", \"sketchB\"] }]","handlingStrategy":"validation","validationCode":"List<PostAggregator> fields = postAggregatorSpec.get(\"fields\");\nif (fields == null || fields.size() != 2) {\n  throw new IllegalArgumentException(\"tTest post-aggregator requires exactly 2 fields, got: \" + (fields == null ? 0 : fields.size()));\n}","typeGuard":null,"tryCatchPattern":"try {\n  queryClient.run(query);\n} catch (IllegalArgumentException e) {\n  if (e.getMessage() != null && e.getMessage().contains(\"Illegal number of fields\")) {\n    throw new QuerySpecException(\"tTest post-aggregator must have exactly 2 sketch fields\", e);\n  }\n  throw e;\n}","preventionTips":["Always declare exactly two ArrayOfDoublesSketch aggregators before referencing them in a tTest post-aggregator","Validate post-aggregator field counts in query-builder helpers before serialization","Never loop N sketches into one tTest; create pairwise tTest post-aggregators instead"],"tags":["druid","datasketches","query-validation"],"backgroundTag":"invalid-argument-value","analyzedSha":"9b90983fd291f26935af934383ce360473179e4d","analyzedAt":"2026-09-07T13:32:30.957Z","contentChangedAt":"2026-09-07T13:32:30.957Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}