是否可以通过hbase java API按行ID列表获取hbase数据记录?
例如,我有一个已知的hbase行id列表:
mykey1:myhash1,mykey1:myhash2,mykey1:myhash3,mykey2:myhash5,...
我希望单独调用hbase所有相关的列单元格信息.我对hbase很新,我不知道这是否支持API.
API伪代码:
GetById(String tableName, List<byte[]> rowIds);
Run Code Online (Sandbox Code Playgroud)
那样的东西?
我可以从单行检索信息Get(byte[] rowName),但是当我有rowIds列表时,我需要多次执行get动作,这会导致建立连接并在每次完成时关闭它.
谢谢
Lor*_*dig 15
将Get操作列表传递给批量调用:
...
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();
}
}
...
Run Code Online (Sandbox Code Playgroud)