내 작업은 중복을 유지하면서 텍스트 파일에 포함 된 모든 단어를 alpahbetically 정렬 된 목록을 반환하는 것입니다.Hadoop MapReduce : 텍스트 파일의 정렬 된 단어 목록을 반환하십시오.
는 {수 또는 수 없습니다} - →
내 생각은 키뿐만 아니라 값으로 각 말을하는 것입니다 {없다거나하는 일}. 이렇게하면, hadoop이 키를 정렬하기 때문에 자동으로 알파벳순으로 정렬됩니다. Reduce 단계에서 나는 하나의 Text 값에 동일한 키 (기본적으로 동일한 단어)를 가진 모든 단어를 간단하게 추가합니다.
public class WordSort {
public static class Map extends Mapper<LongWritable, Text, Text, Text> {
private Text word = new Text();
public void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
String line = value.toString();
StringTokenizer tokenizer = new StringTokenizer(line);
while (tokenizer.hasMoreTokens()) {
word.set(tokenizer.nextToken());
// transform to lower case
String lower = word.toString().toLowerCase();
context.write(new Text(lower), new Text(lower));
}
}
}
public static class Reduce extends Reducer<Text, Text, Text, Text> {
public void reduce(Text key, Iterable<Text> values, Context context) throws IOException, InterruptedException {
String result = "";
for (Text value : values){
res += value.toString() + " ";
}
context.write(key, new Text(result));
}
}
그러나 내 문제는 단순히 출력 파일의 값을 반환하는 것입니다.
이be be be
not not
or or
to to to
그래서 모든 라인에서 나는 값을 다음 키 제를 가지고,하지만 난 그냥 얻을 수 있도록 값을 반환 할이 :
be be
not
or
to to
순간에 나는이 있습니다 이것은 심지어 가능하거나 각 단어의 값에서 한 항목 만 삭제해야합니까?
아, 난 그냥 빈 값 명백한 해결책이 내뿜는 냉온 생각했다 : D를! 네, maprecude로 작업을 해결하는 것은 나에게 이상한 것 같습니다 ...하지만 그것을 만들지 않았다 .. 내 선생님 않았다. – gaussd
실제로 Map/Reduce의 "map"부분 만 사용하는 상황이 많이 있습니다 ... –