Write to multiple tables in HBASE

后端 未结 2 1679
攒了一身酷
攒了一身酷 2020-12-21 08:06

I have a situation here where I need to write to two of the hbase tables say table1,table 2. Whenever a write happens on table 1, I need to do some operation on table 2 say

相关标签:
2条回答
  • 2020-12-21 08:49

    To write into more than one table in map-reduce job, you have to specify that in job configuration. You are right this can be done using MultiTableOutputFormat. Normally for a single table you use like:

    TableMapReduceUtil.initTableReducerJob("tableName", MyReducer.class, job);
    

    Instead of this write:

    job.setOutputFormatClass(MultiTableOutputFormat.class);
    job.setMapperClass(MyMapper.class);
    job.setReducerClass(MyReducer.class);
    job.setNumReduceTasks(2);
    TableMapReduceUtil.addDependencyJars(job);
    TableMapReduceUtil.addDependencyJars(job.getConfiguration());
    

    Now at the time of writing data in table write as:

    context.write(new ImmutableBytesWritable(Bytes.toBytes("tableName1")),put1);
    context.write(new ImmutableBytesWritable(Bytes.toBytes("tableName2")),put2);
    
    0 讨论(0)
  • 2020-12-21 08:49

    For this you can use HBase Observer, You have to create an observer and have to deploy on your server(applicable only for HBase Version >0.92), It will automatic trigger to another table.
    And I think HBase Observer has similar concepts of like Aspects.
    For more details -
    https://blogs.apache.org/hbase/entry/coprocessor_introduction

    0 讨论(0)
提交回复
热议问题