如何在普通的Java项目中调用map reduce方法,是否有可能以Arraylist / Hashmap而不是平面文件的形式返回reducer的输出,以及如何从jboss appServer访问mapreduce方法。
最佳答案
这是一个使用MultipleOutput的示例程序
public void reduce(Text key, Iterator<IntWritable> values,
OutputCollector<Text, IntWritable> output, Reporter reporter)
throws IOException {
int total = 0;
for (; values.hasNext();) {
total += values.next().get();
mos.getCollector("text", reporter).collect(key,
new IntWritable(total));
mos.getCollector("seq", reporter).collect(key,
new IntWritable(total));
}
}
您将需要在configure方法中创建一个MultipleOutputs实例。
private MultipleOutputs mos;
@Override
public void configure(JobConf job) {
mos = new MultipleOutputs(job);
}
在驱动程序类中,您需要确定要使用的所有输入格式。下面将以文本和序列文件格式生成您的输出。
// Defines additional single text based output 'text' for the job
MultipleOutputs.addNamedOutput(conf, "text", TextOutputFormat.class,
Text.class, IntWritable.class);
// Defines additional sequence-file based output 'sequence' for the job
MultipleOutputs.addNamedOutput(conf, "seq",
SequenceFileOutputFormat.class, Text.class, IntWritable.class);
但是根据我对您的问题的理解,您基本上希望从代码中访问mapreduce输出。您可以使用HDFS API下载输出文件。但是最好将数据放在Hive表中并使用JDBC进行访问。
关于hadoop - MapReduce输出为ArrayList,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17401802/