2013-05-01 54 views
1

我正在編寫一個Java應用程序,它從HBase數據庫中檢索並呈現數據。從HBase中檢索除了特定列族的值以外的所有內容

在編寫檢索行的Get方法時,我想獲取該行的所有數據,但排除特定列族(「大」列族)的值。注意:我需要檢索該系列中的列名稱(限定符?),因爲它們包含有價值的信息。

是否有可能爲此編寫過濾器?

我有兩個解決方案。第一個不起作用,第二個很慢。

第一溶液(使用複合過濾器):

HTable table = getTable(); 
Get get = new Get(row); 
FilterList filter = new FilterList(FilterList.Operator.MUST_PASS_ONE); 

FilterList subFilterList = new FilterList(FilterList.Operator.MUST_PASS_ALL); 
subFilterList.addFilter(new KeyOnlyFilter()); 
subFilterList.addFilter(new FamilyFilter(CompareOp.EQUAL, new BinaryComparator(Bytes.toBytes("big")))); 

filter.addFilter(subFilterList); 
filter.addFilter(new FamilyFilter(CompareOp.NOT_EQUAL, new BinaryComparator(Bytes.toBytes("big")))); 

get.setFilter(filter); 
retrieveAndUseResult(table, get); 

此方法適用於沒有概念和實踐上 - 但也許我是使用複合FilterList在正確的軌道上?

解決方法二(使用兩個被):

HTable table = getTable(); 
Get get = new Get(row); 
// exclude the entire "big" column family 
get.setFilter(new FamilyFilter(CompareOp.NOT_EQUAL, new BinaryComparator(Bytes.toBytes("big")))); 
retrieveAndUseResult(table, get); 

Get get2 = new Get(row); 
// include the "big" column family, but only retrieve the key 
FilterList filterList = new FilterList(FilterList.Operator.MUST_PASS_ALL); 
filterList.addFilter(new KeyOnlyFilter()); 
filterList.addFilter(new FamilyFilter(CompareOp.EQUAL, new BinaryComparator(Bytes.toBytes("big")))); 
get2.setFilter(filterList); 
retrieveAndUseResult(table, get2); 

這工作,但我贊成不得不這樣做只有一個GET。

回答

0

我結束了使用第二個解決方案的變種 - 使用兩個獲取。但我使用了批量獲取列表來加速它。

代碼:

HTable table = getTable(); 

Get get = new Get(row); 
// exclude the entire "big" column family 
get.setFilter(new FamilyFilter(CompareOp.NOT_EQUAL, new BinaryComparator(Bytes.toBytes("big")))); 

Get get2 = new Get(row); 
// include the "big" column family, but only retrieve the key 
FilterList filterList = new FilterList(FilterList.Operator.MUST_PASS_ALL); 
filterList.addFilter(new KeyOnlyFilter()); 
filterList.addFilter(new FamilyFilter(CompareOp.EQUAL, new BinaryComparator(Bytes.toBytes("big")))); 
get2.setFilter(filterList); 

List<Get> getList = new ArrayList<Get>(); 
getList.add(get); 
getList.add(get2); 
retrieveAndUseResults(table, getList); 
相關問題