하둡으로 작업 중입니다. 내 출력이 예상보다 두 배오고 있습니다 ().
왜 이런 일이 발생하는지 이해할 수 없습니다.
다음 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이어야한다.
코드는 나에게 잘 보입니다. 이 일을 어떻게 부르니? YARN cmd-line을 게시하고 HDFS의 파일 구조에 대해보고 할 수 있습니까? –