Changes between Version 6 and Version 7 of inputouput


Ignore:
Timestamp:
11/23/2012 12:29:20 PM (13 years ago)
Author:
liaojiaohe
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • inputouput

    v6 v7  
    7474                job); 
    7575}}} 
     76 
     77 
     78输出到关系数据库[[BR]] 
     79 
     80DBOuputFormat[[BR]] 
     81在实际项目中没有使用过,如果要写数据库我们的做法是生成入库的sql,使用另外的程序单线程执行,这样会比较好控制。 
     82 
     83HBASE作为输出[[BR]] 
     84 
     85对一个表输出比较简单 
     86{{{ 
     87        TableMapReduceUtil.initTableReducerJob( 
     88                Constant.TABLE_LAUNCH_REPORT, // output table 
     89                null, // reducer class 
     90                job); 
     91 
     92        job.setOutputKeyClass(ImmutableBytesWritable.class); 
     93        job.setOutputValueClass(Put.class); 
     94 
     95在reduce里面输出就可以了 
     96            Put put = new Put(row); 
     97            put.add(Constant.CF_BASE, qualifier, Bytes.toBytes(sum)); 
     98            context.write(null, put); 
     99}}} 
     100 
     101如果要对其他表的操作,或者执行递增操作可以在reduce的时候新建htable对象 
     102 
     103{{{ 
     104        public void setup(Context context) throws IOException { 
     105            String table = context.getConfiguration().get(TableOutputFormat.OUTPUT_TABLE); 
     106            hTable = new HTable(context.getConfiguration(), table); 
     107        } 
     108 
     109在reduce的时候使用hTable操作hbase 
     110                row = HBaseUtil.getLaunchRowByte(items[2], items[1], null); 
     111                qualifier = Bytes.toBytes(StringUtil.join(UNDERLINE_PARTITION, 
     112                        "c" + items[0], items[3], items[4])); 
     113                hTable.incrementColumnValue(row, Constant.CF_AREA, qualifier, result.get()); 
     114 
     115}}}