MultipleOutputFormat多文件输出

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import  java.io.IOException;
import  org.apache.hadoop.conf.Configuration;
import  org.apache.hadoop.fs.FileSystem;
import  org.apache.hadoop.io.IntWritable;
import  org.apache.hadoop.mapred.JobConf;
import  org.apache.hadoop.mapred.RecordWriter;
import  org.apache.hadoop.mapred.lib.MultipleOutputFormat;
import  org.apache.hadoop.util.Progressable;
import  org.w3c.dom.Text;
public  class  MultipleOutputFormatTest  extends  MultipleOutputFormat<Text, IntWritable>{
     protected  String generateFileNameForKeyValue(Text key, IntWritable value, Configuration conf) {
         char  c = key.toString().toLowerCase().charAt( 0 );
         if (c >=  'a'  && c <=  'z' ){
             return  c +  ".txt" ;
         }
         return  "other.txt" ;
     }
     @Override
     protected  RecordWriter<Text, IntWritable> getBaseRecordWriter(
             FileSystem fs, JobConf job, String name, Progressable arg3)
             throws  IOException {
         // TODO Auto-generated method stub
         return  null ;
     }
}


在教程当中只需要重写generateFileNameForKeyValue 就能达到分文件的效果 但是在实践当中

还需要重写另一个方法 getBaseRecordWriter 还没有清楚其功能 先写着先

conf.setOutputFormat() //通过这个设定我们输出格式

本文转自    拖鞋崽      51CTO博客,原文链接:http://blog.51cto.com/1992mrwang/1206459
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值