| | 76 | |
| | 77 | |
| | 78 | 输出到关系数据库[[BR]] |
| | 79 | |
| | 80 | DBOuputFormat[[BR]] |
| | 81 | 在实际项目中没有使用过,如果要写数据库我们的做法是生成入库的sql,使用另外的程序单线程执行,这样会比较好控制。 |
| | 82 | |
| | 83 | HBASE作为输出[[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 | }}} |