여러 파일에 존재하는 단어를 '유일한'목록으로 표시 할 수있는 코드를 실행하려고했습니다. 지금까지 내가 한 일은 Chris White에게 wordcount 예제와 고맙습니다. 저는 그것을 컴파일 할 수있었습니다. 나는 여기저기서 코드를 작동 시키려고 노력했지만, 나는 데이터가없는 빈 페이지 만 얻는다. 매퍼는 각 단어를 해당 위치와 함께 수집한다고 가정합니다. 감속기는 무엇이 문제인지에 관한 어떤 생각이라도 공통 단어를 수집한다고 가정합니다. 코드는 다음과 같습니다.hadoop mapreduce를 사용하는 파일의 상호 단어
package org.myorg;
import java.io.IOException;
import java.util.*;
import java.lang.*;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.conf.*;
import org.apache.hadoop.io.*;
import org.apache.hadoop.mapred.*;
import org.apache.hadoop.util.*;
public class WordCount {
public static class Map extends MapReduceBase implements Mapper<Text, Text, Text, Text>
{
private final static IntWritable one = new IntWritable(1);
private Text word = new Text();
private Text outvalue=new Text();
private String filename = null;
public void map(Text key, Text value, OutputCollector<Text, Text> output, Reporter reporter) throws IOException
{
if (filename == null)
{
filename = ((FileSplit) reporter.getInputSplit()).getPath().getName();
}
String line = value.toString();
StringTokenizer tokenizer = new StringTokenizer(line);
while (tokenizer.hasMoreTokens())
{
word.set(tokenizer.nextToken());
outvalue.set(filename);
output.collect(word, outvalue);
}
}
}
public static class Reduce extends MapReduceBase implements Reducer<Text, Text, Text, Text>
{
private Text src = new Text();
public void reduce(Text key, Iterator<Text> values, OutputCollector<Text, Text> output, Reporter reporter) throws IOException
{
int sum = 0;
//List<Text> list = new ArrayList<Text>();
while (values.hasNext()) // I believe this would have all locations of the same word in different files?
{
sum += values.next().get();
src =values.next().get();
}
output.collect(key, src);
//while(values.hasNext())
//{
//Text value = values.next();
//list.add(new Text(value));
//System.out.println(value.toString());
//}
//System.out.println(values.toString());
//for(Text value : list)
//{
//System.out.println(value.toString());
//}
}
}
public static void main(String[] args) throws Exception
{
JobConf conf = new JobConf(WordCount.class);
conf.setJobName("wordcount");
conf.setInputFormat(KeyValueTextInputFormat.class);
conf.setOutputKeyClass(Text.class);
conf.setOutputValueClass(Text.class);
conf.setMapperClass(Map.class);
conf.setCombinerClass(Reduce.class);
conf.setReducerClass(Reduce.class);
//conf.setInputFormat(TextInputFormat.class);
conf.setOutputFormat(TextOutputFormat.class);
FileInputFormat.setInputPaths(conf, new Path(args[0]));
FileOutputFormat.setOutputPath(conf, new Path(args[1]));
JobClient.runJob(conf);
}
}
나는 무엇이 누락 되었습니까? 많은 의무 ... 내 하둡 버전 : 당신이 이전 하둡 API (mapred)를 사용하고, 조언의 단어가 새로운 하둡 API를 사용하는 것 같다 모든 0.20.203
http://stackoverflow.com/questions/10086818/wordcount-common-words-of-files 내가 계속 많은 사람들을 본 적이 있기 때문에 새로운 API를 사용하도록 제안 원래의 질문 –