简体   繁体   中英

Set Multiple prefix row filter to scanner hbase java

I want to create one scanner that will give me result with 2 prefix filters
For example I want all the rows that their key starts with the string "x" or start with the string "y".
Currently I know to do it only with one prefix with the following way:

scan.setRowPrefixFilter(prefixFiltet)

In this case you can't use the setRowPrefixFilter API, you have to use the more general setFilter API, something like:

scan.setFilter(
  new FilterList(
    FilterList.Operator.MUST_PASS_ONE, 
    new PrefixFilter('xx'), 
    new PrefixFilter('yy')
  )
);

I have just tried but it doesn't seems you can add a regular expression to a RowPrefixFilter, so I guess the solution is to make two requests using

scan.setRowPrefixFilter("x")
scan.setRowPrefixFilter("y")

This will get you the rows you want.

I have implement a batch set prefix filter ,maybe can help you

    List<String> bindCodes = new ArrayList<>();
    bindCodes.add("CM0001");
    bindCodes.add("CE7563");
    bindCodes.add("DR6785");

    Scan scan = new Scan();
    scan.setCaching(50);//set get batch numbers
    //set Column
    scan.addColumn(HTableColumnEnum.GPS_CF_1.getCfName().getBytes(), LOCATION_CREATE_DATE_ARRAY);
    //set Family
    scan.addFamily(HTableColumnEnum.GPS_CF_1.getCfName().getBytes());

    //create filterList
    FilterList filterList = new FilterList(FilterList.Operator.MUST_PASS_ONE);
    //put mulit prefix row key
    bindCodes.forEach(s -> {
        filterList.addFilter(new PrefixFilter(Bytes.toBytes(s)));
    });

    //set filterList to scan
    scan.setFilter(filterList);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM