0

我在 FilterLists 的层次结构中添加了多个行过滤器,它允许我仅从 HBase 表中过滤我需要的内容,如下所示:

FilterList list = new FilterList(FilterList.Operator.MUST_PASS_ONE);
FilterList uidList = new FilterList(FilterList.Operator.MUST_PASS_ALL);
if(term.length()>longSize){
    long highValue = Long.parseLong(term.substring(longSize));
    uidList.addFilter(new RowFilter(CompareFilter.CompareOp.GREATER_OR_EQUAL,
                            new BinaryComparator(Bytes.add(prefix, Bytes.toBytes(addLongPadding(lowValue))))));
    uidList.addFilter(new RowFilter(CompareFilter.CompareOp.LESS_OR_EQUAL,
                            new BinaryComparator(Bytes.add(prefix, Bytes.toBytes(addLongPadding(highValue))))));
} else
    uidList.addFilter(new RowFilter(CompareFilter.CompareOp.EQUAL,
                            new BinaryComparator(Bytes.add(prefix, Bytes.toBytes(addLongPadding(lowValue))))));
list.addFilter(uidList);

这只是一个例子,在list. 有没有办法可以使用FilterList运算符来否定过滤器?对于这个例子,我需要过滤所有不在lowValueand之间的行,highValue而 else 分支的行是NOT_EQUAL我的 value( lowValue == highValue)。

我知道运营商是基于的NANDNOR所以在技术上它是可能的,但我不知道如何。

4

1 回答 1

0

hbase 列没有 between 运算符。如果你想要那些类型的过滤器,你需要根据你的要求写在自己身上。

检查此代码段:

public ArrayList<HashMap<String, String>> between(String tableName,String colFamilyName, String [] colName,String betweenColName,String lowerValue,String upperValue)
{
    ResultScanner rs=null;
    ArrayList<HashMap<String, String>> al = new ArrayList<HashMap<String, String>>();
    Result res = null;
    try
    {
        HTable table = new HTable(conf, tableName);
        Scan scan = new Scan();
        SingleColumnValueFilter singleColumnValueFilterA = new SingleColumnValueFilter(
                Bytes.toBytes(colFamilyName), Bytes.toBytes(betweenColName), CompareOp.GREATER, Bytes.toBytes(lowerValue));
                singleColumnValueFilterA.setFilterIfMissing(true); 
        SingleColumnValueFilter singleColumnValueFilterB = new SingleColumnValueFilter(
                Bytes.toBytes(colFamilyName), Bytes.toBytes(betweenColName), CompareOp.LESS_OR_EQUAL, Bytes.toBytes(upperValue));
        singleColumnValueFilterB.setFilterIfMissing(true); 
        FilterList filter = new FilterList(Operator.MUST_PASS_ALL, Arrays.asList((Filter) singleColumnValueFilterA,
                singleColumnValueFilterB)); 
        scan.setFilter(filter); 
        rs = table.getScanner(scan);
        while((res=rs.next()) != null)
        {
            HashMap<String, String> map = new HashMap<String,String>();
            String s = null;
            for(int j=0 ; j < colName.length ; j++)
            {
                byte[] obtainedRow = res.getValue(Bytes.toBytes(colFamilyName),Bytes.toBytes(colName[j]));
                s = Bytes.toString(obtainedRow);
                map.put(colName[j],s);
            }           
            al.add(map);
        }
    } catch (IOException e)
    {
        System.out.println("Exception occured in retrieving data");
    }
    finally
    {
        rs.close();
    }
    return al;
}
于 2012-12-31T09:58:16.013 回答