簡體   English   中英

從HBase檢索所有內容,但特定列系列的值除外

[英]Retrieve all from HBase except the value of a particular column family

我正在編寫一個Java應用程序,該程序從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。 但是我使用了批處理獲取列表來加快速度。

編碼:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM