赞
踩
1、第一次mapreduce
- package cn.itcast.mr.combineSort2;
-
- import java.io.IOException;
-
- import org.apache.hadoop.conf.Configuration;
- import org.apache.hadoop.fs.FileSystem;
- import org.apache.hadoop.fs.Path;
- import org.apache.hadoop.io.IntWritable;
- 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.Mapper.Context;
- import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
- import org.apache.hadoop.mapreduce.lib.input.FileSplit;
- import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
-
-
- public class combineSortMRD {
-
- static class combineSortMapper extends Mapper<LongWritable, Text, Text, IntWritable>{
-
- @Override
- protected void map(LongWritable key, Text value,Context context)
- throws IOException, InterruptedException {
-
- String line = value.toString();
- String[] words = line.split(" ");
-
- //获取切片信息
- FileSplit inputSplit = (FileSplit) context.getInputSplit();
- String name = inputSplit.getPath().getName();
-
- for(String word:words){
- context.write(new Text(word+"-->"+name),new IntWritable(1));
- }
- }
- }
-
- static class combineSortReducer extends Reducer<Text, IntWritable, Text, IntWritable>{
-
- @Override
- protected void

Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。