Hbase api - get information about rows of data from a list of row identifiers

Is it possible to get hbase data records from a list of row identifiers via the hbase java API?

For example, I have a known list of hbase string identifiers:

mykey1: myhash1, mykey1: myhash2, mykey1: myhash3, mykey2: myhash5, ...

and I want to get one call to hbase for all the corresponding column cell data. I am new to hbase and I don't know if this is even supported by the API.

API Pseudo Code:

GetById(String tableName, List<byte[]> rowIds); 

Something like that?

I can get information from a single line using Get(byte[] rowName) , but when I have a list of rowIds, I need to execute the get action several times, which causes the connection to be established and closed at each end.

thanks

+4
source share
2 answers

Pass the list of Get operations for the batch call:

 ... import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hbase.HBaseConfiguration; import org.apache.hadoop.hbase.client.Get; import org.apache.hadoop.hbase.client.HTable; import org.apache.hadoop.hbase.client.Result; import org.apache.hadoop.hbase.util.Bytes; ... HTable htable = null; try { htable = new HTable(conf, "mytable"); List<Get> queryRowList = new ArrayList<Get>(); queryRowList.add(new Get(Bytes.toBytes("mykey1:myhash1"))); queryRowList.add(new Get(Bytes.toBytes("mykey1:myhash2"))); queryRowList.add(new Get(Bytes.toBytes("mykey1:myhash3"))); queryRowList.add(new Get(Bytes.toBytes("mykey2:myhash5"))); Result[] results = htable.get(queryRowList); for (Result r : results) { //do something } } finally { if (htable != null) { htable.close(); } } ... 
+13
source

You can use MultiAction as a container for several get (or put, delete and their combinations), which you can execute in batch mode.

However, note that you can perform multiple get operations without closing / reopening the connection each time.

0
source

Source: https://habr.com/ru/post/1445081/


All Articles