강의지원 게시판

[빅데이터] 강의 자료입니다.

윈-프
작성자
신 민규 신 민규
작성일
2015-04-15 14:30
조회
923
import java.io.IOException;
import java.util.StringTokenizer;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.Mapper;
import org.apache.hadoop.mapreduce.Reducer;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

public class RmTab {

public static class BypassMapper
extends Mapper{


public void map(LongWritable key, Text value, Context context
) throws IOException, InterruptedException {
context.write(key, value);
}
}


public static class RmTabReducer
extends Reducer {

public void reduce(LongWritable key, Iterable values,
Context context
) throws IOException, InterruptedException {
for (Text value : values)
context.write(key, value);
}
}

public static void main(String[] args) throws Exception {
Configuration conf = new Configuration();
Job job = Job.getInstance(conf, "rm tab");
job.setJarByClass(RmTab.class);
job.setMapperClass(BypassMapper.class);
job.setReducerClass(RmTabReducer.class);
job.setOutputKeyClass(LongWritable.class);
job.setOutputValueClass(Text.class);
FileInputFormat.addInputPath(job, new Path(args[0]));
FileOutputFormat.setOutputPath(job, new Path(args[1]));
System.exit(job.waitForCompletion(true) ? 0 : 1);
}
}