HBase多列过滤 [英] HBase multi columns filtering

查看:731
本文介绍了HBase多列过滤的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个HBase中有多列的表。表的结构如下所示:

I have a table with multiple columns in HBase. The structure of the table is something like this:

row1 column=cf:c1, timestamp=xxxxxx, value=v1
row1 column=cf:c2, timestamp=xxxxxx, value=v2
row1 column=cf:c3, timestamp=xxxxxx, value=v3
...

我想编写一个自定义过滤器,它可以过滤某个列中的值。例如,如果列c3中的值v3存在,我想包括整行,否则将其放下。据我了解,HBase过滤器基于单元格,它将包含/跳过一列。我想知道在Hbase中是否有类型的过滤器可以像我想要的那样进行过滤?我应该如何执行它?

I want to write a custom filter which can filter the value in a certain column. For example, if the value v3 in the column c3 exists, I want to include the whole row, otherwise drop it. As far as I understand, the HBase filter is based on the cell, which will include/skip just one column. I wonder if there is a type of filter in Hbase that can do the filtering like I want? And how should I implement it?

谢谢。

推荐答案

您可以使用 SingleColumnValueFilter 解决此问题。
使用你的例子,你可以这样做:

You could use SingleColumnValueFilter for this problem. Using your example, you could do this:

SingleColumnValueFilter filter = new SingleColumnValueFilter(Bytes.toBytes("cf"), Bytes.toBytes("c3"), CompareFilter.CompareOp.EQUAL, Bytes.toBytes("v3"));

然后,您可以按照以下方式将过滤器添加到扫描中:

Then, you can add the filter to your scan this way:

Scan scan = new Scan();
scan.setFilter(filter);

另外,如果您想拥有多个过滤器,您也可以这样做。只需确保将它们添加到FilterList并将其传递给您的扫描(使用setFilter方法)。

Also, if you wanted to have multiple filters you can do that too. Just make sure to add them to a FilterList and pass it to your scan (using the setFilter method).

SingleColumnValueFilter f1 = new SingleColumnValueFilter(Bytes.toBytes("cf"), Bytes.toBytes("c3"), CompareFilter.CompareOp.EQUAL, Bytes.toBytes("v3"));
SingleColumnValueFilter f2 = new SingleColumnValueFilter(Bytes.toBytes("cf"), Bytes.toBytes("c2"), CompareFilter.CompareOp.EQUAL, Bytes.toBytes("v2"));

FilterList filterList = new FilterList(FilterList.Operator.MUST_PASS_ONE); //could be FilterList.Operator.MUST_PASS_ALL instead
filterList.addFilter(f1);
filterList.addFilter(f2);

Scan scan = new Scan();
scan.setFilter(filterList);

这篇关于HBase多列过滤的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆