ハイブバージョン0.7.0を使用してログファイルを処理し、カスタムのinputformatとoutputformatを設定します。inputformatで「\n」を「@#@」に置き換え、outputformatで「\n」に戻したい。テスト後、inputformatは正常に機能しますが、outputformatが機能しません。理由を知りたい。これがコードです。ありがとう!
パブリッククラスErrlogOutputFormat、VはWritableを拡張します>
HiveIgnoreKeyTextOutputFormat{を拡張します
public staticclassCustomRecordWriterはRecordWriter{を実装します
RecordWriterライター;
BytesWritable bytesWritable;
public CustomRecordWriter(RecordWriter writer){
this.writer=ライター;
bytesWritable = new BytesWritable();
}
@オーバーライド
public void write(Writable w)はIOException{をスローします
// String str =((Text)w).toString()。replaceAll( "@#@"、 "\ n");
String [] str =((Text)w).toString()。split( "@#@");
StringBuffer sb = new StringBuffer();
for(String s:str){
sb.append(s).append( "\ n");
}
テキストtxtReplace=new Text(sb.toString());
System.out.println( "------------------------");
System.out.println(txtReplace.toString());
System.out.println( "------------------------");
//入力データを取得します
//エンコード
byte [] output = txtReplace.getBytes();
bytesWritable.set(output、0、output.length);
writer.write(bytesWritable);
}
@オーバーライド
public void close(boolean abort)はIOExceptionをスローします{
writer.close(abort);
}
}
@オーバーライド
public RecordWriter getHiveRecordWriter(JobConf jc、Path finalOutPath、
クラスvalueClass、ブールisCompressed、
プロパティtableProperties、進行状況)
IOExceptionをスローします{
CustomRecordWriter writer = new CustomRecordWriter(super
.getHiveRecordWriter(jc、finalOutPath、BytesWritable.class、
isCompressed、tableProperties、progress));
リターンライター;
}
}