用于缺少列的记录的Hbase扫描过滤器或列值为空

时间:2014-06-23 16:11:19

标签: java hadoop hbase database-scan

我在col系列(CF)中有3个cols {col1,col2,col3}。我想编写扫描,以便选择所有包含col1='val1' and col2='val2' and (col3 is missing or col3 is null)的行。

在Java中执行此操作 - 抱歉,我对hbase完全不熟悉; - )

2 个答案:

答案 0 :(得分:2)

我在网上找到答案时遇到了很多麻烦。我终于明白了,而且非常简单 - 只是没有答案:

d = max(c(:))+1;
c(c==-1) = d; 
e = reshape(c,9,2);
f = min(d);

解决方案的关键部分是将 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; 设置为false并与空字符串进行比较。

答案 1 :(得分:0)

我认为以下代码可以为您提供帮助:

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