package com.galaxy.tsg.function; import com.galaxy.tsg.pojo.Entity; import org.apache.flink.api.common.functions.AggregateFunction; import org.apache.flink.api.java.tuple.Tuple1; import java.util.HashMap; public class metricsAggregation implements AggregateFunction>, Tuple1>> { private final int topSize; public metricsAggregation(int i) { this.topSize = i; } @Override public Tuple1> createAccumulator() { return Tuple1.of(new HashMap()); } @Override public Tuple1> add(Entity value, Tuple1> accumulator) { if(accumulator.f0.containsKey(value.getKey_by())) { Entity value1= accumulator.f0.get(value.getKey_by()); value1.setCommon_c2s_pkt_num(value1.getCommon_c2s_pkt_num() + value.getCommon_c2s_pkt_num()); value1.setCommon_s2c_pkt_num(value1.getCommon_s2c_pkt_num() + value.getCommon_s2c_pkt_num()); value1.setCommon_c2s_byte_num(value1.getCommon_c2s_byte_num() + value.getCommon_c2s_byte_num()); value1.setCommon_s2c_byte_num(value1.getCommon_s2c_byte_num() + value.getCommon_s2c_byte_num()); value1.setCommon_sessions(value1.getCommon_sessions() + value.getCommon_sessions()); } else { if(accumulator.f0.size()> getResult(Tuple1> accumulator) { return accumulator; } @Override public Tuple1> merge(Tuple1> a, Tuple1> b) { return null; } }