0

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 ?

UPDATE :

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 ?

Maziar
  • 81
  • 1
  • 12
  • Now I got this error `java.lang.IllegalArgumentException: Tuple created with wrong number of fields. Expected 1 fields but got 190 fields` – Maziar Aug 13 '14 at 16:06

2 Answers2

2

I know it's old question but this can be also useful. Primitive array can be emitted and received in the execute(Tuple input) method like any other object, you just need to use getValue(fieldName) method instead of get(fieldName):

int[][] imageMatrix = (int[][]) input.getValue("scaled-image-matrix")
milosdju
  • 783
  • 12
  • 27
0

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.

halfelf
  • 9,737
  • 13
  • 54
  • 63