Я получаю индекс привязки индекса массива исключения в программе Map. Ниже приведены данные и программа mapreduce.java.lang.ArrayIndexOutOfBoundsException в программе Hadoop mapreduce
данных:
1, Раджа, 10,10000
2, Jyo, 10,10000
3, тедж, 11,20000
4, tej1,11 , 20000
MapReduce Программа:
public static class EmployMap extends Mapper<LongWritable, Text, Text, IntWritable>
{
String dNname;
public void map(LongWritable k,Text v,Context con) throws IOException, InterruptedException{
String text=v.toString();
String[] textArry=text.split(",");
System.out.println(textArry.length);
int dNo=Integer.parseInt(textArry[2]);
int sal=Integer.parseInt(textArry[3]);
if(dNo==10){
dNname="Automation";
}else{
dNname="Manual";
}
con.write(new Text(dNname), new IntWritable(sal));
}
}
public static class EmployReduce extends Reducer<Text, IntWritable, Text, IntWritable>{
int totalSal;
public void reduce(Text k, Iterable<IntWritable> v,Context con) throws IOException, InterruptedException{
for(IntWritable val:v){
totalSal+=val.get();
}
con.write(k, new IntWritable(totalSal));
}
}
public static void main(String[] args) throws IOException, ClassNotFoundException, InterruptedException {
Configuration conf=new Configuration();
Path input=new Path(args[0]);
Path output=new Path(args[1]);
Job job=Job.getInstance(conf);
job.setJarByClass(Employ.class);
job.setMapperClass(EmployMap.class);
job.setReducerClass(EmployReduce.class);
job.setOutputKeyClass(Text.class);
job.setOutputValueClass(IntWritable.class);
FileInputFormat.addInputPath(job, input);
FileOutputFormat.setOutputPath(job, output);
System.exit(job.waitForCompletion(true) ? 0:1);
}
}
Журналы ошибок
Error: java.lang.ArrayIndexOutOfBoundsException: 2
at Employ$EmployMap.map(Employ.java:21)
at Employ$EmployMap.map(Employ.java:1)
at org.apache.hadoop.mapreduce.Mapper.run(Mapper.java:146)
at org.apache.hadoop.mapred.MapTask.runNewMapper(MapTask.java:787)
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:422)
at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1657)
at org.apache.hadoop.mapred.YarnChild.main(YarnChild.java:158)
Ошибка в строке 21, т.е. на "INT Дно = Integer.parseInt (textArry [2]);" может кто-нибудь помочь мне понять, что не так с кодом?
Похоже, что у вас есть лишняя пустая строка в ваших данных. Пожалуйста, проверьте вывод 'System.out.println (textArry.length);' перед ошибкой. Также вы можете добавить условие в свой код для проверки длины массива перед доступом к данным из определенного индекса в массиве. –