【发布时间】:2016-01-06 11:58:49
【问题描述】:
我有保存到 HBase HTABLE 的代码。预期的行为是该表将为每个分区推送提交或“刷新”到 hbase 的放置。
注意:这是更新后的代码
rdd.foreachPartition(p => {
val table = connection.getTable(TableName.valueOf(HTABLE))
val mutator = connection.getBufferedMutator(TableName.valueOf(HTABLE))
p.foreach(row => {
val hRow = new Put(rowkey)
hRow.addColumn....
// use table.exists instead of table.checkAndPut (in favor of BufferedMutator's flushCommits)
val exists = table.exists(new Get(rowkey))
if (!exists) {
hRow.addColumn...
}
mutator.mutate(hRow)
})
table.close()
mutator.flush()
mutator.close()
})
在 HBase 1.1 中,不推荐使用 HTable,并且在 org.apache.hadoop.hbase.client.Table 中没有可用的 flushCommits()。
替换 BufferedMutator.mutate(put) 对普通 put 是可以的,但是 mutator 没有任何类似于 Table 的 checkAndPut。
【问题讨论】: