0
맵 프로그램에서 예외의 배열 인덱스 바운드가 발생합니다. 아래는 데이터 및지도 제작 프로그램입니다.Hadoop mapreduce 프로그램의 java.lang.ArrayIndexOutOfBoundsException
데이터 :
1 라자 10,10000
2 jyo, 10,10000
3 TEJ, 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 DNO있는 Integer.parseInt (textArry [2]);" 어떤 사람이 코드에 무슨 문제가 있는지 이해할 수 있습니까?
데이터에 빈 행이있는 것 같습니다. 오류가 발생하기 전에'System.out.println (textArry.length);'의 출력을 확인하십시오. 또한 배열의 특정 인덱스에서 데이터에 액세스하기 전에 배열 길이를 확인하기 위해 코드에 조건을 추가 할 수 있습니다. –