Java 在 hbase 中指定多个过滤器

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18443291/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-12 01:40:14  来源:igfitidea点击:

Specify multiple filters in hbase

javahbase

提问by priya

Is there a way to specify multiple filters during a scan? For example - Specify both a ColumnFamilyFilterand RowFilter?

有没有办法在扫描期间指定多个过滤器?例如 - 同时指定 aColumnFamilyFilterRowFilter?

Filter rowFilter =
                new RowFilter(CompareFilter.CompareOp.EQUAL, new RegexStringComparator(
                        rowFilterString));
        Scan s = new Scan();
        s.setFilter(rowFilter);

I wanted to also add a ColumnFilterto s. But it obviously overrides the latest filter.

我还想添加一个ColumnFilters. 但它显然覆盖了最新的过滤器。

回答by Hari Menon

You have to create a FilterListobject, and add all the filters you want to that, and set this FilterListobject as the filter. You can either use the constructor or use the addFilter()method to add filters to the filter list.

您必须创建一个FilterList对象,并添加您想要的所有过滤器,并将此FilterList对象设置为过滤器。您可以使用构造函数或使用addFilter()方法将过滤器添加到过滤器列表中。

FilterList filterList = new FilterList();
filterList.addFilter(new RowFilter(...));
filterList.addFilter(new ColumnFilter(...));
Scan s = new Scan();
s.setFilter(filterList);

回答by ArpanKhandelwal

if you are adding multiple filters then do remember that by default filterlist uses

如果您要添加多个过滤器,请记住默认情况下过滤器列表使用

FilterList.Operator.MUST_PASS_ALL

which means all filter must be passed (AND condition). Use

这意味着必须通过所有过滤器(AND 条件)。用

FilterList.Operator.MUST_PASS_ONE 

if you want to apply OR condition for filters.

如果要为过滤器应用 OR 条件。

回答by VishAmdi

You can use the FilterList object to add your list of filters and can control the order of filters using an ArrayList. Each FilterList takes in only a single operator[OR, AND].But, an hierarchy of filter lists can be created by adding multiple filter list instances with their own operators to a parent filter list.

您可以使用 FilterList 对象添加过滤器列表,并可以使用 ArrayList 控制过滤器的顺序。每个 FilterList 只接受一个运算符 [OR, AND]。但是,可以通过将多个带有自己的运算符的过滤器列表实例添加到父过滤器列表来创建过滤器列表的层次结构。

For example: filters_1 & filters_2 are two filter lists.

例如:filters_1 & filters_2 是两个过滤器列表。

FilterList filterList1 = new FilterList(FilterList.Operator.MUST_PASS_ONE,filters_1);
FilterList filterList2 = new FilterList(FilterList.Operator.MUST_PASS_ALL,filters_2);


List<Filter> filterAggregate = new ArrayList<>();
filterAggregate.add(filterList1);
filterAggregate.add(filterList2);

FilterList filterList3 = new FilterList(FilterList.Operator.MUST_PASS_ALL,filterAggregate);