首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Hadoop MapReduce总排序字数

Hadoop MapReduce总排序字数
EN

Stack Overflow用户
提问于 2015-09-03 15:12:25
回答 1查看 439关注 0票数 1

我想在mapreduce计数中做一个完整的排序。

代码语言:javascript
复制
public int run(String[] args) throws Exception {
  Job job = Job.getInstance(getConf(), "wordcount");
  job.setJarByClass(this.getClass());
  FileInputFormat.addInputPath(job, new Path(args[0]));
  FileOutputFormat.setOutputPath(job, new Path(args[1]));
  job.setMapperClass(Map.class);

  //Total Sort
  job.setPartitionerClass(TotalOrderPartitioner.class);
  InputSampler.Sampler<Text, IntWritable> sampler = new InputSampler.RandomSampler<Text, IntWritable>(0.1, 10000, 10);
  InputSampler.writePartitionFile(job, sampler);
  Path inputDir = new Path(args[2] + "/_tmp");
  Path partitionFile = new Path(inputDir, "_partitioning");
  TotalOrderPartitioner.setPartitionFile(job.getConfiguration(),partitionFile);
  InputSampler.writePartitionFile(job, sampler);

  job.setReducerClass(Reduce.class);
  job.setOutputKeyClass(Text.class);
  job.setOutputValueClass(IntWritable.class);  

  return job.waitForCompletion(true) ? 0 : 1;
}

但我遇到了像java.io.IOException: wrong key class: org.apache.hadoop.io.Text is not class org.apache.hadoop.io.LongWritable这样的错误

我不明白InputSampler.RandomSampler是如何工作的。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-09-07 13:53:42

在上面的代码中,没有为作业设置InputFormat,因此将采用默认设置,即TextInputFormat<LongWritable,Text>

对于InputSampler.RandomSampler<Text, IntWritable>,它被配置为Text,IntWritable,它与TextInputFormat不匹配。

由于InputFormatInputSampler之间存在类型不匹配,因此会引发错误。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/32379460

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档