hbase api - 按行ID列表获取数据行信息 [英] hbase api - get data rows information by list of row ids

查看:304
本文介绍了hbase api - 按行ID列表获取数据行信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能通过hbase java API获得行列表列表的hbase数据记录?



例如,我有一个hbase row id的已知列表: / p>

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



我想用单个调用来获取所有相关的列单元信息。我对hbase很陌生,我不知道这是甚至是API支持的。



API伪代码:

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

类似的东西?



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



谢谢 通过a 获取操作到批量调用列表:

  ... 
import org.apache.hadoop.conf.Configuration;
导入org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.client.Get;
import org.apache.hadoop.hbase.client.HTable;
导入org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.util.Bytes;
...
HTable htable = null;
尝试{
htable = new HTable(conf,mytable);
列表<获取> 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)));

结果[] results = htable.get(queryRowList);
for(Result r:results){
// do something
}
}
finally {
if(htable!= null){
htable.close();
}
}
...


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

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

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.

API pseudo code:

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.

Thanks

解决方案

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆