0

入力を HTable から取得する MapReduce ジョブがあります。Java MapReduce コードから、Job inputformat を HBase TableInputFormatにどのように設定しますか?

HTable データベースに接続するための JDBC 接続のようなものはありますか?

4

2 に答える 2

1

HBase には、TableMapResudeUtilmap/reduce ジョブを簡単に設定できるクラスが付属しています。マニュアルの最初のサンプルは次のとおりです。

Configuration config = HBaseConfiguration.create();
Job job = new Job(config, "ExampleRead");
job.setJarByClass(MyReadJob.class);     // class that contains mapper

Scan scan = new Scan();
scan.setCaching(500);        // 1 is the default in Scan, which will be bad for MapReduce jobs
scan.setCacheBlocks(false);  // don't set to true for MR jobs
// set other scan attrs
...

TableMapReduceUtil.initTableMapperJob(
  tableName,        // input HBase table name
  scan,             // Scan instance to control CF and attribute selection
  MyMapper.class,   // mapper
  null,             // mapper output key
  null,             // mapper output value
  job);
job.setOutputFormatClass(NullOutputFormat.class);   // because we aren't emitting anything from mapper

boolean b = job.waitForCompletion(true);
if (!b) {
  throw new IOException("error with job!");
}
于 2013-06-21T02:17:19.743 に答える