apache/druid · error · java.lang.IllegalArgumentException
A-Not-B requires at least 1 sketch
Error message
A-Not-B requires at least 1 sketch
What it means
sketchSetOperation() implements the NOT (A-Not-B) set operation, which mathematically needs at least one sketch (the A side). When the holders array is empty, there is nothing to compute, so it throws an IllegalArgumentException. Other operations (UNION/INTERSECT) tolerate empty inputs but NOT does not.
Source
Thrown at extensions-core/datasketches/src/main/java/org/apache/druid/query/aggregation/datasketches/theta/SketchHolder.java:297
//"true" returns an ordered sketch but slower to compute. advantage of ordered sketch
//is that they are faster to "union" later but given that this method is used in
//the final stages of query processing, ordered sketch would be of no use.
switch (func) {
case UNION:
Union union = (Union) SetOperation.builder().setNominalEntries(sketchSize).build(Family.UNION);
for (Object o : holders) {
((SketchHolder) o).updateUnion(union);
}
return SketchHolder.of(union);
case INTERSECT:
Intersection intersection = (Intersection) SetOperation.builder().setNominalEntries(sketchSize).build(Family.INTERSECTION);
for (Object o : holders) {
intersection.intersect(((SketchHolder) o).getSketch());
}
return SketchHolder.of(intersection.getResult(false, null));
case NOT:
if (holders.length < 1) {
throw new IllegalArgumentException("A-Not-B requires at least 1 sketch");
}
if (holders.length == 1) {
return (SketchHolder) holders[0];
}
Sketch result = ((SketchHolder) holders[0]).getSketch();
for (int i = 1; i < holders.length; i++) {
AnotB anotb = (AnotB) SetOperation.builder().setNominalEntries(sketchSize).build(Family.A_NOT_B);
result = anotb.aNotB(result, ((SketchHolder) holders[i]).getSketch());
}
return SketchHolder.of(result);
default:
throw new IllegalArgumentException("Unknown sketch operation " + func);
}
}
/**View on GitHub (pinned to 9b90983fd2)
Solutions
- Ensure at least one input sketch/field is provided for the NOT post-aggregator
- Validate fields.size() >= 1 when constructing the SketchSetPostAggregator or building the query programmatically
- If A may legitimately be absent, guard the call and return null or a default empty sketch instead of invoking NOT
Example fix
// before
Object[] holders = collectFields(); // may be empty
SketchHolder result = SketchHolder.sketchSetOperation(SketchHolder.Func.NOT, size, holders);
// after
if (holders.length < 1) {
throw new IllegalArgumentException("NOT requires at least one input sketch field");
}
SketchHolder result = SketchHolder.sketchSetOperation(SketchHolder.Func.NOT, size, holders); Defensive patterns
Strategy: validation
Validate before calling
if (holders == null || holders.length < 1) {
throw new IllegalArgumentException("NOT operation requires at least 1 input sketch");
} Type guard
boolean hasInputs(Object[] holders) {
return holders != null && holders.length >= 1;
} Try / catch
try {
SketchHolder r = SketchHolder.sketchSetOperation(Func.NOT, size, holders);
} catch (IllegalArgumentException e) {
// handle empty-input case: return null or empty sketch holder
} Prevention
- Always validate field counts when building SketchSetPostAggregators programmatically
- Check query JSON post-aggregator fields arrays are non-empty
- Resolve field dependencies before executing set operations
When it happens
Trigger: Calling SketchHolder.sketchSetOperation(Func.NOT, size) with an empty Object[] holders array — e.g. a SketchSetPostAggregator whose field list resolved to zero sketches at runtime.
Common situations: A post-aggregator configured in a query whose input fields were filtered out or renamed, leaving zero dependencies; programmatic query building that passes an empty fields list for a NOT aggregator.
Understand the failure class
Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.
Related errors
- Illegal number of fields[%s], must be > 1
- Comparing arrays of estimates and error bounds is not suppor
- Comparing histograms is not supported
- Cannot accept both 'splitPoints' and 'numBins'
- at least 2 bins expected
AI-assisted analysis of apache/druid@9b90983fd2 (2026-09-07).
Data as JSON: /api/errors/f789b84e86b8b0df.
Report an issue: GitHub.