예를 들어 WordCount을 사용 중이며 축소 기능에서 파일 이름을 가져와야합니다.Hadoop에서 현재 파일 이름을 얻는 방법 Reduce
public static class Reduce extends MapReduceBase implements Reducer<Text, IntWritable, Text, IntWritable> {
public void reduce(Text key, Iterator<IntWritable> values, OutputCollector<Text, IntWritable> output, Reporter reporter) throws IOException {
int sum = 0;
while (values.hasNext()) {
sum += values.next().get();
}
String filename = ((FileSplit)(.getContext()).getInputSplit()).getPath().getName();
// ----------------------------^ I need to get the context and filename!
key.set(key.toString() + " (" + filename + ")");
output.collect(key, new IntWritable(sum));
}
}
위의 수정 된 코드는 현재 단어의 파일 이름을 인쇄하고 싶습니다. Java Hadoop: How can I create mappers that take as input files and give an output which is the number of lines in each file?을 시도했지만 context
개체를 가져올 수 없습니다.
나는 hadoop을 처음 사용하여이 도움이 필요합니다. 도움이 필요한가요?
오래된 api 대신 새로운 api를 선호하는 이유는 무엇입니까? 둘 다 지원 될 것이라고 생각합니다. 아마도 나는 최신 정보가 아닙니다. –
이전 API의 reduce 함수에서 파일 이름을 얻는 방법은 무엇입니까? –