我想爲以下數據運行MapReduce程序。當讀取csv中的空單元格時ArrayIndexOutofBounds MapReduce
這是我的映射代碼:
@Override
protected void map(Object key, Text value, Mapper.Context context) throws IOException, ArrayIndexOutOfBoundsException,InterruptedException {
String tokens[]=value.toString().split(",");
if(tokens[6]!=null){
context.write(new Text(tokens[6]), new IntWritable(1));
}
}
由於我的一些單元的數據是空的,當我試圖讀取該列Carrier_delay我得到下面的錯誤。請指教。
17/04/13 20:45:29 INFO mapreduce.Job: Task Id : attempt_1491849620104_0017_m_000000_0, Status : FAILED
Error: java.lang.ArrayIndexOutOfBoundsException: 6
at Test.TestMapper.map(TestMapper.java:22)
at Test.TestMapper.map(TestMapper.java:17)
at org.apache.hadoop.mapreduce.Mapper.run(Mapper.java:145)
at org.apache.hadoop.mapred.MapTask.runNewMapper(MapTask.java:764)
at org.apache.hadoop.mapred.MapTask.run(MapTask.java:340)
at org.apache.hadoop.mapred.YarnChild$2.run(YarnChild.java:168)
at java.security.AccessController.doPrivileged(Native Method)
at javax.security.auth.Subject.doAs(Subject.java:422)
Configuration conf = new Configuration();
Job job = Job.getInstance(conf,"IP Access");
job.setJarByClass(Test.class);
job.setMapperClass(TestMapper.class);
job.setMapOutputKeyClass(Text.class);
job.setMapOutputValueClass(IntWritable.class);
job.setReducerClass(TestReducer.class);
job.setOutputKeyClass(Text.class);
job.setOutputValueClass(IntWritable.class);
FileInputFormat.addInputPath(job, new Path(args[0]));
FileOutputFormat.setOutputPath(job, new Path(args[1]));
System.exit(job.waitForCompletion(true) ? 0 : 1);
非常感謝它的工作 – Harish