我想使用 hive 版本 0.7.0 处理日志文件,并设置自定义输入格式和输出格式。在输入格式中,我将“\n”替换为“@#@”,在输出格式中我想改回“\n”。经过测试,我的 inputformat 表现良好,但我的 outputformat 不起作用。我想知道为什么。这是代码。谢谢!
公共类 ErrlogOutputFormat,V 扩展可写>
扩展 HiveIgnoreKeyTextOutputFormat {
公共静态类 CustomRecordWriter 实现 RecordWriter{
RecordWriter 作家;
BytesWritable bytesWritable;
公共CustomRecordWriter(RecordWriter作家){
this.writer = 作家;
bytesWritable = new BytesWritable();
}
@覆盖
公共无效写入(可写 w)抛出 IOException {
//String str = ((Text) w).toString().replaceAll("@#@","\n");
String[] str = ((Text) w).toString().split("@#@");
StringBuffer sb = new StringBuffer();
for(字符串 s:str){
sb.append(s).append("\n");
}
文本 txtReplace = new Text(sb.toString());
System.out.println("------------------------");
System.out.println(txtReplace.toString());
System.out.println("------------------------");
// 获取输入数据
// 编码
字节[] 输出 = txtReplace.getBytes();
bytesWritable.set(output, 0, output.length);
writer.write(bytesWritable);
}
@覆盖
公共无效关闭(布尔中止)抛出 IOException {
writer.close(中止);
}
}
@覆盖
公共 RecordWriter getHiveRecordWriter(JobConf jc, 路径 finalOutPath,
类 valueClass, boolean isCompressed,
属性表Properties,Progressable progress)
抛出 IOException {
CustomRecordWriter writer = new CustomRecordWriter(super
.getHiveRecordWriter(jc, finalOutPath, BytesWritable.class,
isCompressed,tableProperties,进度));
返回作家;
}
}