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

Installing And Exploring Auto Dark Mode Software

Windows Auto--Night--Mode: Simplify Your Theme Switching   Windows Auto--Night--Mode is a free and lightweight tool that makes switching bet...