java - 在mapreduce程序中未调用reducer

标签 java hadoop mapreduce

我在Mapreduce程序上写了一个简单的扩展,发现我的代码仅显示Map()的输出。映射作业在eclipse中运行,没有任何错误,但不调用reduce()。

这是我的map():

public static class KVMapper 
  extends Mapper<Text, Text, IntWritable, Text>{
//        extends Mapper<Text, Text, Text, IntWritable>{
    private final static IntWritable one = new IntWritable(1);
    private String word;// = new Text();
    private IntWritable iw;
    private final LongWritable val = new LongWritable();
    public void map(Text key, Text value , Context context
                    ) throws IOException, InterruptedException {

      iw = new IntWritable(Integer.parseInt(value.toString()));
      System.out.println(value +" hello , world  " +key );
      context.write(iw, key);
      }
    }

降低()
public static class KVReducer 
       extends Reducer<IntWritable,Text,IntWritable, Text> {

      KVReducer(){

          System.out.println("Inside reducer");
      }
        public void reduce(IntWritable key, Text value, 
                       Context context
                       ) throws IOException, InterruptedException {
      System.out.println(value +" hello2 , world  " +key );
      context.write(key, value);
    }
  }

主要()
public static void main(String[] args) throws Exception {
    Configuration conf = new Configuration();
    conf.set("mapreduce.input.keyvaluelinerecordreader.key.value.separator", "\t");
    //conf.set("mapreduce.input.keyvaluelinerecordreader.key.value.separator",",");
    String[] otherArgs = new GenericOptionsParser(conf, args).getRemainingArgs();
    if (otherArgs.length < 2) {
      System.err.println("Usage: wordcount <in> [<in>...] <out>");
      System.exit(2);
    }
    Job job = new Job(conf, "word desc");
    job.setInputFormatClass(KeyValueTextInputFormat.class);
    job.setJarByClass(WordDesc.class);
    job.setMapperClass(KVMapper.class);
    job.setCombinerClass(KVReducer.class);
    job.setReducerClass(KVReducer.class);
    job.setMapOutputKeyClass(IntWritable.class);
    job.setMapOutputValueClass(Text.class);
    job.setOutputKeyClass(IntWritable.class);
    job.setOutputValueClass(Text.class);
    for (int i = 0; i < otherArgs.length - 1; ++i) {
      FileInputFormat.addInputPath(job, new Path(otherArgs[i]));
    }
    FileOutputFormat.setOutputPath(job,
      new Path(otherArgs[otherArgs.length - 1]));
    System.exit(job.waitForCompletion(true) ? 0 : 1);
  }

输入样本:
1500s   1
1960s   1
Aldus   1

在我期望映射器反转键和值对的同时,该程序的示例输出
1500s   1
1960s   1
Aldus   1

不知道为什么在上面的代码中没有调用reduce()

最佳答案

您没有覆盖reduce()类的Reducer方法。

对于您的情况,其签名应类似于public void reduce(IntWritable key, Iterable<Text> values,Context context)
这是更新的KVReducer

public static class KVReducer 
       extends Reducer<IntWritable,Text,IntWritable, Text> {

      KVReducer(){

          System.out.println("Inside reducer");
      }

      public void reduce(IntWritable key, Iterable<Text> values,Context context) throws IOException, InterruptedException {
        for(Text value: values){}
          System.out.println(value +" hello2 , world  " +key );
          context.write(key, value);
        }
      }
}

关于java - 在mapreduce程序中未调用reducer,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35472077/

相关文章:

java - 使用 FFmpegFrameGrabber 启用 ZVBI 时如何在 Javacv 下配置 ffmpeg

hadoop - 在lib文件夹中找不到与hadoop-2.7.3相关的jar

mysql - 为什么在从 hive 导出到 mysql 期间,sqoop 在数字列的 NumberFormatException 上失败

java - 收集单个 hadoop 作业的计数器和指标

python - 流式传输MapReduce文件时出错

java - Cordova 找不到 $ANDROID_HOME

java - Java中如何初始化日期类型的变量?

java - Java中MongoDB的MapReduce函数返回null

javascript - 有什么方法可以通过 java native 模块(react native bridge)访问 Realm 实例(由 javascript 代码创建)?

java - Hadoop YARN 上的 JMH 基准测试