ฉันยังใหม่กับ Hadoop และพบปัญหานี้ ฉันกำลังพยายามเปลี่ยนค่า Text, Integer เริ่มต้นสำหรับตัวลดเป็น Text, Text ฉันต้องการแมป Text, IntWritable จากนั้นในตัวลดฉันต้องการมี 2 ตัวนับ ขึ้นอยู่กับว่าค่าคืออะไร จากนั้นเขียนตัวนับ 2 ตัวนั้นใน Text สำหรับตัวสะสม
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();
}
}
}
ฉันได้รับข้อผิดพลาดนี้:
14/14/10 18:11:01 ข้อมูล mapred.JobClient: Task Id : try_201412100143_0008_m_000000_0, สถานะ : FAILED java.io.IOException: การรั่วไหลล้มเหลวที่ org.apache.hadoop.mapred.MapTask$MapOutputBuffer.collect(MapTask.java: 425) ที่ WordCountMapper.map(WordCountMapper.java:31) ที่ WordCountMapper.map(WordCountMapper.java:1) ที่ org.apache.hadoop.mapred.MapRunner.run(MapRunner.java:47) ที่ org.apache.hadoop mapred.MapTask.run(MapTask.java:227) ที่ org.apache.hadoop.mapred.TaskTracker$Child.main(TaskTracker.java:2209) เกิดจาก: java.io.IOException: คลาสค่าผิด: class org.apache .hadoop.io.Text ไม่ใช่คลาส org.apache.hadoop.io.IntWritable ที่ org.apache.hadoop.mapred.IFile$Writer.append(IFile.java:143) ที่ org.apache.hadoop.mapred.Task$ CombineOutputCollector.collect(Task.java:626) ที่ WordCountReducer.reduce(WordCountReducer.java:29) ที่ WordCountReducer.reduce(WordCountReducer.java:1) ที่ org.apache.hadoop.mapred.MapTask$MapOutputBuffer.combineAndSpill(MapTask.java) :904) ที่ org.apache.hadoop.mapred.MapTask$MapOutputBuffer.sortAndSpill(MapTask.java:785) ที่ org.apache.hadoop.mapred.MapTask$MapOutputBuffer.access$1600(MapTask.java:286) ที่ org.apache .hadoop.mapred.MapTask$MapOutputBuffer$SpillThread.run(MapTask.java:712)
ข้อผิดพลาดจะเกิดขึ้นซ้ำหลายครั้งหลังจากนี้ ใครช่วยอธิบายได้ไหมว่าทำไมข้อผิดพลาดนี้จึงเกิดขึ้น ฉันค้นหาข้อผิดพลาดที่คล้ายกันกับข้อผิดพลาดนี้ แต่ทั้งหมดที่ฉันพบคือประเภทคีย์-ค่าที่ไม่ตรงกันสำหรับผู้ทำแผนที่และตัวลด แต่อย่างที่ฉันเห็นฉันมีประเภทคีย์-ค่าที่ตรงกันสำหรับผู้ทำแผนที่และตัวลด ขอบคุณล่วงหน้า.