apache/druid · error · org.apache.druid.java.util.common.IAE

Illegal number of fields[%s], must be > 1

Error message

Illegal number of fields[%s], must be > 1

What it means

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.

Source

Thrown at extensions-core/datasketches/src/main/java/org/apache/druid/query/aggregation/datasketches/theta/SketchSetPostAggregator.java:61

  private final SketchHolder.Func func;
  private final int maxSketchSize;

  @JsonCreator
  public SketchSetPostAggregator(
      @JsonProperty("name") String name,
      @JsonProperty("func") String func,
      @JsonProperty("size") Integer maxSize,
      @JsonProperty("fields") List<PostAggregator> fields
  )
  {
    this.name = name;
    this.fields = fields;
    this.func = SketchHolder.Func.valueOf(func);
    this.maxSketchSize = maxSize == null ? SketchAggregatorFactory.DEFAULT_MAX_SKETCH_SIZE : maxSize;
    Util.checkIfIntPowerOf2(this.maxSketchSize, "size");

    if (fields.size() <= 1) {
      throw new IAE("Illegal number of fields[%s], must be > 1", fields.size());
    }
  }

  @Override
  public Set<String> getDependentFields()
  {
    Set<String> dependentFields = new LinkedHashSet<>();
    for (PostAggregator field : fields) {
      dependentFields.addAll(field.getDependentFields());
    }
    return dependentFields;
  }

  @Override
  public Comparator<Object> getComparator()
  {
    return SketchHolder.COMPARATOR;
  }

View on GitHub (pinned to 9b90983fd2)

Solutions

  1. Provide at least two fields in the post-aggregator's fields list
  2. If you only have one sketch, remove the set-operation post-aggregator and aggregate on the single field directly
  3. Validate the fields list size before constructing the aggregator in programmatic query building

Example fix

// before
new SketchSetPostAggregator("uni", "UNION", null, Collections.singletonList("a")); // throws
// after
new SketchSetPostAggregator("uni", "UNION", null, Arrays.asList("a", "b"));
Defensive patterns

Strategy: validation

Validate before calling

if (fields == null || fields.size() <= 1) {
  throw new IllegalArgumentException("SketchSetPostAggregator needs more than 1 field");
}

Type guard

boolean hasMultipleFields(List<PostAggregator> fields) {
  return fields != null && fields.size() > 1;
}

Try / catch

try {
  SketchSetPostAggregator agg = new SketchSetPostAggregator(name, func, maxSize, fields);
} catch (IllegalArgumentException e) {
  // fix query spec: supply >= 2 fields or drop the post-aggregator
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


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