I have some dataset and I want to calculate the minimum, maximum and average for each record (for example: userID_1 -- minimum_1-- maximum_1 -- avg).
this my code, I need to know what to do that can let me write those values for that single key:
public static class Reduce extends Reducer<Text, IntWritable, Text, IntWritable> {
public void reduce(Text key, Iterable<IntWritable> values, Context context)
throws IOException, InterruptedException {
int sum = 0;
int visitsCounter = 0;
int min = Integer.MAX_VALUE;
int max = Integer.MIN_VALUE;
float avg;
for (IntWritable val : values) {
int currentValue = val.get();
sum += currentValue;
visitsCounter++;
min = Math.min(min, currentValue);
max = Math.max(max, currentValue);
}
avg = sum / visitsCounter;
//here can be the supposed edit to let me output (user - min - max - avg )
context.write(key, new IntWritable(sum));
}
}