Hadoop Mapper 代码优化 - 处理 CSV 数据并解决分区错误
package com.mystudy.pxkDazuoye;
import java.io.IOException;
import org.apache.hadoop.io.LongWritable; import org.apache.hadoop.io.Text; import org.apache.hadoop.mapreduce.Mapper;
public class mapper extends Mapper<LongWritable, Text, Text, Text> {
@Override
protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
if (key.get() > 0) { // 排除表头
String[] fields = value.toString().split(',');
String firstName = fields[1];
String lastName = fields[2];
String emailAddress = fields[3];
Text outputKey = new Text(firstName + ',' + lastName);
Text outputValue = new Text(fields[0] + ';' + firstName + ' ' + lastName + ';' + emailAddress);
context.write(outputKey, outputValue);
}
}
}
原文地址: https://www.cveoy.top/t/topic/oJRD 著作权归作者所有。请勿转载和采集!