{"record":{"id":"9330ce7da33faa1c","repo":"apache/druid","slug":"illegal-number-of-fields-s-must-be-1","errorCode":null,"errorMessage":"Illegal number of fields[%s], must be > 1","messagePattern":"Illegal number of fields\\[(.+?)\\], must be > 1","errorType":"validation","errorClass":"org.apache.druid.java.util.common.IAE","httpStatus":null,"severity":"error","filePath":"extensions-core/datasketches/src/main/java/org/apache/druid/query/aggregation/datasketches/theta/SketchSetPostAggregator.java","lineNumber":61,"sourceCode":"  private final SketchHolder.Func func;\n  private final int maxSketchSize;\n\n  @JsonCreator\n  public SketchSetPostAggregator(\n      @JsonProperty(\"name\") String name,\n      @JsonProperty(\"func\") String func,\n      @JsonProperty(\"size\") Integer maxSize,\n      @JsonProperty(\"fields\") List<PostAggregator> fields\n  )\n  {\n    this.name = name;\n    this.fields = fields;\n    this.func = SketchHolder.Func.valueOf(func);\n    this.maxSketchSize = maxSize == null ? SketchAggregatorFactory.DEFAULT_MAX_SKETCH_SIZE : maxSize;\n    Util.checkIfIntPowerOf2(this.maxSketchSize, \"size\");\n\n    if (fields.size() <= 1) {\n      throw new IAE(\"Illegal number of fields[%s], must be > 1\", fields.size());\n    }\n  }\n\n  @Override\n  public Set<String> getDependentFields()\n  {\n    Set<String> dependentFields = new LinkedHashSet<>();\n    for (PostAggregator field : fields) {\n      dependentFields.addAll(field.getDependentFields());\n    }\n    return dependentFields;\n  }\n\n  @Override\n  public Comparator<Object> getComparator()\n  {\n    return SketchHolder.COMPARATOR;\n  }","sourceCodeStart":43,"sourceCodeEnd":79,"githubUrl":"https://github.com/apache/druid/blob/9b90983fd291f26935af934383ce360473179e4d/extensions-core/datasketches/src/main/java/org/apache/druid/query/aggregation/datasketches/theta/SketchSetPostAggregator.java#L43-L79","documentation":"SketchSetPostAggregator is a set operation over multiple theta sketch fields (union, intersect, not), so it requires strictly more than one input field to be meaningful. The constructor rejects a fields list of size <= 1 with an IAE during query validation/JSON parsing.","triggerScenarios":"Constructing new SketchSetPostAggregator(name, func, maxSize, fields) with null or a list of 0/1 fields, or submitting query JSON whose thetaSketch set-operation post-aggregator has a single (or missing) 'fields' entry.","commonSituations":"Hand-written query JSON with only one field in a sketchSet post-aggregator; programmatic query building that accidentally filters fields down to one; SQL planner emitting a degenerate single-input set operation.","solutions":["Provide at least two fields in the post-aggregator's fields list","If you only have one sketch, remove the set-operation post-aggregator and aggregate on the single field directly","Validate the fields list size before constructing the aggregator in programmatic query building"],"exampleFix":"// before\nnew SketchSetPostAggregator(\"uni\", \"UNION\", null, Collections.singletonList(\"a\")); // throws\n// after\nnew SketchSetPostAggregator(\"uni\", \"UNION\", null, Arrays.asList(\"a\", \"b\"));","handlingStrategy":"validation","validationCode":"if (fields == null || fields.size() <= 1) {\n  throw new IllegalArgumentException(\"SketchSetPostAggregator needs more than 1 field\");\n}","typeGuard":"boolean hasMultipleFields(List<PostAggregator> fields) {\n  return fields != null && fields.size() > 1;\n}","tryCatchPattern":"try {\n  SketchSetPostAggregator agg = new SketchSetPostAggregator(name, func, maxSize, fields);\n} catch (IllegalArgumentException e) {\n  // fix query spec: supply >= 2 fields or drop the post-aggregator\n}","preventionTips":["Validate post-aggregator specs before submitting queries","Never hand-write single-field sketchSet post-aggregators","Check programmatically built field lists after filtering logic"],"tags":["java","datasketches","post-aggregator"],"backgroundTag":"invalid-constructor-argument","analyzedSha":"9b90983fd291f26935af934383ce360473179e4d","analyzedAt":"2026-09-07T13:32:30.957Z","contentChangedAt":"2026-09-07T13:32:30.957Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}