Hadoop 我的MapReduce工作失败了

Hadoop 我的MapReduce工作失败了,hadoop,mapreduce,word-count,Hadoop,Mapreduce,Word Count,在Eclipse中有一个mapreduce程序。我想运行它。。我从下面的url跟踪该程序: http://www.orzota.com/step-by-step-mapreduce-programming/ 我做页面上说的所有事情并运行程序。但这表明我犯了错误,我的工作失败了。。程序无法创建输出文件夹,但该文件夹为空。。 这是我的cod: package org.orzota.bookx.mappers; import java.io.IOException; import org.apac

在Eclipse中有一个mapreduce程序。我想运行它。。我从下面的url跟踪该程序:

http://www.orzota.com/step-by-step-mapreduce-programming/
我做页面上说的所有事情并运行程序。但这表明我犯了错误,我的工作失败了。。程序无法创建输出文件夹,但该文件夹为空。。 这是我的cod:

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("\";\"");
    output.collect(new Text(bookdata[3]), one);
  }

   }

public class MyHadoopReducer extends MapReduceBase implements Reducer<Text, IntWritable, Text, IntWritable>{

public void reduce(Text _key, Iterator<IntWritable> values, OutputCollector<Text, IntWritable> output, Reporter reporter) throws IOException {
    Text key = _key;
    int freq = 0;
    while (values.hasNext()){
        IntWritable value = (IntWritable) values.next();
        freq += value.get();
    }
    output.collect(key, new IntWritable(freq));
  }
  }


public class MyHadoopDriver {

public static void main(String[] args) {
    JobClient client = new JobClient();
    JobConf conf = new JobConf(
            org.orzota.bookx.mappers.MyHadoopDriver.class);
    conf.setJobName("BookCrossing1.0");


    // TODO: specify output types
    conf.setOutputKeyClass(Text.class);
    conf.setOutputValueClass(IntWritable.class);


    // TODO: specify a mapper
    conf.setMapperClass(org.orzota.bookx.mappers.MyHadoopMapper.class);

    // TODO: specify a reducer
    conf.setReducerClass(org.orzota.bookx.mappers.MyHadoopReducer.class);

    conf.setInputFormat(TextInputFormat.class);
    conf.setOutputFormat(TextOutputFormat.class);


    FileInputFormat.setInputPaths(conf, new Path(args[0]));
    FileOutputFormat.setOutputPath(conf, new Path(args[1]));


    client.setConf(conf);
    try {
        JobClient.runJob(conf);
    } catch (Exception e) {
        e.printStackTrace();
    }
  }

   }
我认为错误来自这一行:

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

但我不知道上面说什么。。有人能帮我吗?谢谢。

您正在读取的输入文件很可能有一行没有4列

因此,当您将行拆分为数组时

String[] bookdata = st.split("\";\"");
您想访问第四个元素

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

它失败。

您正在读取的输入文件很可能有一行没有4列

因此,当您将行拆分为数组时

String[] bookdata = st.split("\";\"");
您想访问第四个元素

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

失败。

我检查了您提供的链接。我认为最好的方法是对输入键值对(在输入数据集的一小部分上)执行system.out.println(),以确保这一点。如果您正在使用的输入文件包含“\n”,则csv记录可能被分为两个单独的记录,其中包含的子字符串少于8个。BoundsException的
阵列似乎指向这个方向。我不认为这是mapreduce的错误。您还可以将以下行添加到映射函数中:

if (bookdata.length!=8){
  System.out.println("Warning, bad entry");
  return; 
}

如果模拟成功,您已经隔离了问题。

我检查了您提供的链接。我认为最好的方法是对输入键值对(在输入数据集的一小部分上)执行system.out.println(),以确保这一点。如果您正在使用的输入文件包含“\n”,则csv记录可能被分为两个单独的记录,其中包含的子字符串少于8个。BoundsException的
阵列似乎指向这个方向。我不认为这是mapreduce的错误。您还可以将以下行添加到映射函数中:

if (bookdata.length!=8){
  System.out.println("Warning, bad entry");
  return; 
}

如果模拟成功,您已经隔离了问题。

我正在从站点中检查csv文件,分割可能存在一些问题。如果您复制粘贴了它,那么不是每个记录都用“;”分隔,还有一些记录的“;在一行上,而”在下一行上,例如以THUMBZZZ.jpg结尾"; 如果这解决了您的问题,请标记为已回答。谢谢您的回复irW。。错误解决了。。问题出在我的输入文件中。。H改变它,它就解决了…我正在从网站上检查csv文件,可能有一些分裂的问题。如果你复制粘贴了它,那么不是每个记录都用“;”分隔,还有一些地方“在一行上”和“在下一行上,例如以THUMBZZZ.jpg结尾”;如果这解决了你的问题,请标记为已回答。谢谢你的回复irW..错误已解决..问题来自我的输入文件..H更改它,问题已解决。。。