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

Object is not of a type

Error message

Object is not of a type[%s] that can be deserialized to sketch.

What it means

SketchHolder.deserialize() accepts an object that should be a serialized sketch form (Sketch, Union, or Memory) and wraps it in a SketchHolder. If the object is none of these types, it throws an ISE because there is no defined way to turn it into a theta sketch. It is the entry-point validation used by deserializeSafe().

Solutions

  1. Ensure the input is a Sketch, Union, or Memory; if you have raw bytes, wrap them with Memory.wrap(byte[]) before deserializing
  2. If the value is a JSON string, decode it into Memory/sketch bytes rather than passing the String directly
  3. Verify the input source (segment/store) was written by the same DataSketches family and version
  4. Add an instanceof check on the value and route unsupported types to a fallback or error path before calling deserialize

Example fix

// before
SketchHolder holder = SketchHolder.deserialize(rawObject); // rawObject is byte[]
// after
Object obj = rawObject instanceof byte[]
    ? Memory.wrap((byte[]) rawObject)
    : rawObject;
SketchHolder holder = SketchHolder.deserialize(obj);
Defensive patterns

Strategy: type-guard

Validate before calling

if (!(serializedSketch instanceof Sketch)
    && !(serializedSketch instanceof Union)
    && !(serializedSketch instanceof Memory)) {
  throw new IllegalArgumentException("Not deserializable to theta sketch: " + serializedSketch.getClass());
}

Type guard

boolean isDeserializableToSketch(Object o) {
  return o instanceof Sketch || o instanceof Union || o instanceof Memory;
}

Try / catch

try {
  SketchHolder h = SketchHolder.deserializeSafe(obj);
} catch (IllegalStateException e) {
  // inspect obj.getClass(); convert raw bytes via Memory.wrap() and retry once
}

Prevention

When it happens

Trigger: Calling SketchHolder.deserialize(obj) or deserializeSafe(obj) with anything other than a Sketch, Union, or Memory instance — typically a String, byte[], Map, or ByteBuffer coming from JSON ingestion of an aggregator column or a custom deserialization path.

Common situations: Ingesting theta sketch columns serialized by a different system where the value deserialized into a generic JSON type (String/List) instead of Memory; feeding raw byte[] (Druid deserializes Memory itself, so a raw array reaches this as byte[]); storing sketches in a serialization format the extension cannot recognize.

Understand the failure class

Background: "is not a compatible type" / "cannot merge" errors: when a value's type doesn't match what the library requires — this error's family across 65 libraries.

Related errors


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

Appendix: source

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

    cachedEstimate = null;
    cachedSketch = null;
  }

  public static SketchHolder deserialize(Object serializedSketch)
  {
    if (serializedSketch instanceof String) {
      return SketchHolder.of(deserializeFromBase64EncodedString((String) serializedSketch));
    } else if (serializedSketch instanceof byte[]) {
      return SketchHolder.of(deserializeFromByteArray((byte[]) serializedSketch));
    } else if (serializedSketch instanceof SketchHolder) {
      return (SketchHolder) serializedSketch;
    } else if (serializedSketch instanceof Sketch
               || serializedSketch instanceof Union
               || serializedSketch instanceof Memory) {
      return SketchHolder.of(serializedSketch);
    }

    throw new ISE(
        "Object is not of a type[%s] that can be deserialized to sketch.",
        serializedSketch.getClass()
    );
  }

  public static SketchHolder deserializeSafe(Object serializedSketch)
  {
    if (serializedSketch instanceof String) {
      return SketchHolder.of(deserializeFromBase64EncodedStringSafe((String) serializedSketch));
    } else if (serializedSketch instanceof byte[]) {
      return SketchHolder.of(deserializeFromByteArraySafe((byte[]) serializedSketch));
    }

    return deserialize(serializedSketch);
  }

  private static Sketch deserializeFromBase64EncodedString(String str)
  {

View on GitHub (pinned to 9b90983fd2)