0
그래서 저는 Hadoop을 배우고 잘 작동하는 WordCount.java 자습서를 사용해 보았습니다. 나는 그것으로 제로 문제가있다. 내 유일한 문제는 출력 파일에서 내 결과를 얻었을 때 String을 직접 추가하고 싶다는 것이다. 그래서 내가 읽은 다른 파일이 있다고 말하게합니다. 예를 들어 읽을 수 있어야합니다. 하둡의 출력 형식 및 가독성
// Results here
// More results
========= Output 1 =========
// Results here
============================
========= Output 2 =========
// 2nd Results here
============================
보다는
나는 본질적으로 출력 파일로 출력 한 시간을 보낼 수 있어야합니다. 가장 좋은 장소/방법은 무엇입니까? 나는 그것이 주에있을 것이라고 생각하고있다. 그러나 나는 확실하지 않다. hadoop은이 용도로 설계 되었습니까? 아니면 출력 파일을 꽤 만드는데 일종의 bash 스크립트를 사용해야합니까? 아래코드,
import java.io.IOException;
import java.util.*;
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<LongWritable, Text, Text, IntWritable> {
private final static IntWritable one = new IntWritable(1);
private Text word = new Text();
public void map(LongWritable key, Text value, OutputCollector<Text, IntWritable> output, Reporter reporter) throws IOException {
String line = value.toString();
StringTokenizer tokenizer = new StringTokenizer(line);
while (tokenizer.hasMoreTokens()) {
word.set(tokenizer.nextToken());
output.collect(word, one);
}
}
}
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();
}
output.collect(key, new IntWritable(sum));
}
}
public static void main(String[] args) throws Exception {
JobConf conf = new JobConf(WordCount.class);
conf.setJobName("wordcount");
conf.setOutputKeyClass(Text.class);
conf.setOutputValueClass(IntWritable.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);
}
}