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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13310434/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 12:15:04  来源:igfitidea点击:

hbase api - get data rows information by list of row ids

javaapihbase

提问by jMn

Is it possible to get hbase data records by list of row ids via hbase java API?

是否可以通过 hbase java API 通过行 ID 列表获取 hbase 数据记录?

For example, I have a known list of hbase row ids:

例如,我有一个已知的 hbase 行 ID 列表:

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

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

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.

我想通过一次调用来获取 hbase 所有相关的列单元格信息。我对 hbase 很陌生,我不知道 API 是否支持这一点。

API pseudo code:

API伪代码:

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

Something like that?

类似的东西?

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(byte[] rowName),但是当我有 rowIds 列表时,我需要多次执行 get 操作,这会导致每次完成时建立连接并关闭它。

Thanks

谢谢

回答by Lorand Bendig

Pass a list of Getoperations to a batchcall:

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();
            }
        }
...

回答by Arnon Rotem-Gal-Oz

You can use MultiActionas a container for multiple get (or put, delete and combinations of them) that you can execute in batch.

您可以将MultiAction用作可以批量执行的多个 get(或 put、delete 和它们的组合)的容器。

That said, note that you can perform multiple get operations without closing/reopening the connection every time.

也就是说,请注意,您可以执行多个 get 操作而无需每次都关闭/重新打开连接。