java - java.lang.ArrayIndexOutOfBoundsException错误Hadoop MapReduce进程

标签 java docker hadoop mapreduce hue

我在制作 map 减少作业来处理cdv文件时遇到一些问题。问题出在 map 处理上,但我不确定。我正在做..

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));
            }

        }
    }

但是,当我在集群中运行map减少作业时。好吧,我发现了这个错误。
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)

我不知道为什么map reduce无法读取我的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;
}

最佳答案

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

关于java - java.lang.ArrayIndexOutOfBoundsException错误Hadoop MapReduce进程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52510335/

相关文章:

docker - 容器之间的连接被拒绝

Java Spring 运行时错误

docker - 访问另一个 docker 容器中生成的数据

java - `org.junit.runner.JUnitCore` 是如何找到 `java` 的?

node.js - 从 docker 构建时安装 nodejs 时出错

linux - 连接到主机 localhost 端口 22 : Connection refused

hadoop - Oozie shell 操作 - 运行 sqoop 命令并需要日志记录详细信息

hadoop - 无法使用直线连接到配置单元,用户 root 无法模拟匿名

java - SLF4J-Logback : Multiple Pattern based on Log Level

java - Spring JDBCTemplate Mysql 从 Mysql 驱动程序抛出 ArrayIndxOutofBound