mapreduce run后输出显示空文件
问题描述:
希望大佬能解决一下
//map代码段
import java.io.IOException;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;
public class PMMap extends Mapper<Text, LongWritable, Text, PM>{
@Override
protected void map(Text key, LongWritable value, Context context)
throws IOException, InterruptedException {
String keys =value.toString();
String[] file = keys.split(",");
String cs = file[16];
int pm = Integer.parseInt(file[3]);
context.write(new Text(cs), new PM(cs, pm));
}
}
//reduce代码段
import java.io.IOException;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;
public class PMReduce extends Reducer<Text, PM, Text, LongWritable>{
@Override
protected void reduce(Text key, Iterable<PM> value, Context context)
throws IOException, InterruptedException {
int pm = 0;
// int time = 0;
for (PM pm2 : value) {
// time++;
pm+= pm2.getPm();
}
context.write(key, new LongWritable(pm));
}
}
//run代码段
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
public class PMRun {
public static void main(String[] args)throws IOException ,ClassNotFoundException,InterruptedException{
Configuration configuration=new Configuration();
Job job=Job.getInstance(configuration);
job.setJarByClass(PMRun.class);
job.setMapperClass(PMMap.class);
job.setReducerClass(PMReduce.class);
job.setOutputKeyClass(Text.class);
job.setOutputValueClass(LongWritable.class);
job.setMapOutputKeyClass(Text.class);
job.setMapOutputValueClass(PM.class);
FileInputFormat.setInputPaths(job, "hdfs://hadoop01:9000/tmp/input");
FileOutputFormat.setOutputPath(job, new Path("hdfs://hadoop01:9000/tmp/output"));
job.waitForCompletion(true);
}
}
答
您好,我是有问必答小助手,你的问题已经有小伙伴为您解答了问题,您看下是否解决了您的问题,可以追评进行沟通哦~
如果有您比较满意的答案 / 帮您提供解决思路的答案,可以点击【采纳】按钮,给回答的小伙伴一些鼓励哦~~
ps:问答VIP仅需29元,即可享受5次/月 有问必答服务,了解详情>>>https://vip.csdn.net/askvip?utm_source=1146287632
答
非常感谢您使用有问必答服务,为了后续更快速的帮您解决问题,现诚邀您参与有问必答体验反馈。您的建议将会运用到我们的产品优化中,希望能得到您的支持与协助!
速戳参与调研>>>https://t.csdnimg.cn/Kf0y