源码
[mw_shl_code=java,true]package cn.kxl;
import java.io.IOException;
import org.apache.commons.lang.StringUtils;
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;
import org.apache.hadoop.util.GenericOptionsParser;
public class identicalPassword {
public static class mymapper extends Mapper<LongWritable, Text, Text, LongWritable> {
private static final LongWritable one=new LongWritable(1);
private Text mailbox = new Text();
private Text password = new Text();
public void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
String[] lins=StringUtils.split(value.toString(),",");
if(lins[2].length()>0&&lins[3].length()>0){
password.set(lins[2]);
mailbox.set(lins[3]);
System.err.println("----"+password+"\t "+mailbox);
context.write(password,one);
}
}
}
public static class myreduce extends Reducer<Text, LongWritable, Text, LongWritable> {
private LongWritable result = new LongWritable();
public void reduce(Text key, Iterable<LongWritable> values, Context context)
throws IOException, InterruptedException {
int sum = 0;
for (LongWritable val : values) {
sum+=val.get();
}
result.set(sum);
context.write(key, result);
}
}
public static void main(String[] args) throws Exception, IOException {
Configuration conf = new Configuration();
String[] otherArgs = new GenericOptionsParser(conf, args).getRemainingArgs();
if (otherArgs.length < 2) {
System.err.println(" input and ouput");
System.exit(2);
}
Job job = Job.getInstance(conf, "word count");
job.setJarByClass(independentIp.class);
job.setMapperClass(mymapper.class);
job.setReducerClass(myreduce.class);
job.setMapOutputKeyClass(Text.class);
job.setMapOutputValueClass(LongWritable.class);
job.setOutputKeyClass(Text.class);
job.setOutputValueClass(LongWritable.class);
for (int i = 0; i < otherArgs.length - 1; i++) {
FileInputFormat.addInputPath(job, new Path(otherArgs));
}
FileOutputFormat.setOutputPath(job, new Path(otherArgs[(otherArgs.length-1)]));
System.exit(job.waitForCompletion(true)?0:1);
}
}
[/mw_shl_code]
|