我在Col族(CF)中有3個cols {col1,col2,col3}。我想寫一個掃描,以便我選擇所有具有col1='val1' and col2='val2' and (col3 is missing or col3 is null)
的行。Hbase掃描篩選器記錄缺失列或列值爲空
在Java中這樣做 - 對不起,我完全陌生的HBase的;-)
我在Col族(CF)中有3個cols {col1,col2,col3}。我想寫一個掃描,以便我選擇所有具有col1='val1' and col2='val2' and (col3 is missing or col3 is null)
的行。Hbase掃描篩選器記錄缺失列或列值爲空
在Java中這樣做 - 對不起,我完全陌生的HBase的;-)
我有很多的麻煩網上找到一個答案,這個自己。我終於想通了,它很簡單 - 只是沒有答案:
Scan scanner = new Scan();
SingleColumnValueFilter filter = new SingleColumnValueFilter(
Bytes.toBytes("some family"),
Bytes.toBytes("some column"),
CompareFilter.CompareOp.EQUAL,
Bytes.toBytes("")
);
filter.setFilterIfMissing(false);
scanner.setFilter(filter);
return scanner;
解決方案的關鍵部位設置setFilterIfMissing
爲false,並與空字符串比較。
我認爲下面的代碼可以幫助你:
FilterList filterList = new FilterList();
SingleColumnValueFilter filter1 = new SingleColumnValueFilter(Bytes.toBytes("someFamily"), Bytes.toBytes("col1"), CompareFilter.CompareOp.EQUAL, Bytes.toBytes("val1"));
filter1.setFilterIfMissing(true);
filterList.addFilter(filter1);
SingleColumnValueFilter filter2 = new SingleColumnValueFilter(Bytes.toBytes("someFamily"), Bytes.toBytes("col2"), CompareFilter.CompareOp.EQUAL, Bytes.toBytes("val2"));
filter2.setFilterIfMissing(true);
filterList.addFilter(filter2);
SingleColumnValueFilter filter3 = new SingleColumnValueFilter(Bytes.toBytes("someFamily"), Bytes.toBytes("col3"), CompareFilter.CompareOp.EQUAL, new NullComparator());
filter3.setFilterIfMissing(false);
filterList.addFilter(filter3);
Scan scan = new Scan();
scan.setFilter(filterList);
ResultScanner resultScanner = table.getScanner(scan);
for (Result res : resultScanner) {
System.out.println(res);
}
resultScanner.close();
我沒得setFilterIfMissing(假);我認爲這是默認的錯誤 – hba