apache/druid · error · ISE
Object cannot be deserialized to a Moments Sketch:
Error message
Object cannot be deserialized to a Moments Sketch:
What it means
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.
Source
Thrown at extensions-contrib/momentsketch/src/main/java/org/apache/druid/query/aggregation/momentsketch/aggregator/MomentSketchAggregatorFactory.java:186
}
private MomentSketchWrapper deserializeFromByteArray(byte[] bytes)
{
return MomentSketchWrapper.fromByteArray(bytes);
}
@Override
public Object deserialize(Object serializedSketch)
{
if (serializedSketch instanceof String) {
String str = (String) serializedSketch;
return deserializeFromByteArray(StringUtils.decodeBase64(StringUtils.toUtf8(str)));
} else if (serializedSketch instanceof byte[]) {
return deserializeFromByteArray((byte[]) serializedSketch);
} else if (serializedSketch instanceof MomentSketchWrapper) {
return serializedSketch;
}
throw new ISE(
"Object cannot be deserialized to a Moments Sketch: "
+ serializedSketch.getClass()
);
}
@Nullable
@Override
public Object finalizeComputation(@Nullable Object object)
{
return object;
}
@Override
@JsonProperty
public String getName()
{
return name;
}View on GitHub (pinned to 9b90983fd2)
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.
Example fix
// before
Object sketch = columnValue; // could be Integer, Map, etc.
momentSketch = factory.deserialize(sketch);
// after
if (sketch instanceof String || sketch instanceof byte[] || sketch instanceof MomentSketchWrapper) {
momentSketch = factory.deserialize(sketch);
} else {
throw new IllegalArgumentException("Unsupported sketch type: " + sketch.getClass());
} Defensive patterns
Strategy: type-guard
Validate before calling
boolean isSupportedSketchForm(Object v) {
return v instanceof String || v instanceof byte[] || v instanceof MomentSketchWrapper;
} Type guard
boolean canDeserializeSketch(Object serializedSketch) {
return serializedSketch instanceof String
|| serializedSketch instanceof byte[]
|| serializedSketch instanceof MomentSketchWrapper;
}
MomentSketchWrapper safeDeserialize(MomentSketchAggregatorFactory f, Object v) {
return canDeserializeSketch(v) ? f.deserialize(v) : null;
} Try / catch
try {
sketch = factory.deserialize(value);
} catch (IllegalStateException e) {
log.warn("Unrecognized sketch payload: {}", e.getMessage());
sketch = null; // or re-ingest / skip row
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
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
- not implemented
- Not implemented
- Not implemented
- Not implemented
- AggregatorFactoryNotMergeableException(this, other)
AI-assisted analysis of apache/druid@9b90983fd2 (2026-09-07).
Data as JSON: /api/errors/24884e9049891f1d.
Report an issue: GitHub.