apache/druid · error · ISE

Both union and sketch were null!

Error message

Both union and sketch were null!

What it means

The HllSketchHolder constructor stores an optional Union or an optional HllSketch and enforces the invariant that at least one must be non-null. When both are null the holder would represent no sketch at all and every downstream operation would fail, so the constructor throws an IllegalStateException immediately. This is an internal invariant violation, usually caused by calling the constructor directly instead of the static factories.

Source

Thrown at extensions-core/datasketches/src/main/java/org/apache/druid/query/aggregation/datasketches/hll/HllSketchHolder.java:77

  public static HllSketchHolder of(HllSketch sketch)
  {
    return new HllSketchHolder(null, sketch);
  }

  private Union union;
  private HllSketch sketch;

  public HllSketchHolder(
      Union union,
      HllSketch sketch
  )
  {
    this.union = union;
    this.sketch = sketch;

    if (this.union == null && this.sketch == null) {
      throw new ISE("Both union and sketch were null!");
    }
  }

  @JsonValue
  public HllSketch getSketch()
  {
    if (sketch == null) {
      sketch = union.getResult();
    }

    return sketch;
  }

  public HllSketch getSketch(TgtHllType type)
  {
    if (sketch == null) {
      sketch = union.getResult(type);
    }

View on GitHub (pinned to 9b90983fd2)

Solutions

  1. Use the static factories HllSketchHolder.of(union) / of(sketch) / of(union, sketch) rather than the raw constructor
  2. If the union was drained, wrap the resulting HllSketch instead of the null union
  3. Add a guard that falls back to a fresh empty Union (new Union(12)) when both inputs would be null

Example fix

// before
HllSketchHolder holder = new HllSketchHolder(maybeUnion, null);
// after
HllSketchHolder holder = maybeUnion != null ? HllSketchHolder.of(maybeUnion) : HllSketchHolder.of(new Union(12));
Defensive patterns

Strategy: validation

Validate before calling

if (union == null && sketch == null) { throw new IllegalArgumentException("at least one of union/sketch required"); }

Try / catch

try { holder = new HllSketchHolder(u, s); } catch (IllegalStateException e) { holder = HllSketchHolder.of(new Union(12)); }

Prevention

When it happens

Trigger: Invoking new HllSketchHolder(null, null) directly, or a code path where the union was consumed/reduced to null (e.g. after union.reset()) before constructing the holder.

Common situations: Custom aggregation code building holders manually; refactoring that nulls out the union field before re-wrapping; copying holders after aggregation finalized the union into a sketch but cleared the reference.

Understand the failure class

Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.

Related errors


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