Hadoop调试信息的输出办法
Hadoop
调试是比较麻烦的事情,考虑到只能通过reduce输出数据,我们可以把调试信息输出到reduce中,然后固定到某个文件中。<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />
我们可以把所有的调试数据都是用key=“Debug”,调试信息作为value=“debugInfo”。
(1)在map中直接使用
output.collect(new Text("debug"), new Text("调试信息"));
(2)在reduce中判断
[*]if(key.equals("debug"))
[*]{
[*]while(values.hasNext())
[*]{
[*]Stringline=values.next().toString();
[*]output.collect(newText("debug"),newText(line));
[*]}
[*]}
(3)
增加类ReportOutFormat
[*]publicstaticclassReportOutFormat<KextendsWritableComparable<?>,VextendsWritable>
[*]extendsMultipleOutputFormat<K,V>{
[*]
[*]privateTextOutputFormat<K,V>theTextOutputFormat=null;
[*]
[*]@Override
[*]protectedRecordWriter<K,V>getBaseRecordWriter(FileSystemfs,
[*]JobConfjob,Stringname,Progressablearg3)throwsIOException{
[*]if(theTextOutputFormat==null){
[*]theTextOutputFormat=newTextOutputFormat<K,V>();
[*]}
[*]returntheTextOutputFormat.getRecordWriter(fs,job,name,arg3);
[*]}
[*]@Override
[*]protectedStringgenerateFileNameForKeyValue(Kkey,Vvalue,Stringname){
[*]if(key.equals("debug"))///注意这个判断
[*]return"debug"+name;
[*]returnname;
[*]}
[*]}
(
4)在configJob里面添加代码
[*]protectedvoidconfigJob(JobConfconf)
[*]{
[*]conf.setMapOutputKeyClass(Text.class);
[*]conf.setMapOutputValueClass(Text.class);
[*]conf.setOutputKeyClass(Text.class);
[*]conf.setOutputValueClass(Text.class);
[*]conf.setOutputFormat(ReportOutFormat.class);//增加该行
[*]}
这样在输出文件中我们就可以得到调试信息了。这个办法有点曲线救国的意思,不知道有没有其他方便的办法。
页:
[1]