Set Multiple prefix row filter to scanner hbase java

感情迁移 提交于 2019-12-13 15:18:32

问题


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)

回答1:


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



回答2:


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.




回答3:


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


来源:https://stackoverflow.com/questions/39079949/set-multiple-prefix-row-filter-to-scanner-hbase-java

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!