代码之家  ›  专栏  ›  技术社区  ›  Maziar

风暴发射整数数组并检索它

  •  0
  • Maziar  · 技术社区  · 11 年前

    我将图像转换为二维整数数组。对此进行一些处理,然后我尝试以这种方式发射阵列:

    collector.emit( new Values ( scaledImageMatrix ) );
    

    然后我试图检索另一个螺栓中的数据,如下所示:

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

    但我得到了错误

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

    有什么建议吗?

    更新:

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

    我得到了这个错误:

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

    然后我应该把问题改为:如何发射二维阵列?

    2 回复  |  直到 9 年前
        1
  •  2
  •   milosdju    9 年前

    我知道这是个老问题,但这也很有用。基元数组可以在 execute(Tuple input) 方法,您只需要使用 getValue(fieldName) 方法而不是 get(fieldName) :

    int[][] imageMatrix = (int[][]) input.getValue("scaled-image-matrix")
    
        2
  •  0
  •   halfelf    11 年前

    我想这是不可能的,除非自己为二维数组构建序列化程序。

    Storm将尝试猜测元组的类型,看看它是否可以序列化。发射的任何东西都已经序列化,所以没有办法发送任何无法序列化的对象风暴。

    默认情况下,Storm可以序列化基元类型、字符串、字节数组、ArrayList、HashMap、HashSet和Clojure集合类型。

    所以我建议使用 ArrayList 或Clojure的 vector 或者编写自定义 kryo 序列化程序。查看文档 here .