Hbase使用MultiTableOutputFormat实现多表输出MapReduce job
来源:互联网 发布:淘宝网支持的网上银行 编辑:程序博客网 时间:2024/06/09 23:50
参考:https://bigdatabuzz.wordpress.com/2012/04/24/how-to-write-to-multiple-hbase-tables-in-a-mapreduce-job/
我们经常遇到需要更新多个表从一个map中输出以减少程序的运行时间。一个简单的方法是使用一个multitableoutputformat。
要配置这个工作,我们需要设置outputformatclass到multitableoutputformat.class。
为了使输出格式类识别的表名,我们需要通过表名为context.write关键。
下面给出一个例子:
为了使输出格式类识别的表名,我们需要通过表名为context.write关键。
下面给出一个例子:
In Mapper :
public class Clean_TransMapper extends TableMapper<ImmutableBytesWritable, Put> {private ImmutableBytesWritable tbl1 = new ImmutableBytesWritable (Bytes.toBytes("outPutTable"));private ImmutableBytesWritable tbl2 = new ImmutableBytesWritable (Bytes.toBytes("outTempTable")); @Override protected void map(ImmutableBytesWritable key, Result value, Context context) throws IOException, InterruptedException { Put put = new Put(key.get());//具体的逻辑就不给你们看了,以下举例String value = Bytes.toString(row.get() );if ("ONE".equals(value)) {context.write(tbl1, record);} else {context.write(tbl2, record);}}}
In the Driver class,
public final class MultiTableWriteDriver extends Configured implements Tool {.................@Overridepublic int run (final String[] args) {Configuration conf = HBaseConfiguration.create();conf.set("mapreduce.job.jar","WeRroot\\WEB-INF\\lib\\hadoop-veiwhigh-0.0.1-SNAPSHOT.jar");Job job = Job.getInstance(conf, "*******");Scan scan = new Scan(); scan.setCaching(500); scan.setCacheBlocks(false); // don't set to true for MR jobs scan.setStartRow(Bytes.toBytes(setStartRow)); scan.setStopRow(Bytes.toBytes(setStopRow));TableMapReduceUtil.addDependencyJars(job);TableMapReduceUtil.addDependencyJars(job.getConfiguration()); job.setJarByClass(MrCleanTransJobTool.class); // TableMapReduceUtil.initTableMapperJob(inPutTable, // 输入表 scan, // Scan instance to control CF and attribute selection *****.class, // mapper class ImmutableBytesWritable.class, // mapper output key Put.class, // mapper output value job); job.setOutputFormatClass (MultiTableOutputFormat.class); job.setNumReduceTasks(0); //设置为0表示不需要reduce return job.waitForCompletion(true) ? 0 : -1;}}
0 0
- Hbase使用MultiTableOutputFormat实现多表输出MapReduce job
- Bulk Load使用--利用MapReduce job实现上传海量数据到HBase
- 使用java MapReduce job 批量导入大额数据到Hbase
- 用一个MapReduce job实现去重,多目录输出功能
- mapreduce读取hbase值,结果输出到多个hbase表中
- 使用JobControl管理mapreduce多job依赖
- 使用JobControl管理mapreduce多job依赖
- 如何执行hbase 的mapreduce job
- 如何执行hbase 的mapreduce job
- HBase MapReduce 使用
- 使用mapreduce操作Hbase
- Mapreduce多表关联与词频统计程序运行结果输出到Hbase的两个途径
- hbase多表输出
- hbase多表输出
- mapreduce输入源为多hbase数据表 输出目标为多hbase数据表
- 实现mapreduce多文件自定义输出
- 实现mapreduce多文件自定义输出
- 实现mapreduce多文件自定义输出
- 嵌套ListView,GridView高度问题
- CSS实现垂直居中
- HDU1008 Elevator
- hibernate配置文件hibernate.cfg.xml的详细解释
- 自己编译JDK
- Hbase使用MultiTableOutputFormat实现多表输出MapReduce job
- ERROR:invalid byte sequence for encoding"UTF8"
- swift自制工厂模式
- xib中设置ScrollView
- 2015 年最棒的 5 个 HTML5 框架
- C#操作图片存入XML和显示XML图片
- iOS框架和服务知识点
- 应用程序和驱动的简易交互方式的实现
- MFC--设置静态文本框的文字的字体、大小和颜色