其实就是获取上图的start key和end key
- 代码:
object HbaseRegions {
def main(args: Array[String]): Unit = {
val hconf: Configuration = HBaseConfiguration.create()
hconf.set("hbase.zookeeper.property.clientPort", "2181")
hconf.set("hbase.zookeeper.quorum", "node118,node119,node120")
hconf.set("hbase.master", "node118:16000")
val hbaseConn: Connection = ConnectionFactory.createConnection(hconf)
val tableName: TableName = TableName.valueOf("OFFICIAL", "SAMPLE_INFO")
val table: Table = hbaseConn.getTable(tableName)
val startKeys: Array[Array[Byte]] = table.getRegionLocator.getStartKeys
val endKeys: Array[Array[Byte]] = table.getRegionLocator.getEndKeys
startKeys.zip(endKeys).foreach(kv=>{
println((Bytes.toString(kv._1), Bytes.toString(kv._2)))
})
table.close()
hbaseConn.close()
}
}