当前位置:天才代写 > tutorial > JAVA 教程 > Java中如何操作MultipleOutputs节制reduce输出路径

Java中如何操作MultipleOutputs节制reduce输出路径

2017-11-01 08:00 星期三 所属: JAVA 教程 浏览:61

package com.mr.test;
import java.io.IOException;
import java.util.Iterator;
import java.util.StringTokenizer;

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.mapred.FileInputFormat;
import org.apache.hadoop.mapred.FileOutputFormat;
import org.apache.hadoop.mapred.JobClient;
import org.apache.hadoop.mapred.JobConf;
import org.apache.hadoop.mapred.Mapper;
import org.apache.hadoop.mapred.OutputCollector;
import org.apache.hadoop.mapred.Reducer;
import org.apache.hadoop.mapred.Reporter;
import org.apache.hadoop.mapred.TextInputFormat;
import org.apache.hadoop.mapred.TextOutputFormat;
import org.apache.hadoop.mapred.lib.MultipleOutputs;

public class WordCount {
public static class MyMap implements
Mapper<LongWritable, Text, Text, IntWritable> {
private final static IntWritable one = new IntWritable(1);
private Text word = new Text();

public void map(LongWritable key, Text value,
OutputCollector<Text, IntWritable> output, Reporter reporter)
throws IOException {
String line = value.toString();
StringTokenizer tokenizer = new StringTokenizer(line);
while (tokenizer.hasMoreTokens()) {
word.set(tokenizer.nextToken());
output.collect(word, one);
}
}
public void configure(JobConf arg0) {

}
public void close() throws IOException {
// TODO Auto-generated method stub
}
}
//本栏目

test1

test2

test3

test4

test5

output:

-rw-r--r--   2 test supergroup          0 2014-04-20 11:23 /chukwa/output/0419-10/_SUCCESS

drwxr-xr-x   - test supergroup          0 2014-04-20 11:23 /chukwa/output/0419-10/_logs

-rw-r--r--   2 test supergroup         42 2014-04-20 11:23 /chukwa/output/0419-10/part-00000.lzo

-rw-r--r--   2 test supergroup         58 2014-04-20 11:23 /chukwa/output/0419-10/test1-m-00000.lzo

-rw-r--r--   2 test supergroup         58 2014-04-20 11:23 /chukwa/output/0419-10/test2-m-00000.lzo

-rw-r--r--   2 test supergroup         58 2014-04-20 11:23 /chukwa/output/0419-10/test3-m-00000.lzo

-rw-r--r--   2test supergroup         58 2014-04-20 11:23 /chukwa/output/0419-10/test4-m-00001.lzo

-rw-r--r--   2 test supergroup         58 2014-04-20 11:23 /chukwa/output/0419-10/test5-m-00001.lzo

 

    关键字:


天才代写-代写联系方式