【问题标题】:Write an empty MapReduce job编写一个空的 MapReduce 作业
【发布时间】:2014-10-18 17:03:37
【问题描述】:

我想写一个空的mapreduce作业,实际上我的意思是一个什么都不做的mapreduce作业,只有一个Mapper,一个Reducer和一个主类。我希望它在 hortonwoks 沙盒 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 line 14 Java Problem

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

【问题讨论】:

    标签: java hadoop mapreduce hortonworks-data-platform


    【解决方案1】:

    您的类型参数有点混乱。您的映射器正在使用 &lt;LongWritable,Text&gt; 对,并输出 &lt;Text,IntWritable&gt; 对。但是您的班级声明说:

    implements Mapper<IntWritable, Text, IntWritable, Text> 
    

    应该读什么

    implements Mapper<LongWritable, Text, Text, LongWritable>
    

    其余的看起来还可以。

    【讨论】:

    • 非常感谢#btbamcostello
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-07-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多