Flink - how to compute sum and average at the same time?

Viewed 1646

Is there a way in Flink (batch/streaming) to compute the average and sum of a field at the same time? Using the aggregate method I can compute the sum of a field on a groupBy result, but how do I calculate the average also at the same time? Example code below.

ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
DataSet<Tuple3<String,Integer,Double>> source = 
         env.readCsvFile(PathConfig.LINEITEM_1)
         .fieldDelimiter("|")
         types(String.class, Integer.class, Double.class);

source.groupBy(0,1).aggregate(Aggregations.SUM, 2);
//average of field 2???
1 Answers
Related