Maziar Maziar - 11 months ago 55
Java Question

Storm emitting array of integers and retrieving it

I'm turning an image to a 2D array of integers. Doing some process on that then I'm trying to emit the array in this way :

collector.emit( new Values ( scaledImageMatrix ) );

then I'm trying to retrieve the data in another bolt like this :

int [][] imageMatrix = input.get("scaled-image-matrix");

but I get the error

incompatible types
[ERROR] found : java.lang.Object
[ERROR] required: int[][]

Any suggestions ?


I tried this
int [][] imageMatrix = (int[][])input.get("scaled-image-matrix");

and I got this error :

java.lang.IllegalArgumentException: Tuple created with wrong number of fields. Expected 1 fields but got 190 fields

Then I should change my question to : How to emit a two dimensional array ?

Answer Source

I guess that's not possible except building a serializer yourself for two-dimensional array.

Storm will try to guess the type of a tuple and see if it can be serialized. Anything emitted is already serialized, so there's no way to send any object storm can't serialize.

By default, Storm can serialize primitive types, strings, byte arrays, ArrayList, HashMap, HashSet, and the Clojure collection types.

So I suggest use ArrayList or Clojure's vector instead, or write a custom kryo serializer by yourself. See the docs here.