码迷,mamicode.com
首页 > 其他好文 > 详细

计数器

时间:2020-11-25 13:04:03      阅读:26      评论:0      收藏:0      [点我收藏+]

标签:tostring   config   org   drive   task   driver   key   exception   rem   

 

 

 

package com.atguigu.etl;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

import javax.xml.soap.Text;

public class etlDriver {
    public static void main(String[] args) throws Exception {

        Job job = Job.getInstance(new Configuration());

        job.setJarByClass(etlDriver.class);

        job.setMapperClass(etlMapper.class);
        job.setNumReduceTasks(0);

        job.setMapOutputKeyClass(Text.class);
        job.setMapOutputValueClass(NullWritable.class);

        FileInputFormat.setInputPaths(job,new Path("input/log.txt"));
        FileOutputFormat.setOutputPath(job,new Path("output"));


        boolean b = job.waitForCompletion(true);
        System.exit(b?0:1);
    }
}


/*
    etl
        False=4
        True=2
 */

 

 

package com.atguigu.etl;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

public class etlMapper extends Mapper<LongWritable,Text, Text, NullWritable> {
    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
        String[] fiels = value.toString().split(",");

        if(fiels.length>5){
            context.write(value,NullWritable.get());
            context.getCounter("etl","True").increment(1);
        }else{
            context.getCounter("etl","False").increment(1);
        }
    }
}

 

计数器

标签:tostring   config   org   drive   task   driver   key   exception   rem   

原文地址:https://www.cnblogs.com/hapyygril/p/14018683.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!