2017-01-10 71 views
0

我很新的HBase的API,並執行以下操作時看到了一些奇怪的結果。HBase的掃描API與多個過濾條件

我們正在嘗試基於多個過濾器進行掃描。我想通過所有的過濾條件。我正在使用下面的代碼。

FilterList filterList = new FilterList(FilterList.Operator.MUST_PASS_ALL); 
Filter pageFilter = new PageFilter(5000); 
filterList.addFilter(pageFilter); 
SingleColumnValueFilter filterOne = new SingleColumnValueFilter(Bytes.toBytes(COLUMN_FAMILY), 
       Bytes.toBytes(COLUMN_NAME1), CompareOp.EQUAL, Bytes.toBytes(value1)); 
filterList.addFilter(filterOne); 
SingleColumnValueFilter filterTwo = new SingleColumnValueFilter(Bytes.toBytes(COLUMN_FAMILY), 
       Bytes.toBytes(COLUMN_NAME2), CompareOp.EQUAL, Bytes.toBytes(value2)); 
filterList.addFilter(filterOne); 
filterList.addFilter(filterTwo); 

//Scan 
Scan scan = new Scan(); 
scan.setFilter(filterList); 
Result result; 
try { 
      scanner = hTable.getScanner(scan); 
     } catch (IOException e) { 
      // TODO Auto-generated catch block 
      e.printStackTrace(); 
     } 
while ((result = scanner.next()) != null) { 
    //print the result. 
} 
//If I am adding multiple SingleColumnValueFilter and I am not doing a addCoulmn() to the scan I am not getting any result even though there are records. 

//If I am adding a column to scan then I am seeing results. Initially the result set is matching my filter condition but if I am running for bigger hbase data set then I am seeing bad results. 

//If I am adding multiple addCoulmn() to my scan then I am not seeing any result 

我試圖尋找合適的例子,但他們都沒有工作。任何幫助在這個方向非常感謝。提前致謝。

+0

爲什麼你添加filterTwo兩次? – Comencau

+0

我們無法在其中創建掃描儀變量 – Comencau

回答

0

您指定了一個FilterList,其中所有過濾器都必須通過(如「AND」行爲)。在過濾器列表中,您有2 SingleColumnValueFilter這是矛盾的:它們表示列COLUMN_FAMILY:COLUMN_NAME必須同時等於值1和值2。我想這就是爲什麼你沒有得到第一和第三條評論的結果。

關於你的第二個評論,我認爲你必須要記住,只有當該列在掃描中存在SingleColumnValueFilter應用。這可能是你看到的內容的解釋。檢查setFilterIfMissing(boolean)方法:https://hbase.apache.org/apidocs/org/apache/hadoop/hbase/filter/SingleColumnValueFilter.html#setFilterIfMissing-boolean-

希望它可以幫助

+0

我編輯了我的錯字。它們是同一列家族下的兩個不同列。關於你的第二點,即使我在掃描中添加兩列,我也沒有得到期望的結果。 – hopeIsTheonlyWeapon

+0

我修改了代碼,但並未產生所需的結果。 – hopeIsTheonlyWeapon