26 lines
814 B
Java
26 lines
814 B
Java
|
import org.apache.hadoop.io.Text;
|
||
|
import org.apache.hadoop.mapreduce.Reducer;
|
||
|
|
||
|
import java.io.IOException;
|
||
|
|
||
|
public class ProvinceMaxDailyPowerReducer extends Reducer<Text, Text, Text, Text> {
|
||
|
|
||
|
@Override
|
||
|
protected void reduce(Text key, Iterable<Text> values, Context context) throws IOException, InterruptedException {
|
||
|
String maxRecord = null;
|
||
|
double maxValue = Double.MIN_VALUE;
|
||
|
|
||
|
for (Text value : values) {
|
||
|
String[] parts = value.toString().split(":");
|
||
|
double powerUsage = Double.parseDouble(parts[2]);
|
||
|
if (powerUsage > maxValue) {
|
||
|
maxValue = powerUsage;
|
||
|
maxRecord = value.toString();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
if (maxRecord != null) {
|
||
|
context.write(key, new Text(maxRecord));
|
||
|
}
|
||
|
}
|
||
|
}
|