0

I've got a simple Trident Topology running in a LocalDRPC where one of the functions outputs the result field, but when I run it the results I get back seem to be all the information from every tuple, instead of just the result field as I would have expected given the DRPC docs. Eg:

[["http:\/\/www.smbc-comics.com\/rss.php",http://www.smbc-comics.com/rss.php,[#document: null],[item: null],[link: null],[description: null],http://feedproxy.google.com/~r/smbc-comics/PvLb/~3/CBpJmAiJSxs/index.php,http://www.smbc-comics.com/comics/20141001.png,"http:\/\/www.smbc-comics.com\/comics\/20141001.png"], ...]

It would be okay to get all the information from every tuple back, but there's no indication of which of the fields is called result. As it stands it's not even valid JSON!

So how can I extract the value that corresponds to a specific field that I specified in the topology?

4

1 回答 1

1

Storm 在 Json 数组中返回执行链中处理的每个字段。值的顺序与处理它们的顺序相同,因此如果您只对最后一个函数的结果感兴趣,那么您应该只读取数组中的最后一个值。如果出于某种原因您对中间结果不感兴趣,那么您可以使用投影方法对其进行限制。例如,如果您有一个流:

stream.each(new Fields("args"), new AddExclamation(), new Fields(EX_1))
    .each(new Fields(EX_1), new AddPlus(), new Fields(P1, P2));

返回

[["hello","hello!1","hello!1+1","hello!1+2"],["hello","hello!2","hello!2+1","hello!2+2"]]

然后通过设置投影,您可以限制为 P2

stream.each(new Fields("args"), new AddExclamation(), new Fields(EX_1))
    .each(new Fields(EX_1), new AddPlus(), new Fields(P1, P2))
    .project(new Fields(P2));

所以输出将只有这个

[["hello!1+2"],["hello!2+2"]]

你可以在这里看到这个:

https://github.com/ExampleDriven/storm-example/blob/master/src/test/java/org/exampledriven/ExclamationPlusTridentTopologyTest.java

于 2014-10-03T15:02:36.740 回答