1. 先把RDD转成RDD[Put]类型
2. HBase2.x版本api改变很大,这里使用 BufferedMutator 写入数据
dataRDD.repartition(100)
.foreachPartition(partition => {
val hBaseConfiguration = HBaseConfiguration.create()
hBaseConfiguration.set("hbase.zookeeper.quorum", zookeeper)
hBaseConfiguration.set("zookeeper.znode.parent", "/hbase")
hBaseConfiguration.set("hbase.zookeeper.property.clientPort", "2181")
val connection = ConnectionFactory.createConnection(hBaseConfiguration)
val mutatorParams = new BufferedMutatorParams(TableName.valueOf(tableName)).writeBufferSize(4 * 1024 * 1024)
val bufferedMutator = connection.getBufferedMutator(mutatorParams)
import scala.collection.JavaConversions._
bufferedMutator.mutate(partition.toSeq)
bufferedMutator.flush()
bufferedMutator.close()
})