繁体   English   中英

编写一个空的MapReduce作业

[英]Write an empty MapReduce job

我想写一个空的mapreduce作业,实际上我的意思是不做任何事情的Mapreduce作业,只是有一个Mapper,Reducer和一个主类。 我想要在hortonwoks sandbox 2.1中进行测试。 这是我的代码:

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.mapred.*;
import org.apache.hadoop.util.*;

public class MainClassName {

  public static class Map extends MapReduceBase 
    implements Mapper<IntWritable, Text, IntWritable, Text> 
  {
    private final static IntWritable one = new IntWritable(1);
    private Text word = new Text();

    public void map(LongWritable key, Text value, 
      OutputCollector<Text, IntWritable> output, 
      Reporter reporter) throws IOException 
    {
      output.collect(word, one);
    }
  }

  public static class Reduce extends MapReduceBase 
    implements Reducer<Text, IntWritable, Text, IntWritable> 
  {
    public void reduce(Text key, Iterator<IntWritable> values, 
      OutputCollector<Text, IntWritable> output, Reporter reporter) 
      throws IOException 
    {
      int data = 0;
      }
      output.collect(key, new IntWritable(data));
    }
  }

  public static void main(String[] args) throws Exception 
  {
    JobConf conf = new JobConf(MainClassName.class);
    conf.setJobName("JobName");

    conf.setOutputKeyClass(Text.class);
    conf.setOutputValueClass(IntWritable.class);

    conf.setMapperClass(Map.class);
    conf.setCombinerClass(Reduce.class);
    conf.setReducerClass(Reduce.class);

    conf.setInputFormat(TextInputFormat.class);
    conf.setOutputFormat(TextOutputFormat.class);

    FileInputFormat.setInputPaths(conf, new Path(args[0]));
    FileOutputFormat.setOutputPath(conf, new Path(args[1]));

    JobClient.runJob(conf);
  }
}

这是正确的吗? 但这给了我一个错误:

说明资源路径位置类型MainClassName.Map类型必须实现继承的抽象方法Mapper.map(Text,Text,OutputCollector,Reporter)MainClassName.java / mainempty / src第14行Java问题

我也想知道必须导入哪些Java文件才能运行简单的作业。 非常感谢。 :)

您的类型参数有些混乱。 您的映射器正在使用<LongWritable,Text>对,并输出<Text,IntWritable>对。 但是您的类声明说:

implements Mapper<IntWritable, Text, IntWritable, Text> 

哪个应该读

implements Mapper<LongWritable, Text, Text, LongWritable>

其余的看起来还可以。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM