我正在尝试使用MR来查找州的全部未注册信息, 下面是示例数据存储, 第1条记录(telangana(3)是状态,第8个字段是注册成功或失败) 印度银行,Frontech Systems Pvt Ltd,Telangana,Nalgonda,Miryalaguda,508207,M,1,3,0,0,3
印度银行,Frontech Systems Pvt Ltd,Telangana,Nalgonda,Miryalaguda,508207,M,1,2、0、0、2
我应该得到输出 telanga 1 telanga 1 telanga 2 但我越来越 telanga 1 telanga 1
以下是我的Mapper代码:-
public class adhaarmapper extends Mapper < LongWritable,Text,Text,IntWritable>
{
@Override
public void map(LongWritable key,Text value,Context context)
throws IOException,InterruptedException {
String[] adhaar_info=value.toString().split(",");
String State= adhaar_info[2].toString();
// String adhaar_generated= adhaar_info[8];
int adhaar_generated=Integer.parseInt(adhaar_info[8]);
context.write(new Text(State), new IntWritable(adhaar_generated));
}
}
减速器代码:-
package aadhaaranalysis;
import java.io.IOException;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;
public class aadhaarrducer extends Reducer <Text,Text,Text,IntWritable>{
public void reduce (Text key,Iterable<IntWritable> values,Context context)
throws IOException, InterruptedException{
int count=0;
for (IntWritable value : values){
count+=value.get();
}
context.write(key, new IntWritable(count));
}
}