Currently I am trying to learn Secondary Sort in map reduce but getting an error of null pointer exception while running my mapper. I am using this link but while running the code I get the error. here is my callStack .
16/06/18 13:34:53 INFO mapreduce.Job: Task Id : attempt_1466235357420_0007_m_000000_0, Status : FAILED Error: java.lang.NullPointerException at SecondartSort.SecondarySortSample1.SecondarySortMapper.map(SecondarySortMapper.java:22) at SecondartSort.SecondarySortSample1.SecondarySortMapper.map(SecondarySortMapper.java:1) at org.apache.hadoop.mapreduce.Mapper.run(Mapper.java:145) at org.apache.hadoop.mapred.MapTask.runNewMapper(MapTask.java:784) at org.apache.hadoop.mapred.MapTask.run(MapTask.java:341) at org.apache.hadoop.mapred.YarnChild$2.run(YarnChild.java:163) at java.security.AccessController.doPrivileged(Native Method) at javax.security.auth.Subject.doAs(Subject.java:415)
and my mapper code is:
public class SecondarySortMapper extends Mapper<LongWritable , Text, CustomTextInt, IntWritable> {
private CustomTextInt nameDepname;
private Text name;
private Text departmentName;
private IntWritable sal;
public void map (LongWritable key , Text value , Context context) throws IOException , InterruptedException{
String[] line = value.toString().split(",");
//String depName = line[3];
String Fullname =line[2]+line[1];
name.set(Fullname);
departmentName.set(line[3]);
nameDepname.set(name,departmentName);
sal.set(Integer.parseInt(line[4]));
context.write(nameDepname, sal);
}
}
and data file is :
1,kumar,sunil,enginering,2200
2,mishra,sunil,enginering,1200
3,arora,karan,mech,1200
4,sharma,vivek,physics,2300
5,koushik,vivek,physics,1350
6,sindhu,armaan,math,2310
7,arora,armaan,math,500
8,yadav,pooja,mech,1800
9,kuthi,pooja,math,1600
10,arora,sunil,physics,1450
11,mishra,karan,enginering,3400
12,chandra,manish,physics,2300
kindly advice
Thanks sPradeep
String[] line = value.toString().split(",");map function will call each line and pass it to value - Anaadih.pradeep