Search code examples
apache-stormtrident

how to get complete list of original fields along with new Fields which has been modified in trident?


Suppose i have list of fields i.e, {field1,field2,field3,field4} I performed some operation on field2 say i want to add increment each tuple values by some value say 5,

performed this operation in a function which gave me modified field with "M_field2" as out field name now i want to write complete tuple in a file but in place of field2 i want "M_field2". How i will achieve this.

Solution

  • I solved this issue.. using trident just you have to use modified field name in list of input fields. For example :-

    topology.newStream("dummySpout",new DummySpout()).stateQuery(tridentState, new QueryFunctionClass(), new Fields("outLpi","outFileId"))
    .each(new Fields("outLpi"),new DBReaderFunction((ArrayList<String>)conf.get("listOfFields")), new Fields((ArrayList<String>)conf.get("listOfFields")))
    .each(new Fields((ArrayList<String>)conf.get("listOfFields")), new LoggerFilter())
    .aggregate(new Fields("SAL"), new ApplyAggregator(),new Fields("sum"))
    .each(new Fields("sum","SAL"),new LoggerFilter());
    

    in last line "sum" is the modified field and SAL is original field.