Map中的键类型不匹配:预期为org.apache.hadoop.io.text,收到org.apache.hadoop.io.longwritable;如何纠正?

1yjd4xko  于 2021-07-13  发布在  Hadoop
关注(0)|答案(0)|浏览(222)

我遇到了标题中的错误,我无法理解如何完成此Map函数以创建以下reduce函数。有什么线索吗(用于处理的数据来自covid-19.csv文件,该文件跟踪每个国家、地区等的每个新病例。)
分配给我的请求如下:“return the total number of cases per continent”,因此我想创建一个由(key=continent,value=new\u cases)组成的键值对。
在这里,我按“map class”、“driver class”的顺序说明代码:

  1. package ContTotCase;
  2. import java.io.IOException;
  3. import org.apache.hadoop.io.LongWritable;
  4. import org.apache.hadoop.io.Text;
  5. import org.apache.hadoop.mapred.OutputCollector;
  6. import org.apache.hadoop.mapreduce.*;
  7. public class ContTotCasesMap extends Mapper<Text, LongWritable, Text, LongWritable>
  8. {
  9. public void Map(Text key, LongWritable value, OutputCollector<Text, LongWritable> output) throws IOException, InterruptedException
  10. {
  11. String[] query1 = (value.toString()).split(",");
  12. String parseBase = query1[5];
  13. int parsed = Integer.parseInt(parseBase.trim());
  14. if(parsed > 0)
  15. {
  16. output.collect(new Text(query1[1]), new LongWritable(parsed));
  17. }
  18. }
  19. }

  1. package ContTotCase;
  2. import org.apache.hadoop.conf.Configuration;
  3. import org.apache.hadoop.fs.Path;
  4. import org.apache.hadoop.io.*;
  5. import org.apache.hadoop.mapreduce.Job;
  6. import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
  7. import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
  8. public class ContTotCaseDriver {
  9. public static void main(String[] args) throws Exception {
  10. if (args.length != 2) {
  11. System.err.println("Usage: ContTotCases <InPath> <OutPath>");
  12. System.exit(2);
  13. }
  14. Configuration conf = new Configuration();
  15. Job job = Job.getInstance(conf, "ContTotCases");
  16. job.setJarByClass(ContTotCasesMap.class);
  17. job.setMapperClass(ContTotCasesMap.class);
  18. job.setMapOutputKeyClass(Text.class);
  19. job.setMapOutputValueClass(LongWritable.class);
  20. job.setOutputKeyClass(Text.class);
  21. job.setOutputValueClass(LongWritable.class);
  22. FileInputFormat.addInputPath(job, new Path(args[0]));
  23. FileOutputFormat.setOutputPath(job, new Path(args[1]));
  24. System.exit(job.waitForCompletion(true) ? 0 : 1);
  25. }
  26. }

请注意,我是java的新手。。。提前谢谢!

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题