import
import org.apache.
import org.apache.
import org.apache.
import org.apache.hadoop.mapreduce.Mapper;
public class MyMapper extends Mapper<LongWritable, Text, Text, DoubleWritable>{
protected void map(LongWritable key, Text value, Mapper<LongWritable, Text, Text, DoubleWritable>.Context context)
throws IOException, InterruptedException {
String line = value.toString();
String[] arra = line.split(",");
double[] arrb = new double[arra.length-1];
for(int i=0; i<arra.length-1; i++) {
arrb[i] = Double.parseDouble(arra[i]);
}
Double a = arrb[0] - arrb[1];
Double b = arrb[2] - arrb[3];
Double c = Math.sqrt((Math.pow(a, 2) + Math.pow(b, 2)));
context.write(new Text(arra[arra.length-1]), new DoubleWritable(c));
}
}
如果有错误请求指正,谢谢。