Wednesday, January 25, 2012

Impliment And/Or multi condition in hbase.

Here  FilterList listOfFiltersA and FilterList listOfFiltersB will impliment AND condition of the filters in the filter list and  FilterList listOfFiltersC will impliment OR Condition on  listOfFiltersA and listOfFiltersB

 public static void multiConditionReturn() throws IOException
    {
        HTable hTable = new HTable("well");
        Scan scan = new Scan();
        FilterList listOfFiltersA = new FilterList(FilterList.Operator.MUST_PASS_ALL);
        FilterList listOfFiltersB = new FilterList(FilterList.Operator.MUST_PASS_ALL);
        FilterList listOfFiltersC = new FilterList(FilterList.Operator.MUST_PASS_ONE);
        SingleColumnValueFilter nodeFilter;
       
        nodeFilter = new SingleColumnValueFilter
                (
                Bytes.toBytes("cf"),
                Bytes.toBytes("well_name"),
                CompareOp.EQUAL,
                Bytes.toBytes("AB Test Well")
                );
        listOfFiltersA.addFilter(nodeFilter);
        nodeFilter = new SingleColumnValueFilter
                (
                Bytes.toBytes("cf"),
                Bytes.toBytes("well_region"),
                CompareOp.EQUAL,
                Bytes.toBytes("Region Name")
                );
        listOfFiltersA.addFilter(nodeFilter);
       
        nodeFilter = new SingleColumnValueFilter
                (
                Bytes.toBytes("cf"),
                Bytes.toBytes("wellDatum_name"),
                CompareOp.EQUAL,
                Bytes.toBytes("Kelly Bushing")
                );
        listOfFiltersB.addFilter(nodeFilter);       
        nodeFilter = new SingleColumnValueFilter
                (
                Bytes.toBytes("cf"),
                Bytes.toBytes("well_uid"),
                CompareOp.EQUAL,
                Bytes.toBytes("BGC_TD")
                );
        listOfFiltersB.addFilter(nodeFilter);      
        listOfFiltersC.addFilter(listOfFiltersA);
        listOfFiltersC.addFilter(listOfFiltersB);
        scan.setFilter(listOfFiltersC);
        ResultScanner scanner = hTable.getScanner(scan);

        for (Result result : scanner) {
        System.out.println(result);           
        }
    }

No comments:

Post a Comment

Thank you for Commenting Will reply soon ......

Featured Posts

#Intel #Core #i9 #Processors: A Breakdown

Intel Core i9 Processors: A Breakdown Intel's 14th Gen Core i9 series offers a range of processors designed for various use cases. Her...