Get records based on Rowkey and ColumnFamily

2019-09-07 07:39发布

Is it possible to read data from HBase based on rowKey and columnFamily. Currently I access records by rowkey by this code:

HTable table = new HTable(conf, "tablename");
Get get = new Get(rowkey.getBytes());            
Result rs = table.get(get);
for (KeyValue kv : rs.raw()) {
    holdvalue = new String(kv.getValue());
}

I want to add columnfamily as a filter to access specific records that belongs to that specific rowKey and columnFamily. How could I achieve this?

Thanks in advance

标签: java hbase
1条回答
你好瞎i
2楼-- · 2019-09-07 08:02

You can add the column family as a filter by using the addFamily method of the Get object.

HTable table = new HTable(conf, "tablename");
Get get = new Get(rowkey.getBytes());     
get.addFamily(family.getBytes());    // <-----------------       
Result rs = table.get(get);
for (KeyValue kv : rs.raw()) {
    holdvalue = new String(kv.getValue());
}
查看更多
登录 后发表回答