Saya baru menggunakan hadoop dan mengalami masalah ini. Saya mencoba mengubah nilai Teks, Bilangan Bulat default untuk peredam menjadi Teks, Teks. Saya ingin memetakan Text,IntWritable lalu di peredam saya ingin memiliki 2 penghitung tergantung nilainya dan kemudian menulis 2 penghitung tersebut dalam Teks untuk kolektor.
public class WordCountMapper extends MapReduceBase
implements Mapper<LongWritable, Text, Text, IntWritable> {
private final IntWritable one = new IntWritable(1);
private Text word = new Text();
public void map(LongWritable key, Text value, OutputCollector<Text, IntWritable>
output, Reporter reporter) throws IOException {
String line = value.toString();
String[] words = line.split(",");
String[] date = words[2].split(" ");
word.set(date[0]+" "+date[1]+" "+date[2]);
if(words[0].contains("0"))
one.set(0);
else
one.set(4);
output.collect(word, one);
}
}
-----------------------------------------------------------------------------------
public class WordCountReducer extends MapReduceBase
implements Reducer<Text, IntWritable, Text, Text> {
public void reduce(Text key,Iterator<IntWritable> values,
OutputCollector<Text, Text> output,
Reporter reporter) throws IOException {
int sad = 0;
int happy = 0;
while (values.hasNext()) {
IntWritable value = (IntWritable) values.next();
if(value.get() == 0)
sad++; // process value
else
happy++;
}
output.collect(key, new Text("sad:"+sad+", happy:"+happy));
}
}
---------------------------------------------------------------------------------
public class WordCount {
public static void main(String[] args) {
JobClient client = new JobClient();
JobConf conf = new JobConf(WordCount.class);
// specify output types
conf.setOutputKeyClass(Text.class);
conf.setOutputValueClass(IntWritable.class);
// specify input and output dirs
FileInputFormat.addInputPath(conf, new Path("input"));
FileOutputFormat.setOutputPath(conf, new Path("output"));
// specify a mapper
conf.setMapperClass(WordCountMapper.class);
// specify a reducer
conf.setReducerClass(WordCountReducer.class);
conf.setCombinerClass(WordCountReducer.class);
client.setConf(conf);
try {
JobClient.runJob(conf);
} catch (Exception e) {
e.printStackTrace();
}
}
}
Saya mendapatkan kesalahan ini:
14/12/10 18:11:01 INFO mapred.JobClient: Id Tugas : percobaan_201412100143_0008_m_000000_0, Status : GAGAL java.io.IOException: Tumpahan gagal di org.apache.hadoop.mapred.MapTask$MapOutputBuffer.collect(MapTask.java: 425) di WordCountMapper.map(WordCountMapper.java:31) di WordCountMapper.map(WordCountMapper.java:1) di org.apache.hadoop.mapred.MapRunner.run(MapRunner.java:47) di org.apache.hadoop. mapred.MapTask.run(MapTask.java:227) di org.apache.hadoop.mapred.TaskTracker$Child.main(TaskTracker.java:2209) Disebabkan oleh: java.io.IOException: kelas nilai salah: class org.apache .hadoop.io.Text bukan kelas org.apache.hadoop.io.IntWritable di org.apache.hadoop.mapred.IFile$Writer.append(IFile.java:143) di org.apache.hadoop.mapred.Task$ CombineOutputCollector.collect(Task.java:626) di WordCountReducer.reduce(WordCountReducer.java:29) di WordCountReducer.reduce(WordCountReducer.java:1) di org.apache.hadoop.mapred.MapTask$MapOutputBuffer.combineAndSpill(MapTask.java :904) di org.apache.hadoop.mapred.MapTask$MapOutputBuffer.sortAndSpill(MapTask.java:785) di org.apache.hadoop.mapred.MapTask$MapOutputBuffer.access$1600(MapTask.java:286) di org.apache .hadoop.mapred.MapTask$MapOutputBuffer$SpillThread.run(MapTask.java:712)
Kesalahan berulang beberapa kali setelah ini. Bisakah seseorang menjelaskan mengapa kesalahan ini terjadi? Saya mencari kesalahan serupa seperti ini tetapi yang saya temukan hanyalah tipe nilai kunci yang tidak cocok untuk pembuat peta dan peredam, tetapi seperti yang saya lihat, saya memiliki tipe nilai kunci yang cocok untuk pembuat peta dan peredam. Terima kasih sebelumnya.