在hadoop中,控制不会转到reducer



我在hadoop中编写了一个自定义的输入格式和数据类型,可以读取图像,将其存储到RGB数组中。但是当我在我的map和reduce函数中实现时,控件不会转到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"

如果我的数据类型只在映射器中使用,那么一切都很好。你能猜出问题在哪里吗?

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

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

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

相关内容

  • 没有找到相关文章

最新更新