gpt4 book ai didi

java - 无法在 hadoop 上运行字数统计

转载 作者:可可西里 更新时间:2023-11-01 15:39:15 25 4
gpt4 key购买 nike

我尝试在 eclipse 中运行 hadoop 字数统计。我只是将 hadoop 目录和 hadoop/lib 目录中的所有 jar 文件添加到该项目的库中,但出现以下错误:

java.lang.Exception: java.lang.ArrayIndexOutOfBoundsException: 1
at org.apache.hadoop.mapred.LocalJobRunner$Job.run(LocalJobRunner.java:400)
Caused by: java.lang.ArrayIndexOutOfBoundsException: 1
at org.orzota.bookx.mappers.MyHadoopMapper.map(MyHadoopMapper.java:23)
at org.orzota.bookx.mappers.MyHadoopMapper.map(MyHadoopMapper.java:1)
at org.apache.hadoop.mapred.MapRunner.run(MapRunner.java:54)
at org.apache.hadoop.mapred.MapTask.runOldMapper(MapTask.java:400)
at org.apache.hadoop.mapred.MapTask.run(MapTask.java:335)
at
org.apache.hadoop.mapred.LocalJobRunner$Job$MapTaskRunnable.run(LocalJobRunner.java:232)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
at java.util.concurrent.FutureTask.run(FutureTask.java:166)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1146)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:679)
2013-10-23 18:59:20,841 INFO [main] mapreduce.Job
(Job.java:monitorAndPrintJob(1288)) Job job_local_0001 running in uber mode : false
2013-10-23 18:59:20,843 INFO [main] mapreduce.Job (Job.java:monitorAndPrintJob(1295))
map 0% reduce 0%
2013-10-23 18:59:20,847 INFO [main] mapreduce.Job (Job.java:monitorAndPrintJob(1308))
Job job_local_0001 failed with state FAILED due to: NA
2013-10-23 18:59:20,866 INFO [main] mapreduce.Job (Job.java:monitorAndPrintJob(1313))
Counters: 0
java.io.IOException: Job failed!
at org.apache.hadoop.mapred.JobClient.runJob(JobClient.java:891)
at org.orzota.bookx.mappers.MyHadoopDriver.main(MyHadoopDriver.java:46)

你能帮我解决这个问题吗?

MyhadoopMapper 是:

package org.orzota.bookx.mappers;
import java.io.IOException;
import org.apache.hadoop.io.*;
import org.apache.hadoop.mapred.MapReduceBase;
import org.apache.hadoop.mapred.Mapper;
import org.apache.hadoop.mapred.OutputCollector;
import org.apache.hadoop.mapred.Reporter;

public class MyHadoopMapper extends MapReduceBase implements Mapper <LongWritable,
Text, Text, IntWritable>{
private final static IntWritable one = new IntWritable(1);

public void map(LongWritable _key, Text value, OutputCollector<Text, IntWritable>
output, Reporter reporter) throws IOException {
String st = value.toString();
String[] bookdata = st.split(",");
//for (int i=0; i< bookdata.length; i++){
//System.out.println(bookdata[i]);
//}
//if (bookdata.length!=8){
//System.out.println("Warning, bad Entry.." + bookdata.length);
//return;
//}
output.collect(new Text(bookdata[1]), one);
}

}

最佳答案

看来错误是在下面这行:

output.collect(new Text(bookdata[1]), one);

因此,对于您遇到的异常(exception)情况,可以进行以下解释:

  • 您的输入文件中有没有 , 的行。
  • 您的输入文件中有空行。

这相当于数组 bookdata 分别有一个元素或没有元素,因此导致 ArrayIndexOutOfBoundsException

关于java - 无法在 hadoop 上运行字数统计,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19547416/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com