Error with java.lang.ArrayIndexOutOfBoundsException Hadoop M



我在制作用于处理 cdv 文件的地图减少作业时遇到了一些问题。问题出在地图过程上,但我不确定。我在做..

public void map(Object key, Text value, Context context) throws IOException, InterruptedException {
final String[] arrayCsv = value.toString().split(DELIMETER);
LOG.info("This file has " + arrayCsv.length);
final String victimas = format(arrayCsv[19]);
final int intValue = NumberUtils.toInt(victimas);
for (int i = 0; i < arrayCsv.length; i++) {
String name = getNameById(i);
if (i > 6 && i < 20 && validBooleanStatus(name)) {
context.write(new Text(name), new IntWritable(intValue));
}
}
}

但是当我在集群中运行地图减少作业时。好吧,我发现了这个错误。

Error: java.lang.ArrayIndexOutOfBoundsException: 19
at com.master.tarea.Task$MaperSolution.map(Task.java:99)
at com.master.tarea.Task$MaperSolution.map(Task.java:83)
at org.apache.hadoop.mapreduce.Mapper.run(Mapper.java:145)
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:164)
at java.security.AccessController.doPrivileged(Native Method)
at javax.security.auth.Subject.doAs(Subject.java:415)
at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1693)
at org.apache.hadoop.mapred.YarnChild.main(YarnChild.java:158)

我不知道为什么地图减少无法读取我的csv文件,但似乎该文件不存在。如果您发现代码存在一些问题,请告诉我。非常感谢你能给我的任何帮助!!

编辑

这是我的工作代码...

public int run(String[] args) throws Exception {
System.err.println("ENTRADA ........" + args[0]);
System.err.println("SALIDA.........." + args[1]);
if (args.length != 2) {
System.err.println("AccidentMapReduce required params: {input file} {output dir}");
System.exit(-1);
}
deleteOutputFileIfExists(args);
final Job job = new Job(getConf());
job.setJarByClass(Task.class);
job.setInputFormatClass(TextInputFormat.class);
job.setOutputFormatClass(TextOutputFormat.class);
job.setMapperClass(MaperSolution.class);
job.setReducerClass(ReducerSolution.class);
job.setMapOutputKeyClass(Text.class);
job.setMapOutputValueClass(IntWritable.class);
job.setOutputKeyClass(Text.class);
job.setOutputValueClass(Text.class);
FileInputFormat.addInputPath(job, new Path(args[0]));
FileOutputFormat.setOutputPath(job, new Path(args[1]));
job.waitForCompletion(true);
return 0;
}

抛出以指示已使用非法索引访问数组。索引为负数,或者大于或等于数组的大小。

您在此行具有恒定的数组访问权限:

final String victimas = format(arrayCsv[19]);

消息说非法索引确实19。因此,我猜数组更小。所以你似乎有一个太短的csv行。

最新更新