标签: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