{"record":{"id":"a8cdad2437c7abda","repo":"apache/druid","slug":"object-is-not-of-a-type-s-that-can-be-deserializ-a8cdad","errorCode":null,"errorMessage":"Object is not of a type[%s] that can be deserialized to sketch.","messagePattern":"Object is not of a type\\[(.+?)\\] that can be deserialized to sketch\\.","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/SketchHolder.java","lineNumber":222,"sourceCode":"    cachedEstimate = null;\n    cachedSketch = null;\n  }\n\n  public static SketchHolder deserialize(Object serializedSketch)\n  {\n    if (serializedSketch instanceof String) {\n      return SketchHolder.of(deserializeFromBase64EncodedString((String) serializedSketch));\n    } else if (serializedSketch instanceof byte[]) {\n      return SketchHolder.of(deserializeFromByteArray((byte[]) serializedSketch));\n    } else if (serializedSketch instanceof SketchHolder) {\n      return (SketchHolder) serializedSketch;\n    } else if (serializedSketch instanceof Sketch\n               || serializedSketch instanceof Union\n               || serializedSketch instanceof Memory) {\n      return SketchHolder.of(serializedSketch);\n    }\n\n    throw new ISE(\n        \"Object is not of a type[%s] that can be deserialized to sketch.\",\n        serializedSketch.getClass()\n    );\n  }\n\n  public static SketchHolder deserializeSafe(Object serializedSketch)\n  {\n    if (serializedSketch instanceof String) {\n      return SketchHolder.of(deserializeFromBase64EncodedStringSafe((String) serializedSketch));\n    } else if (serializedSketch instanceof byte[]) {\n      return SketchHolder.of(deserializeFromByteArraySafe((byte[]) serializedSketch));\n    }\n\n    return deserialize(serializedSketch);\n  }\n\n  private static Sketch deserializeFromBase64EncodedString(String str)\n  {","sourceCodeStart":204,"sourceCodeEnd":240,"githubUrl":"https://github.com/apache/druid/blob/9b90983fd291f26935af934383ce360473179e4d/extensions-core/datasketches/src/main/java/org/apache/druid/query/aggregation/datasketches/theta/SketchHolder.java#L204-L240","documentation":"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().","triggerScenarios":"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.","commonSituations":"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.","solutions":["Ensure the input is a Sketch, Union, or Memory; if you have raw bytes, wrap them with Memory.wrap(byte[]) before deserializing","If the value is a JSON string, decode it into Memory/sketch bytes rather than passing the String directly","Verify the input source (segment/store) was written by the same DataSketches family and version","Add an instanceof check on the value and route unsupported types to a fallback or error path before calling deserialize"],"exampleFix":"// before\nSketchHolder holder = SketchHolder.deserialize(rawObject); // rawObject is byte[]\n// after\nObject obj = rawObject instanceof byte[]\n    ? Memory.wrap((byte[]) rawObject)\n    : rawObject;\nSketchHolder holder = SketchHolder.deserialize(obj);","handlingStrategy":"type-guard","validationCode":"if (!(serializedSketch instanceof Sketch)\n    && !(serializedSketch instanceof Union)\n    && !(serializedSketch instanceof Memory)) {\n  throw new IllegalArgumentException(\"Not deserializable to theta sketch: \" + serializedSketch.getClass());\n}","typeGuard":"boolean isDeserializableToSketch(Object o) {\n  return o instanceof Sketch || o instanceof Union || o instanceof Memory;\n}","tryCatchPattern":"try {\n  SketchHolder h = SketchHolder.deserializeSafe(obj);\n} catch (IllegalStateException e) {\n  // inspect obj.getClass(); convert raw bytes via Memory.wrap() and retry once\n}","preventionTips":["Wrap raw byte[] in Memory.wrap() before deserialization","Never pass JSON Strings/Maps directly to deserialize()","Keep sketch serialization formats consistent between writer and reader systems","Use deserializeSafe() which handles null and returns an empty holder for null inputs"],"tags":["java","datasketches","deserialization"],"backgroundTag":"incompatible-source-type","analyzedSha":"9b90983fd291f26935af934383ce360473179e4d","analyzedAt":"2026-09-07T13:32:30.957Z","contentChangedAt":"2026-09-07T13:32:30.957Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}