2011-10-10 33 views
2
找家庭的價值

行:在HBase的

Key, Family:Qualifier, Value 
Key, Family1:Qualifier, Value 
Key, Family2:Qualifier, Value 
Key, FamilyN:Qualifier, Value 

在Java API的HBase我們可以按行掃描錶行,然後得到的每一行FamilyMap

是否有任何選項可以在不知道qualifier的情況下獲取特定family的所有行?

如果是,是否在性能方面存在差異:按鍵獲取價值或按家庭價值計算?

回答

1

你可以在這樣的特定家庭獲得掃描儀。在特定列族上獲取掃描儀只會返回該家族數據作爲結果的一部分。這意味着作爲結果的一部分的屬於該家庭的限定詞和數值是有用的。

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); 

如果你沒有任何家庭加入到上面,那麼你得到的所有列族的數據創建的scan對象。現在,你可以通過這樣的

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); 

} 

迭代至於性能,當你得到所有這將是比較慢的,因爲所有的列族特定行中的所有數據被取出的行數據掃描表。所以,除非你想讓你所有的家庭都沒有整個行。

+1

奇怪...你做table.get(get);爲了得到結果,你已經在循環中得到了結果...(結果結果= scanner.next(),這是否意味着我們不能通過家族和無鑰匙獲得一行? – JohnJohnGa

+0

@ JohnJohnGa'table.get(get)'獲取包含所有列系列數據的整行,讓我編輯答案以使其更清晰 –

+0

是的,您是對的,您無法按家族獲得特定的行。爲了得到一個特定的行,你必須使用'rowkey'來獲取行,這是'table.get(get)'所做的。 –