编写一个空的mapreduce作业

tvmytwxo  于 2021-06-02  发布在  Hadoop
关注(0)|答案(1)|浏览(289)

我想写一个空的mapreduce作业,实际上我指的是一个什么都不做的mapreduce作业,只有一个Map器,一个减缩器和一个主类。我想在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/mainepty/src line 14 java problem
我还想知道运行一个简单的作业必须导入哪些java文件。非常感谢。:)

a5g8bdjr

a5g8bdjr1#

你的类型参数有点混乱。你的Map绘制者正在拍摄 <LongWritable,Text> 配对,并输出 <Text,IntWritable> 一对。但是你的班级宣言说:

implements Mapper<IntWritable, Text, IntWritable, Text>

应该是

implements Mapper<LongWritable, Text, Text, LongWritable>

其余的看起来还可以。

相关问题