hbase api - 通过行ID列表获取数据行信息

2024-04-24

是否可以通过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);

类似的事情?

我可以从单行检索信息Get(byte[] rowName),但是当我有 rowId 列表时,我需要多次执行 get 操作,这会导致建立连接并在每次完成时关闭它。

Thanks


传递一个列表Get操作到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();
            }
        }
...
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

hbase api - 通过行ID列表获取数据行信息 的相关文章

随机推荐