{"record":{"id":"d96dbc0c2ee01c93","repo":"apache/druid","slug":"object-is-not-of-a-type-that-can-deserialize-to-sk","errorCode":null,"errorMessage":"Object is not of a type that can deserialize to sketch: %s","messagePattern":"Object is not of a type that can deserialize to sketch: (.+?)","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"extensions-core/datasketches/src/main/java/org/apache/druid/query/aggregation/datasketches/tuple/ArrayOfDoublesSketchOperations.java","lineNumber":116,"sourceCode":"    {\n      final double[] result = new double[a.length];\n      for (int i = 0; i < a.length; i++) {\n        result[i] = a[i] + b[i];\n      }\n      return result;\n    }\n  };\n\n  public static ArrayOfDoublesSketch deserialize(final Object serializedSketch)\n  {\n    if (serializedSketch instanceof String) {\n      return deserializeFromBase64EncodedString((String) serializedSketch);\n    } else if (serializedSketch instanceof byte[]) {\n      return deserializeFromByteArray((byte[]) serializedSketch);\n    } else if (serializedSketch instanceof ArrayOfDoublesSketch) {\n      return (ArrayOfDoublesSketch) serializedSketch;\n    }\n    throw new ISE(\"Object is not of a type that can deserialize to sketch: %s\", serializedSketch.getClass());\n  }\n\n  public static ArrayOfDoublesSketch deserializeSafe(final Object serializedSketch)\n  {\n    if (serializedSketch instanceof String) {\n      return deserializeFromBase64EncodedStringSafe((String) serializedSketch);\n    } else if (serializedSketch instanceof byte[]) {\n      return deserializeFromByteArraySafe((byte[]) serializedSketch);\n    }\n\n    return deserialize(serializedSketch);\n  }\n\n  public static ArrayOfDoublesSketch deserializeFromBase64EncodedString(final String str)\n  {\n    return deserializeFromByteArray(StringUtils.decodeBase64(str.getBytes(StandardCharsets.UTF_8)));\n  }\n","sourceCodeStart":98,"sourceCodeEnd":134,"githubUrl":"https://github.com/apache/druid/blob/9b90983fd291f26935af934383ce360473179e4d/extensions-core/datasketches/src/main/java/org/apache/druid/query/aggregation/datasketches/tuple/ArrayOfDoublesSketchOperations.java#L98-L134","documentation":"ArrayOfDoublesSketchOperations.deserialize() only accepts String (base64), byte[], or an already-deserialized ArrayOfDoublesSketch. Any other object type reaches the final ISE, which reports the offending class. This is a type-guard failure in sketch deserialization.","triggerScenarios":"Calling deserialize(Object) with an object that is none of String, byte[], or ArrayOfDoublesSketch — e.g. a Map, List, or Numeric value returned by an expression or stored in a column.","commonSituations":"Query results where the column does not actually contain a serialized sketch (wrong column chosen, aggregator changed, older data written with a different type); passing a Calcite/Java object of the wrong type into deserialize directly.","solutions":["Inspect the reported class name in the message to see what was actually passed","Use deserializeSafe() which returns null instead of throwing for unusable objects","Ensure the source column/aggregator genuinely produces ArrayOfDoublesSketch objects","Convert the object to byte[] or base64 String before deserializing"],"exampleFix":"// before\nArrayOfDoublesSketch sketch = ArrayOfDoublesSketchOperations.deserialize(obj);\n// after\nArrayOfDoublesSketch sketch = ArrayOfDoublesSketchOperations.deserializeSafe(obj);\nif (sketch == null) {\n  // handle non-sketch object\n}","handlingStrategy":"type-guard","validationCode":"if (!(obj instanceof String) && !(obj instanceof byte[]) && !(obj instanceof ArrayOfDoublesSketch)) {\n  throw new IllegalStateException(\"Cannot deserialize to sketch: \" + obj.getClass());\n}","typeGuard":"boolean isDeserializable = obj instanceof String\n    || obj instanceof byte[]\n    || obj instanceof ArrayOfDoublesSketch;","tryCatchPattern":"try {\n  ArrayOfDoublesSketch s = ArrayOfDoublesSketchOperations.deserialize(obj);\n} catch (IllegalStateException e) {\n  // handle non-sketch object, e.g. log and treat as empty/null\n}","preventionTips":["Use deserializeSafe() when input type is uncertain","Confirm the source column is produced by a sketch aggregator","Check for schema/version drift in stored data"],"tags":["druid","datasketches","type-mismatch","deserialization"],"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"}