{"record":{"id":"1080259cdbf3b9dd","repo":"apache/druid","slug":"illegal-number-of-fields-d-must-be-1","errorCode":null,"errorMessage":"Illegal number of fields[%d], must be > 1","messagePattern":"Illegal number of fields\\[(.+?)\\], must be > 1","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"extensions-core/datasketches/src/main/java/org/apache/druid/query/aggregation/datasketches/tuple/ArrayOfDoublesSketchSetOpPostAggregator.java","lineNumber":67,"sourceCode":"  private final int numberOfValues;\n\n  @JsonCreator\n  public ArrayOfDoublesSketchSetOpPostAggregator(\n      @JsonProperty(\"name\") final String name,\n      @JsonProperty(\"operation\") final String operation,\n      @JsonProperty(\"nominalEntries\") @Nullable final Integer nominalEntries,\n      @JsonProperty(\"numberOfValues\") @Nullable final Integer numberOfValues,\n      @JsonProperty(\"fields\") List<PostAggregator> fields\n  )\n  {\n    super(name, fields);\n    this.operation = ArrayOfDoublesSketchOperations.Operation.valueOf(operation);\n    this.nominalEntries = nominalEntries == null ? ThetaUtil.DEFAULT_NOMINAL_ENTRIES : nominalEntries;\n    this.numberOfValues = numberOfValues == null ? 1 : numberOfValues;\n    Util.checkIfIntPowerOf2(this.nominalEntries, \"size\");\n\n    if (fields.size() <= 1) {\n      throw new IAE(\"Illegal number of fields[%d], must be > 1\", fields.size());\n    }\n  }\n\n  @Override\n  public Comparator<ArrayOfDoublesSketch> getComparator()\n  {\n    return ArrayOfDoublesSketchAggregatorFactory.COMPARATOR;\n  }\n\n  @Override\n  public ArrayOfDoublesSketch compute(final Map<String, Object> combinedAggregators)\n  {\n    final ArrayOfDoublesSketch[] sketches = new ArrayOfDoublesSketch[getFields().size()];\n    for (int i = 0; i < sketches.length; i++) {\n      sketches[i] = (ArrayOfDoublesSketch) getFields().get(i).compute(combinedAggregators);\n    }\n    return operation.apply(nominalEntries, numberOfValues, sketches);\n  }","sourceCodeStart":49,"sourceCodeEnd":85,"githubUrl":"https://github.com/apache/druid/blob/9b90983fd291f26935af934383ce360473179e4d/extensions-core/datasketches/src/main/java/org/apache/druid/query/aggregation/datasketches/tuple/ArrayOfDoublesSketchSetOpPostAggregator.java#L49-L85","documentation":"ArrayOfDoublesSketchSetOpPostAggregator's constructor validates that the set operation (UNION, INTERSECT, NOT) has more than one input field, since set operations are defined between multiple sketches. A field list of size <= 1 triggers IAE.","triggerScenarios":"Constructing the post-aggregator (programmatically or via JSON query parsing) with fields omitted, empty, or containing exactly one entry.","commonSituations":"Hand-written native JSON queries with a typo in the fields key; programmatic query builders adding a single field; a NOT operation mistakenly given only one field even though NOT allows one at runtime (constructor still demands >1).","solutions":["Provide at least two fields in the post-aggregator's fields array","For a single-input NOT operation, use a different construction path or wrap the single sketch appropriately","Validate the JSON query's postAggregator spec before submission"],"exampleFix":"// before\nnew ArrayOfDoublesSketchSetOpPostAggregator(\"set_op\", \"INTERSECT\", List.of(fieldA), 16384, 1);\n// after\nnew ArrayOfDoublesSketchSetOpPostAggregator(\"set_op\", \"INTERSECT\", List.of(fieldA, fieldB), 16384, 1);","handlingStrategy":"validation","validationCode":"if (fields == null || fields.size() <= 1) {\n  throw new IllegalArgumentException(\"Set op post-aggregator requires > 1 field, got \"\n      + (fields == null ? 0 : fields.size()));\n}","typeGuard":"boolean hasEnoughFields = fields != null && fields.size() > 1;","tryCatchPattern":"try {\n  new ArrayOfDoublesSketchSetOpPostAggregator(name, operation, fields, nominalEntries, numValues);\n} catch (IllegalArgumentException e) {\n  if (e.getMessage().startsWith(\"Illegal number of fields\")) {\n    // fix the query spec / add more fields\n  } else {\n    throw e;\n  }\n}","preventionTips":["Validate postAggregator JSON specs (fields list length) before submitting queries","Ensure programmatic query builders always add two or more fields","Double-check field key names in hand-written native queries"],"tags":["druid","datasketches","illegal-argument","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-14T11:17:12.474Z"}