我遇到了标题中的错误,我无法理解如何完成此Map函数以创建以下reduce函数。有什么线索吗(用于处理的数据来自covid-19.csv文件,该文件跟踪每个国家、地区等的每个新病例。)
分配给我的请求如下:“return the total number of cases per continent”,因此我想创建一个由(key=continent,value=new\u cases)组成的键值对。
在这里,我按“map class”、“driver class”的顺序说明代码:
package ContTotCase;
import java.io.IOException;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapred.OutputCollector;
import org.apache.hadoop.mapreduce.*;
public class ContTotCasesMap extends Mapper<Text, LongWritable, Text, LongWritable>
{
public void Map(Text key, LongWritable value, OutputCollector<Text, LongWritable> output) throws IOException, InterruptedException
{
String[] query1 = (value.toString()).split(",");
String parseBase = query1[5];
int parsed = Integer.parseInt(parseBase.trim());
if(parsed > 0)
{
output.collect(new Text(query1[1]), new LongWritable(parsed));
}
}
}
和
package ContTotCase;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.*;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
public class ContTotCaseDriver {
public static void main(String[] args) throws Exception {
if (args.length != 2) {
System.err.println("Usage: ContTotCases <InPath> <OutPath>");
System.exit(2);
}
Configuration conf = new Configuration();
Job job = Job.getInstance(conf, "ContTotCases");
job.setJarByClass(ContTotCasesMap.class);
job.setMapperClass(ContTotCasesMap.class);
job.setMapOutputKeyClass(Text.class);
job.setMapOutputValueClass(LongWritable.class);
job.setOutputKeyClass(Text.class);
job.setOutputValueClass(LongWritable.class);
FileInputFormat.addInputPath(job, new Path(args[0]));
FileOutputFormat.setOutputPath(job, new Path(args[1]));
System.exit(job.waitForCompletion(true) ? 0 : 1);
}
}
请注意,我是java的新手。。。提前谢谢!
暂无答案!
目前还没有任何答案,快来回答吧!