Hadoop
调试是比较麻烦的事情,考虑到只能通过reduce输出数据,我们可以把调试信息输出到reduce中,然后固定到某个文件中。
我们可以把所有的调试数据都是用key=“Debug”,调试信息作为value=“debugInfo”。
(1)在map中直接使用
output.collect(new Text("debug"), new Text("调试信息"));
(2)在reduce中判断
- if(key. equals ("debug"))
- {
- while (values.hasNext())
- {
- String line = values.next().toString();
- output.collect(new Text("debug"), new Text(line));
- }
- }
(3)
增加类ReportOutFormat- public static class ReportOutFormat<K extends WritableComparable<?>, V extends Writable>
- extends MultipleOutputFormat<K, V> {
- private TextOutputFormat<K, V> theTextOutputFormat = null;
- @Override
- protected RecordWriter<K, V> getBaseRecordWriter(FileSystem fs,
- JobConf job, String name, Progressable arg3) throws IOException {
- if (theTextOutputFormat == null) {
- theTextOutputFormat = new TextOutputFormat<K, V>();
- }
- return theTextOutputFormat.getRecordWriter(fs, job, name, arg3);
- }
- @Override
- protected String generateFileNameForKeyValue(K key, V value, String name) {
- if(key.equals("debug")) ///注意这个判断
- return "debug"+name;
- return name ;
- }
- }
(
4)在configJob里面添加代码- protected void configJob(JobConf conf)
- {
- conf.setMapOutputKeyClass(Text.class);
- conf.setMapOutputValueClass(Text.class);
- conf.setOutputKeyClass(Text.class);
- conf.setOutputValueClass(Text.class);
- conf.setOutputFormat(ReportOutFormat.class); //增加该行
- }
这样在输出文件中我们就可以得到调试信息了。这个办法有点曲线救国的意思,不知道有没有其他方便的办法。