【发布时间】:2016-08-22 12:45:33
【问题描述】:
我想创建一个扫描仪,它会给我带有 2 个前缀过滤器的结果
例如,我想要其键以字符串“x”开头或以字符串“y”开头的所有行。
目前我知道只用一个前缀通过以下方式做到这一点:
scan.setRowPrefixFilter(prefixFiltet)
【问题讨论】:
标签: java hadoop mapreduce hbase
我想创建一个扫描仪,它会给我带有 2 个前缀过滤器的结果
例如,我想要其键以字符串“x”开头或以字符串“y”开头的所有行。
目前我知道只用一个前缀通过以下方式做到这一点:
scan.setRowPrefixFilter(prefixFiltet)
【问题讨论】:
标签: java hadoop mapreduce hbase
在这种情况下你不能使用setRowPrefixFilter API,你必须使用更通用的setFilter API,比如:
scan.setFilter(
new FilterList(
FilterList.Operator.MUST_PASS_ONE,
new PrefixFilter('xx'),
new PrefixFilter('yy')
)
);
【讨论】:
scan.setRowPrefixFilter(prefix) 进行多次扫描可能会更快。
我刚刚尝试过,但似乎您不能将正则表达式添加到 RowPrefixFilter,所以我想解决方案是使用
发出两个请求scan.setRowPrefixFilter("x")
scan.setRowPrefixFilter("y")
这将为您提供所需的行。
【讨论】:
我已经实现了一个批量设置前缀过滤器,也许可以帮助你
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);
【讨论】: