我在一个col家族(cf)中有3个col{col1,col2,col3}。我想写一个扫描,这样我就可以选择所有有 col1='val1' and col2='val2' and (col3 is missing or col3 is null) .在java中执行此操作-抱歉,我对hbase完全陌生;-)
col1='val1' and col2='val2' and (col3 is missing or col3 is null)
ubof19bj1#
我认为以下代码可以帮助您:
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();
tzxcd3kk2#
我在网上很难找到答案。我终于弄明白了,其实很简单——就是没有答案:
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并与空字符串进行比较。
setFilterIfMissing
2条答案
按热度按时间ubof19bj1#
我认为以下代码可以帮助您:
tzxcd3kk2#
我在网上很难找到答案。我终于弄明白了,其实很简单——就是没有答案:
解决方案的关键部分是设置
setFilterIfMissing
为false并与空字符串进行比较。