数据清洗
数据清洗:
洗衣服 =》 脏东西洗出来
数据清洗 =》脏数据
有的时候数据并非全部需要
不符合格式的数据
不是所有的数据都符合目前情况 或缺少值
清除掉
1、给默认值
2、转化 比如 男 女
3、删除错误数据,不符合格式的数据
public class ETLDemo {
static {
try {
System.load("D:\\hd\\bin\\hadoop.dll");
} catch (UnsatisfiedLinkError e) {
System.out.println("Native code library failed to load.\n" + e);
System.exit(1);
}
}
public static void main(String[] args) throws Exception{
System.setProperty("hadoop.home.dir","D:\\hd");
Configuration configuration = new Configuration();
Job job = Job.getInstance(configuration);
job.setJarByClass(ETLDemo.class);
job.setMapperClass(ETLDemo.ETLMapper.class);
job.setMapOutputKeyClass(Text.class);
job.setMapOutputValueClass(NullWritable.class);
FileInputFormat.setInputPaths(job, new Path("data/taobao_persona.csv"));
FileOutputFormat.setOutputPath(job, new Path("output/etl"));
boolean result = job.waitForCompletion(true);
System.exit(result ? 0 : -1);
}
// 清洗不需要运算 NullWritable:空 数据传输对象
static class ETLMapper extends Mapper<LongWritable, Text,Text, NullWritable> {
@Override
protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
String[] strs = value.toString().split(",");
//用户id 商品id 操作 种类
//可扩展性字符串
StringBuffer sb = new StringBuffer();
sb.append(strs[0]).append("::")
.append(strs[1]).append("::")
.append(strs[2]).append("::")
.append(strs[4]);
context.write(new Text(sb.toString()),NullWritable.get());
}
}
}