{"record":{"id":"24884e9049891f1d","repo":"apache/druid","slug":"object-cannot-be-deserialized-to-a-moments-sketch","errorCode":null,"errorMessage":"Object cannot be deserialized to a Moments Sketch: ","messagePattern":"Object cannot be deserialized to a Moments Sketch: ","errorType":"exception","errorClass":"ISE","httpStatus":null,"severity":"error","filePath":"extensions-contrib/momentsketch/src/main/java/org/apache/druid/query/aggregation/momentsketch/aggregator/MomentSketchAggregatorFactory.java","lineNumber":186,"sourceCode":"  }\n\n  private MomentSketchWrapper deserializeFromByteArray(byte[] bytes)\n  {\n    return MomentSketchWrapper.fromByteArray(bytes);\n  }\n\n  @Override\n  public Object deserialize(Object serializedSketch)\n  {\n    if (serializedSketch instanceof String) {\n      String str = (String) serializedSketch;\n      return deserializeFromByteArray(StringUtils.decodeBase64(StringUtils.toUtf8(str)));\n    } else if (serializedSketch instanceof byte[]) {\n      return deserializeFromByteArray((byte[]) serializedSketch);\n    } else if (serializedSketch instanceof MomentSketchWrapper) {\n      return serializedSketch;\n    }\n    throw new ISE(\n        \"Object cannot be deserialized to a Moments Sketch: \"\n        + serializedSketch.getClass()\n    );\n  }\n\n  @Nullable\n  @Override\n  public Object finalizeComputation(@Nullable Object object)\n  {\n    return object;\n  }\n\n  @Override\n  @JsonProperty\n  public String getName()\n  {\n    return name;\n  }","sourceCodeStart":168,"sourceCodeEnd":204,"githubUrl":"https://github.com/apache/druid/blob/9b90983fd291f26935af934383ce360473179e4d/extensions-contrib/momentsketch/src/main/java/org/apache/druid/query/aggregation/momentsketch/aggregator/MomentSketchAggregatorFactory.java#L168-L204","documentation":"MomentSketchAggregatorFactory.deserialize throws this IllegalStateException when the object passed in is not one of the supported serialized forms of a Moments Sketch: a String (base64), a byte[], or an already-decoded MomentSketchWrapper. The message appends the offending object's class so the developer can see what type actually arrived.","triggerScenarios":"deserialize receives a serializedSketch object whose runtime class is none of String, byte[], or MomentSketchWrapper — typically a corrupted aggregation result, an object written by an incompatible Druid version, or unexpected data read back from a segment/store that changed the representation.","commonSituations":"Querying segments written with an older or newer Druid serialization format; a custom aggregation pipeline inserting a wrong-typed object; a corrupted column value stored in deep storage; class-shading/version drift of the momentsketch dependency changing the wrapper type.","solutions":["Inspect the logged class name in the message to identify the unexpected type and where it originates.","Rewrite or re-ingest the affected segments so the sketches are serialized with the current format.","Align the momentsketch library and Druid versions across ingestion and query clusters.","If the value comes from your own code, convert it to base64 String or byte[] before calling deserialize."],"exampleFix":"// before\nObject sketch = columnValue; // could be Integer, Map, etc.\nmomentSketch = factory.deserialize(sketch);\n// after\nif (sketch instanceof String || sketch instanceof byte[] || sketch instanceof MomentSketchWrapper) {\n  momentSketch = factory.deserialize(sketch);\n} else {\n  throw new IllegalArgumentException(\"Unsupported sketch type: \" + sketch.getClass());\n}","handlingStrategy":"type-guard","validationCode":"boolean isSupportedSketchForm(Object v) {\n  return v instanceof String || v instanceof byte[] || v instanceof MomentSketchWrapper;\n}","typeGuard":"boolean canDeserializeSketch(Object serializedSketch) {\n  return serializedSketch instanceof String\n      || serializedSketch instanceof byte[]\n      || serializedSketch instanceof MomentSketchWrapper;\n}\n\nMomentSketchWrapper safeDeserialize(MomentSketchAggregatorFactory f, Object v) {\n  return canDeserializeSketch(v) ? f.deserialize(v) : null;\n}","tryCatchPattern":"try {\n  sketch = factory.deserialize(value);\n} catch (IllegalStateException e) {\n  log.warn(\"Unrecognized sketch payload: {}\", e.getMessage());\n  sketch = null; // or re-ingest / skip row\n}","preventionTips":["Keep Druid and momentsketch versions consistent between ingestion and query clusters.","Guard deserialization with instanceof checks on the three supported types.","Validate segment data after version upgrades or format migrations.","Wrap deserialization of external/corruptible data in try-catch."],"tags":["serialization","deserialization","aggregation","sketch","druid"],"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-14T05:17:10.506Z"}