开发者

Get value by family in HBase

开发者 https://www.devze.com 2023-04-12 05:04 出处:网络
Row: Key, Family:Qualifier, Value Key, Family1:Qualifier, Value Key, Family2:Qualif开发者_JS百科ier, Value

Row:

Key, Family:Qualifier, Value
Key, Family1:Qualifier, Value
Key, Family2:Qualif开发者_JS百科ier, Value
Key, FamilyN:Qualifier, Value

In the Java HBase API we can scan a table row by row and then get a FamilyMap for each row.

Is there any option to get all the row for a specific family without knowing the qualifier?

If yes, is there a difference in term of performance between: get value by key or get value by family ?


You can get the scanner on a specific family like this. Getting a scanner on a specific column family returns only that family data as part of the result. What this means is that the qualifier and values which are part of that family are availabe as part of the result.

HTable table = new HTable(HBaseConfiguration.create(), "tablename");
Scan scan = new scan();
scan.setCaching(NUMBER_OF_ROWS_TO_CACHE);
//If you want to get data for all families then do not add any family.
scan.addFamily(Bytes.toBytes("columnFamilyName"));
ResultScanner scanner = table.getScanner(scan);

If you do not add any family to the scan object created above then you get data of all the column families. Now you can scan the table by iterating like this

for (Result result = scanner.next(); (result != null); result = scanner.next()) {
    //If you want a family specific data
    NavigableMap familyMap = result.getFamilyMap(Bytes.toBytes("familyname"));
    //if you want to get the entire row 
    Get get = new Get(result.getRow());
    Result entireRow = table.get(get); 

}

As for the performance when you get all the row data it will be comparatively slow because all data for all the column families for a specific row is fetched. So, unless you want all of your families do not get the entire row.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号