控制不是去hadoop的减速器

时间:2014-07-05 04:37:49

标签: java hadoop mapreduce

我在hadoop中编写了一个自定义inputformat和数据类型,它可以读取图像,将其存储到RGB数组中。但是当我在我的地图中实现并减少函数时,控件不会转到reducer函数。

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.mapreduce.*;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
import org.apache.hadoop.mapreduce.lib.output.TextOutputFormat;

public class Image {

    public static class Map extends Mapper<Text, ImageM, Text, ImageM> {

        public void map(Text key, ImageM value, Context context) throws IOException,     
        InterruptedException {
          /*
           for(int i=0;i<value.Height;i++)
           {
               System.out.println();
               for(int j=0;j<value.Width;j++)
               {
                   System.out.print(" "+value.Blue[i][j]);
               }
           }       
           */
           context.write(key, value);


        } 
    }

    public static class Reduce extends Reducer<Text, ImageM, Text, IntWritable> {

        public void reduce(Text key, ImageM value, Context context) 
         throws IOException, InterruptedException {

           for(int i=0;i<value.Height;i++)
           {
               System.out.println();
               for(int j=0;j<value.Width;j++)
               {
                   System.out.print(value.Blue[i][j]+" ");
               }
           }
           IntWritable m = new IntWritable(10);
           context.write(key, m);
        }
    }

    public static void main(String[] args) throws Exception {
        Configuration conf = new Configuration();

        Job job = new Job(conf, "wordcount");

        job.setOutputKeyClass(Text.class);
        job.setOutputValueClass(ImageM.class);

        job.setMapperClass(Map.class);
        job.setReducerClass(Reduce.class);

        job.setInputFormatClass(ImageFileInputFormat.class);
        job.setOutputFormatClass(TextOutputFormat.class);

        FileInputFormat.addInputPath(job, new Path(args[0]));
        FileOutputFormat.setOutputPath(job, new Path(args[1]));
        long start = new Date().getTime();    
        job.waitForCompletion(true);
        long end = new Date().getTime();
        System.out.println("Job took "+(end-start) + " milliseconds");
    }

}

这里map函数中的键根据输入格式给出文件名。

我得到输出为“icon2.gif ImageM @ 31093d14”

如果我的数据类型仅在mapper中使用,那么每件事都可以。 你能猜出问题出在哪里吗?

1 个答案:

答案 0 :(得分:2)

您的reduce函数签名错误。它应该是:

@Override
public void reduce(Text key, Iterable<ImageM> values, Context context) 
     throws IOException, InterruptedException

请使用@Override注释让编译器为您发现此错误。