java - Hadoop MapReduce 总排序字数

标签 java hadoop mapreduce

我想在mapreduce字数统计中进行总排序。

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: 错误的关键类: org.apache.hadoop.io.Text 不是类 org.apache.hadoop.io.LongWritable

的错误

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

最佳答案

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

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

由于 InputFormat 之间存在类型不匹配和InputSampler抛出错误。

关于java - Hadoop MapReduce 总排序字数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32379460/

相关文章:

java - 每次单元测试后回滚

hadoop - 通过HDP 2.3.2沙箱中的Sqoop导入表时出错

json - 如何使用 hadoop map-reduce 和 es-hadoop 将 json 索引到 elasticsearch?

hadoop - Hadoop MapReduce映射器任务从HDFS或S3读取输入文件所花费的时间

hive - hadoop WordCount 卡在 map 0% 减少 0%

java - TYPE_TEXT_VARIATION_VISIBLE_PASSWORD 适用于使用 Phonegap 的 Android

java - Maven 对原始 Spring Boot JAR 的依赖

java - 安卓中的 RestKit?

hadoop - 多行到PIG中的单个逗号分隔行

visual-studio-2010 - 在 Visual Studio 中调试 MapReduce 程序