ETL数据清洗代码操作

数据清洗

数据清洗:
            洗衣服 =》 脏东西洗出来
            数据清洗 =》脏数据
            
            有的时候数据并非全部需要
            不符合格式的数据
            不是所有的数据都符合目前情况 或缺少值
            
            清除掉
            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());
        }
    }


}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值