2014-11-14 3 views
2

하둡으로 작업 중입니다. 내 출력이 예상보다 두 배오고 있습니다 ().
왜 이런 일이 발생하는지 이해할 수 없습니다.
다음 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~10


샘플 출력 출력은 0~5 대신 10 0이어야한다.

+0

코드는 나에게 잘 보입니다. 이 일을 어떻게 부르니? YARN cmd-line을 게시하고 HDFS의 파일 구조에 대해보고 할 수 있습니까? –

답변

1

프로그램이 정상인 것 같습니다. 코드를 복사하여 내 컴퓨터에서 실행했습니다. 올바른 결과 즉, 0을 제공합니다.

이클립스를 사용하는 경우 새 구성을 만들고 입력 디렉토리도 변경하십시오.
그러면 작동 할 수 있습니다.

+0

나는 당신이 말한 것을 시도했습니다. 여전히 효과가 없습니다. – royalyadnesh

관련 문제