阅读(3134) (0)

访问MapReduce作业中的其他HBase表

2018-04-11 11:18:45 更新

访问MapReduce作业中的其他HBase表

尽管当前框架允许一个 HBase 表作为 MapReduce 作业的输入,其他的HBase表可以作为查找表来访问,等等,在 MapReduce 作业中,通过在 Mapper 的 setup 方法中创建一个 Table 实例。

public class MyMapper extends TableMapper<Text, LongWritable> {
  private Table myOtherTable;

  public void setup(Context context) {
    // In here create a Connection to the cluster and save it or use the Connection
    // from the existing table
    myOtherTable = connection.getTable("myOtherTable");
  }

  public void map(ImmutableBytesWritable row, Result value, Context context) throws IOException, InterruptedException {
    // process Result...
    // use 'myOtherTable' for lookups
  }