【发布时间】:2016-08-01 13:27:03
【问题描述】:
我一直在使用以下函数将我的数据保存到 Hbase,有人可以帮助我如何使用更新的 api 或一些示例吗?下面是我的代码:
def getConnection():(Connection, Configuration) ={
val config = HBaseConfiguration.create()
config.set("hbase.zookeeper.quorum", "node-01.algo,node-02.algo")
config.set("hbase.master", "node-01.algo:60000")
config.set("zk.connectiontimeout.ms", "10000")
config.set("hbase.zookeeper.property.clientport", "2181")
config.set("zookeeper.znode.parent", "/hbase-unsecure")
val connection = ConnectionFactory.createConnection(config)
(connection, config)
}
def addRecord(tableName: String, rowKey: String, family: String, qualifier: String, value: String) ={
val conTuple = getConnection()
val connection = conTuple._1
val table = new HTable(conTuple._2, tableName)
val theput= new Put(Bytes.toBytes(rowKey))
theput.add(Bytes.toBytes(family), Bytes.toBytes(qualifier), Bytes.toBytes(value))
table.put(theput)
table.close()
connection.close()
}
Htable 已被弃用,并要求我改用 Table。
【问题讨论】: