我有一個輸入文件地圖降低輸出不正確
UserId|TrackId|Shared|Radio|Skip
111115|222|0|1|0
111113|225|1|0|0
111117|223|0|1|1
111115|225|1|0|0
我需要添加共享以及無線列所有軌道ID 輸出應該
222,1
223,1
225,2
通過以下程序我寫的,我得到
222,1
223,1
225,1
225,2.
不知道錯誤是什麼
這是我的計劃
public class Total {
public static class ListenMap extends Mapper<LongWritable, Text, Text, IntWritable>
{
public void map(LongWritable key, Text values, Context context) throws IOException, InterruptedException
{
String slt= values.toString();
String arr[]= slt.split("[|]");
String trackid= arr[1];
String shared= arr[2];
String radio= arr[3];
int sharenum= Integer.parseInt(shared);
int radionum= Integer.parseInt(radio);
int total= sharenum+radionum;
context.write(new Text(trackid), new IntWritable(total));
}
}
public static class ListenReduce extends Reducer<Text, IntWritable, Text, IntWritable>
{
public void reduce(Text key, Iterable<IntWritable> values, Context context) throws IOException, InterruptedException
{
int sum=0;
for(IntWritable x: values)
{
sum+=x.get();
context.write(key, new IntWritable(sum));
}
}
}
public static void main(String[] args) throws IOException, InterruptedException, ClassNotFoundException{
Configuration conf= new Configuration();
Job job= new Job(conf, "listen");
job.setJarByClass(Total.class);
job.setMapperClass(ListenMap.class);
job.setReducerClass(ListenReduce.class);
job.setOutputKeyClass(Text.class);
job.setOutputValueClass(IntWritable.class);
job.setInputFormatClass(TextInputFormat.class);
job.setOutputFormatClass(TextOutputFormat.class);
FileInputFormat.addInputPath(job, new Path(args[0]));
FileOutputFormat.setOutputPath(job, new Path(args[1]));
System.exit(job.waitForCompletion(true)? 1:0);
}
}
謝謝你所有的工作! – Harshi