简体   繁体   中英

HBase Get values where rowkey in

How do I get all the values in HBase given Rowkey values?

val tableName = "myTable"
val hConf = HBaseConfiguration.create()
val hTable = new HTable(hConf, tableName)
val theget= new Get(Bytes.toBytes("1001-A")) // rowkey values (1001-A, 1002-A, 2010-A, ...)
val result = hTable.get(theget)
val values = result.listCells()

The code above only works for one rowkey.

You can use Batch operations. Please refer the link below for Javadoc : Batch Operations on HTable

Another approach is to Scan with a start row key & end row key (First & Last row keys from an sorted ascending set of keys). This makes more sense if there are too many values.

There is htable.get method that take list of Gets:

List<Get> gets = ....
List<Result> results = htable.get(gets)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM