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?
Storm returns every field that was processed during the execution chain in a Json array. The order of the values are the same as they were processed, so if you are interested in the result of only the last function then you should read only the last value from the array. If for any reason you are not interested in the intermediate results then you can limit it with the projection method. For example if you have a stream :
stream.each(new Fields("args"), new AddExclamation(), new Fields(EX_1))
.each(new Fields(EX_1), new AddPlus(), new Fields(P1, P2));
that returns
[["hello","hello!1","hello!1+1","hello!1+2"],["hello","hello!2","hello!2+1","hello!2+2"]]
then by setting projection, you can limit to 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));
so the output will be only this
[["hello!1+2"],["hello!2+2"]]
You can see this in action here :