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

StackOverflow https://stackoverflow.com/questions/19906417

  •  30-07-2022
  •  | 
  •  

Frage

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.
War es hilfreich?

Lösung 2

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.

Andere Tipps

From the trident API page it says

A function takes in a set of input fields and emits zero or more tuples as output. The fields of the output tuple are appended to the original input tuple in the stream. If a function emits no tuples, the original input tuple is filtered out. Otherwise, the input tuple is duplicated for each output tuple

Now digging more from the trident tutorial page found this
With grouped streams, the output will contain the grouping fields followed by the fields emitted by the aggregator. For example:

    stream.groupBy(new Fields("val1"))
     .aggregate(new Fields("val2"), new Sum(), new Fields("sum"))

In this example, the output will contain the fields "val1" and "sum".

I am not sure but the closest one I can think of is doing something like

    stream.groupBy(new Fields("field1","field3","field4"))
     .aggregate(new Fields("field2"), new Sum(), new Fields("M_field2"))

might achieve what you are looking for. Correct me if I am wrong.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top