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

Illegal type received while theta sketch merging [%s]

Error message

Illegal type received while theta sketch merging [%s]

What it means

SketchAggregator.updateUnion accepts theta sketch objects, Memory, or Strings (hex/base64) for merging; any other input type triggers this IllegalStateException. It indicates the aggregation is receiving a value that is not a theta sketch in any accepted representation.

Source

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

    } else if (update instanceof Double) {
      union.update((Double) update);
    } else if (update instanceof Integer || update instanceof Long) {
      union.update(((Number) update).longValue());
    } else if (update instanceof int[]) {
      union.update((int[]) update);
    } else if (update instanceof long[]) {
      union.update((long[]) update);
    } else if (update instanceof List) {
      for (Object entry : (List) update) {
        if (entry != null) {
          final String asString = entry.toString();
          if (asString != null) {
            union.update(asString);
          }
        }
      }
    } else {
      throw new ISE("Illegal type received while theta sketch merging [%s]", update.getClass());
    }
  }

  /**
   * Gets the initial size of this aggregator in bytes.
   */
  public long getInitialSizeBytes()
  {
    // Size = 16B (object header) + 24B (3 refs) + 4B (int size) = 44B
    // Due to 8-byte alignment, size = 48B
    // (see https://www.baeldung.com/java-memory-layout)
    return 48L;
  }

}

View on GitHub (pinned to 9b90983fd2)

Solutions

  1. Ensure the column is a theta sketch (thetaSketch aggregator at ingestion); re-ingest or convert the metric if it is another sketch type
  2. Check that queries do not mix sketch types across segments/subqueries
  3. If input is serialized data, ensure it is provided as String (hex/base64), Memory, or Sketch

Example fix

// before
String payload = readFieldAsObject(row); // returns HLL object
union.update(payload); // ISE
// after
ThetaValue v = toThetaSketch(row.getField("sketch")); // re-ingest column as thetaSketch if not convertible
Defensive patterns

Strategy: validation

Validate before calling

Object v = selector.get(); if (!(v instanceof Sketch || v instanceof Memory || v instanceof String)) { throw new IllegalArgumentException("Column must be thetaSketch, got " + v.getClass()); }

Type guard

boolean isMergeableTheta(Object v) { return v instanceof Sketch || v instanceof Memory || v instanceof String; }

Try / catch

try { agg.aggregate(); } catch (IllegalStateException e) { if (e.getMessage().startsWith("Illegal type received while theta sketch merging")) { log.error("Re-ingest column as thetaSketch"); } else throw e; }

Prevention

When it happens

Trigger: aggregate()/aggregateWithSize() feed updateUnion a selector value whose runtime class is neither Sketch, Memory, nor String — commonly because the rolled-up metric object is of a different sketch family (HLL, quantiles) or a deserialized generic Object.

Common situations: Querying a theta sketch column that was ingested with the wrong sketch type (e.g. HLLSketch metrics); mixing sketch families in a datasource; segment/rollup type drift after schema changes.

Understand the failure class

Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.

Related errors


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