嗨,如果我想编码“直到输入文件的结尾不是”来找出要写什么代码的程序,我想这是由于一个错误。非常感谢你
15/07/01 13:05:11 INFO mapreduce.Job: Task Id : attempt_1435769899158_0001_m_000000_1, Status : FAILED
Error: java.lang.ArrayIndexOutOfBoundsException: 1
15/07/01 13:05:28 INFO mapreduce.Job: Job job_1435769899158_0001 failed with state FAILED due to: Task failed task_1435769899158_0001_m_000000
Job failed as tasks failed. failedMaps:1 failedReduces:0
code:
import java.io.IOException;
import java.util.*;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.conf.*;
import org.apache.hadoop.io.*;
import org.apache.hadoop.mapreduce.*;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.input.TextInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
import org.apache.hadoop.mapreduce.lib.output.TextOutputFormat;
public class MatrixSum {
public static class Map extends Mapper<LongWritable, Text, Text, Text> {
public void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
Configuration conf = context.getConfiguration();
String line = value.toString();
String[] indicesAndValue = line.split(",");
Text outputKey = new Text();
Text outputValue = new Text();
//只要输入文件不是结尾؟؟؟؟؟؟
if (indicesAndValue[0].equals("A")) {
outputKey.set(indicesAndValue[1] + "," + indicesAndValue[2]);
outputValue.set("A," + indicesAndValue[2] + "," + indicesAndValue[3]);
context.write(outputKey, outputValue);
} else {
outputKey.set(indicesAndValue[1] + "," + indicesAndValue[2]);
outputValue.set("B," + indicesAndValue[2] + "," + indicesAndValue[3]);
context.write(outputKey, outputValue);
}
}
}
}
1条答案
按热度按时间s6fujrry1#
问题解决了:在if之前先放开if,直到输入文件的末尾和空白行读取。它读起来像一个空白行,显示错误消息