Hadoop MapReduce输出为ArrayList

Hadoop MapReduce输出为ArrayList,hadoop,mapreduce,Hadoop,Mapreduce,如何在普通java项目中调用map reduce方法,是否可以将reducer输出作为Arraylist/Hashmap而不是平面文件返回,以及如何从jboss appServer访问mapreduce方法。下面是一个使用MultipleOutput的示例程序 public void reduce(Text key, Iterator<IntWritable> values, OutputCollector<Text, IntWritable&g

如何在普通java项目中调用map reduce方法,是否可以将reducer输出作为Arraylist/Hashmap而不是平面文件返回,以及如何从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));
        }

    }
在驱动程序类中,您需要告诉要使用的所有输入格式。下面将生成文本和序列文件格式的输出

// 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下载输出文件。但最好将数据放在配置单元表中,并使用JDBC进行访问。

看看Apache MRUnit是如何做到这一点的,您可以根据自己的需要使用它。@ThomasJungblut,我通过了你的
http://stackoverflow.com/questions/9849776/calling-a-mapreduce-job-from-a-simple-java-program
要从远程服务器调用mapreduce方法,一切正常,但如何在调用MP的远程计算机中获取mapreduce的输出?从文件系统访问输出数据。@ThomasJungblut,你能分享“MultipleOutput”过程中的任何示例代码来保存多个文件吗?我使用的是Hadoop-0.20.2版本,其中更多的类,如JobConf类等,都不推荐使用。你能推荐一个稳定的Hadoop版本,它也提供MultipleOutput功能吗。谢谢您可以使用新的MR API。这是使用org.apache.hadoop.mapreduce.lib.output.MultipleOutputs而不是org.apache.hadoop.mapred.lib.MultipleOutputs。
// 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);