{"record":{"id":"c87f023350a920a9","repo":"apache/druid","slug":"illegal-type-received-while-theta-sketch-merging","errorCode":null,"errorMessage":"Illegal type received while theta sketch merging [%s]","messagePattern":"Illegal type received while theta sketch merging \\[(.+?)\\]","errorType":"exception","errorClass":"org.apache.druid.java.util.common.ISE","httpStatus":null,"severity":"error","filePath":"extensions-core/datasketches/src/main/java/org/apache/druid/query/aggregation/datasketches/theta/SketchAggregator.java","lineNumber":160,"sourceCode":"    } else if (update instanceof Double) {\n      union.update((Double) update);\n    } else if (update instanceof Integer || update instanceof Long) {\n      union.update(((Number) update).longValue());\n    } else if (update instanceof int[]) {\n      union.update((int[]) update);\n    } else if (update instanceof long[]) {\n      union.update((long[]) update);\n    } else if (update instanceof List) {\n      for (Object entry : (List) update) {\n        if (entry != null) {\n          final String asString = entry.toString();\n          if (asString != null) {\n            union.update(asString);\n          }\n        }\n      }\n    } else {\n      throw new ISE(\"Illegal type received while theta sketch merging [%s]\", update.getClass());\n    }\n  }\n\n  /**\n   * Gets the initial size of this aggregator in bytes.\n   */\n  public long getInitialSizeBytes()\n  {\n    // Size = 16B (object header) + 24B (3 refs) + 4B (int size) = 44B\n    // Due to 8-byte alignment, size = 48B\n    // (see https://www.baeldung.com/java-memory-layout)\n    return 48L;\n  }\n\n}\n","sourceCodeStart":142,"sourceCodeEnd":176,"githubUrl":"https://github.com/apache/druid/blob/9b90983fd291f26935af934383ce360473179e4d/extensions-core/datasketches/src/main/java/org/apache/druid/query/aggregation/datasketches/theta/SketchAggregator.java#L142-L176","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Ensure the column is a theta sketch (thetaSketch aggregator at ingestion); re-ingest or convert the metric if it is another sketch type","Check that queries do not mix sketch types across segments/subqueries","If input is serialized data, ensure it is provided as String (hex/base64), Memory, or Sketch"],"exampleFix":"// before\nString payload = readFieldAsObject(row); // returns HLL object\nunion.update(payload); // ISE\n// after\nThetaValue v = toThetaSketch(row.getField(\"sketch\")); // re-ingest column as thetaSketch if not convertible","handlingStrategy":"validation","validationCode":"Object v = selector.get(); if (!(v instanceof Sketch || v instanceof Memory || v instanceof String)) { throw new IllegalArgumentException(\"Column must be thetaSketch, got \" + v.getClass()); }","typeGuard":"boolean isMergeableTheta(Object v) { return v instanceof Sketch || v instanceof Memory || v instanceof String; }","tryCatchPattern":"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; }","preventionTips":["Ingest theta sketch columns with the thetaSketch aggregator","Never mix sketch families (HLL, quantiles) in one metric column","Verify column types across all segments before querying"],"tags":["java","datasketches","theta-sketch","type-mismatch"],"backgroundTag":"type-mismatch","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"}