2014-11-14 124 views
2

我正在致力於Hadoop。我的輸出比預期的要快
我無法理解爲什麼會發生這種情況。
請幫我Hadoop中的Mapreduce程序中的意外輸出

下面是映射類

import java.io.File; 
import java.io.IOException; 
import java.util.Scanner; 
import org.apache.hadoop.io.*; 
import org.apache.hadoop.mapred.*; 

public class StringMapper extends MapReduceBase implements Mapper<LongWritable, Text, Text, IntWritable> 
{ 
     //hadoop supported data types 
     private static IntWritable send; 
     private Text word; 

     //map method that performs the tokenizer job and framing the initial key value pairs 
    public void map(LongWritable key, Text value, OutputCollector<Text, IntWritable> output, Reporter reporter) throws IOException 
    { 
     String line = value.toString(); 
     String out=""; 
     int count=0; 
      out+=Integer.toString(count); 
      send = new IntWritable(1); 
      word = new Text(out); 
      output.collect(word, send);            
    } 
} 

下面是減速類

import java.io.IOException; 
import java.util.Iterator; 
import org.apache.hadoop.io.*; 
import org.apache.hadoop.mapred.*; 

public class StringReducer extends MapReduceBase implements Reducer<Text, IntWritable, Text, IntWritable> 
{ 
    //reduce method accepts the Key Value pairs from mappers, do the aggregation based on keys and produce the final output 
    public void reduce(Text key, Iterator<IntWritable> values, OutputCollector<Text, IntWritable> output, Reporter reporter) throws IOException 
    { 
     int sum=0; 
     while(values.hasNext()){ 
      sum=sum+values.next().get(); 
     } 
     output.collect(key, new IntWritable(sum)); 
    } 
} 

樣品輸入:
dashjdasdhashjfsda
dashjdasdhashjfsda
dashjdasdhashjfsda
dashjdasdhashjfsda
dashjdasdhashjfsda

樣本輸出

這裏輸出應該是0,而不是5 0 10,因爲只有5在我的輸入線。

+0

該代碼對我來說很合適。你打這個工作怎麼樣?您可以發佈您的YARN cmd行並報告HDFS上的文件結構。 –

回答

1

您的程序似乎沒問題。我複製了你的代碼並在我的機器上運行它。它給出了正確的輸出,即0 5

如果你使用eclipse創建一個新的配置並且改變你的輸入目錄。
然後它可能會工作。

+0

我試着說你說的。但它不工作 – royalyadnesh