在Hadoop中找不到"KeyValueInputFormat"



我是Hadoop的新手,但已经阅读了雅虎关于这方面的教程,并且已经编写了一些mapReduce作业。我以前的所有作品都使用了TextInputFormat,但现在我需要将其更改为KeyValueInputFormat。问题是在hadoop 0.20.2中找不到KeyValueInputFormat.class?

我在下面附上我的代码(这是单词计数的例子,只有输入格式被更改)

package org.myorg;
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 WordCount {
  public static class Map extends MapReduceBase implements Mapper<LongWritable, Text, Text, IntWritable> {
    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 {
      String line = value.toString();
      StringTokenizer tokenizer = new StringTokenizer(line);
      while (tokenizer.hasMoreTokens()) {
        word.set(tokenizer.nextToken());
        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 sum = 0;
          while (values.hasNext()) {
            sum += values.next().get();
          }
          output.collect(key, new IntWritable(sum));
        }
      }
      public static void main(String[] args) throws Exception {
        JobConf conf = new JobConf(WordCount.class);
        conf.setJobName("wordcount");
        conf.setOutputKeyClass(Text.class);
        conf.setOutputValueClass(IntWritable.class);
        conf.setMapperClass(Map.class);
        conf.setCombinerClass(Reduce.class);
        conf.setReducerClass(Reduce.class);
        conf.setInputFormat(keyValueInputFormat.class);  //The modified input format
        conf.setOutputFormat(TextOutputFormat.class);
        FileInputFormat.setInputPaths(conf, new Path(args[0]));
        FileOutputFormat.setOutputPath(conf, new Path(args[1]));
        JobClient.runJob(conf);
      }
    }

org.apache.hadoop.mapreduce.lib.input.中存在KeyValueTextInputFormat

一些旧的教程基于Hadoop API的旧版本。我建议您浏览一些较新的教程。

这就是当我转到KeyValueTextInputFormat的源代码时得到的结果。

package org.apache.hadoop.mapreduce.lib.input;
import java.io.IOException;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.InputSplit;
import org.apache.hadoop.mapreduce.JobContext;
import org.apache.hadoop.mapreduce.RecordReader;
import org.apache.hadoop.mapreduce.TaskAttemptContext;
public class KeyValueTextInputFormat extends FileInputFormat<Text, Text> {
public KeyValueTextInputFormat() {
    //compiled code
    throw new RuntimeException("Compiled Code");
}
protected boolean isSplitable(JobContext context, Path file) {
    //compiled code
    throw new RuntimeException("Compiled Code");
}
public RecordReader<Text, Text> createRecordReader(InputSplit genericSplit,     TaskAttemptContext context) throws IOException {
    //compiled code
    throw new RuntimeException("Compiled Code");
}
}

相关内容

  • 没有找到相关文章

最新更新