简体   繁体   English

多个过滤器在HBase 1.2.6中不起作用

[英]Multiple filters not work in HBase 1.2.6

My HBase schema looks like as following: 我的HBase模式如下所示:

{
    "<trace-id>": {
        "span-timestamp": {
            "ts:span:<timestamp>": ""
        },
        "span-name": {
            "ts:span:<name>": ""
        },
        "span-duration": {
            "ts:span:<duration>": ""
        },
        "span-blob": {
            "ts:span:<span-id>": "<span>"
        },
        "endpoint": {
            "ts:endpoint:<service-name>": ""
        },
        "annotation": {
            "ts:annotation:<value>": ""
        },
        "binary-annotation": {
            "ts:binary-annotation:<key>": "<value>",
        },
    }
}

In my circumstance, I need query specific qualifiers, so I constructed following filters: 在我的情况下,我需要查询特定的限定词,因此我构造了以下过滤器:

final FilterList filters = new FilterList(Operator.MUST_PASS_ALL);
final Charset cs = HOperation.CHARSET;
filters.addFilter(Filters.qualifier(Schema.SCHEMA_TRACES_ENDPOINT, CompareOp.EQUAL, request.serviceName));
filters.addFilter(Filters.qualifier(Schema.SCHEMA_TRACES_SPAN_NAME, CompareOp.EQUAL, request.spanName));
filters.addFilter(Filters.qualifier(Schema.SCHEMA_TRACES_SPAN_TIMESTAMP,
request.endTs * 1000 - request.lookback * 1000, request.endTs * 1000));
filters.addFilter(new PageFilter(request.limit));
scan.setFilter(filters);
scan.setLoadColumnFamiliesOnDemand(true);

As you can see, I've bound column family filter with qualifier filter, which means the row will be returned only if both of family filter and qualifier filter evaluate to true. 如您所见,我已将列族过滤器与限定符过滤器绑定在一起,这意味着仅当族过滤器和限定符过滤器的两个值都为true时,才返回该行。

static FilterList qualifier(final Schema schema, final CompareOp op, final byte[] value) {
    final FilterList list = new FilterList(Operator.MUST_PASS_ALL);
    list.addFilter(new FamilyFilter(CompareOp.EQUAL, new BinaryComparator(schema.cf().getBytes(HOperation.CHARSET))));
    list.addFilter(new QualifierFilter(op, new BinaryComparator(value)));
    return list;
}

After I've tried the code, I found my find method based on Table#getScanner(Scan) could not work properly. 在尝试了代码之后,我发现基于Table#getScanner(Scan) find方法无法正常工作。

What's more, I found these two filters could not work together: 而且,我发现这两个过滤器无法一起使用:

filters.addFilter(Filters.qualifier(Schema.SCHEMA_TRACES_ENDPOINT, CompareOp.EQUAL, request.serviceName));
filters.addFilter(Filters.qualifier(Schema.SCHEMA_TRACES_SPAN_NAME, CompareOp.EQUAL, request.spanName));

Typically, when I comment out any one of these two filters it work. 通常,当我注释掉这两个过滤器中的任何一个时,它将起作用。 Of course, not perfectly work, cause I need it return limit rows, however, it's not. 当然,不能完美地工作,因为我需要它返回limit行,但是事实并非如此。

Any ideas would be appreciate. 任何想法将不胜感激。 Thanks a lot! 非常感谢!

After several days research about HBase, I finally figured out the real reason why these multiple filters not working properly together. 在对HBase进行了几天的研究之后,我终于弄清楚了为什么这些多个过滤器不能一起正常工作的真正原因。

In HBase, Filter is obviously for output not just working as an condition. 在HBase中, Filter显然用于输出,而不仅仅是作为条件。

For example, if a row (with row key row ) with 3 columns called as cf:A , cf1:1 , cf2:2 (column family is obviously cf , cf1 , cf2 ). 例如,如果具有3列的行(具有row key row )称为cf:Acf1:1cf2:2 (列族显然是cfcf1cf2 )。


Situation 1: 情况一:

Applying a FamilyFilter and the family must be cf , this will not return any family that not match(only those families with name of cf returned for one row), in this scenario, cf1:1 and cf2:2 will not be included in return value. 应用FamilyFilter并且该家庭必须是cf ,这将不返回任何不匹配的家庭(仅返回名称为cf那些家庭一行),在这种情况下, cf1:1cf2:2将不包含在返回中值。


Situation 2: 情况2:

Applying a QualifierFilter and the qualifier must be 1 , than only cf1:1 will be returned. 应用QualifierFilter且该限定符必须为1cf1:1将仅返回cf1:1


Of course, these situations should be easy to understand. 当然,这些情况应该很容易理解。


However , how about applying these filters together? 但是 ,如何一起应用这些过滤器? The result is interesting. 结果很有趣。 If you try to applying following filters: 如果您尝试应用以下过滤器:

QualifierFilter(=,'binary:1') && QualifierFilter(=,'binary:2')

It seems like you want to get rows with both qualifier 1 and 2 exist no matter which family it belongs to. 似乎您想获得同时存在限定符12行,无论它属于哪个家族。 Actually, you won't get row caused there is no column matching those two filters at same time. 实际上,由于没有同时匹配这两个过滤器的 ,您不会得到row


After all, this is not best practice for using HBase. 毕竟,这不是使用HBase的最佳实践。 In chapter 34( Table Schema Rules Of Thumb ) of official reference, there are suggestions for building schemas. 在官方参考的第34章“ 表模式的经验法则”中 ,提出了一些构建模式的建议。 And this question is not best designed and confused with RDBMS. 而且这个问题不是最佳设计,并且不能与RDBMS混淆。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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