hbase api - 通过行 ID 列表获取数据行信息 [英] hbase api - get data rows information by list of row ids
问题描述
是否可以通过 hbase java API 通过行 ID 列表获取 hbase 数据记录?
Is it possible to get hbase data records by list of row ids via hbase java API?
例如,我有一个已知的 hbase 行 ID 列表:
For example, I have a known list of hbase row ids:
mykey1:myhash1,mykey1:myhash2,mykey1:myhash3,mykey2:myhash5,...
mykey1:myhash1, mykey1:myhash2, mykey1:myhash3, mykey2:myhash5, ...
并且我想通过一次调用来获取所有相关的列单元格信息.我对 hbase 还很陌生,我不知道 API 是否支持这一点.
and I want to get with single call to hbase all relevant column cell informations. I'm pretty new to hbase and i don't know is this even supported by the API.
API 伪代码:
GetById(String tableName, List<byte[]> rowIds);
类似的东西?
我可以使用Get(byte[] rowName)
从单行检索信息,但是当我有rowIds列表时,我需要多次执行get操作,这会导致建立连接和关闭每次完成时.
I can retrieve information from single row with Get(byte[] rowName)
, but when I have list of rowIds, I need to execute the get action several times, which cause establishing connection and closing it when completed each time.
谢谢
推荐答案
将 Get
操作列表传递给 batch 调用:
Pass a list of Get
operations to a 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();
}
}
...
这篇关于hbase api - 通过行 ID 列表获取数据行信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!