程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> JAVA編程 >> 關於JAVA >> Java中如何利用MultipleOutputs控制reduce輸出路徑

Java中如何利用MultipleOutputs控制reduce輸出路徑

編輯:關於JAVA
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

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved