布尔场上的Aerospike滤波器表达不起作用

发布于 2025-01-28 17:25:48 字数 1103 浏览 2 评论 0原文

我已经在Java写下了以下Aerospike过滤器。 field1field2都是布尔值。由于某种原因,尽管记录与标准匹配,但“ filterbyfield.validboth”条件并不能产生真实。

由于它是布尔值,所以我将1用于true,为false为0。

我想念什么吗?

public Exp getFilterByFieldFilter(FilterByField filterByField) {
    if (filterByField == null || "".equals(filterByField)) {
        return Exp.val(true);
    }
    if (filterByField == filterByField.All) {
        return Exp.val(true);
    } else if (filterByField == filterByField.ValidBoth) {
        return Exp.and(Exp.eq(Exp.intBin("Field1"), Exp.val(0)),
                Exp.eq(Exp.intBin("Field2"), Exp.val(0)));
    }
}

从我可以通过AQL从数据库结果中看到的内容,未设置为true的结果并未反映在结果集中。

我应该写过滤器是检查此情况的另一种方法吗?如果是这样,这种情况会是什么样?

我尝试检查exp.val(null),但出错。

这是通过AQL设置的数据库结果

 [
        {
          "PK": "1",
          "Name": "ABC",
          "Field1": 1,
          "Field2": 1
        },
        {
          "PK": "2",
          "Name": "EFG",
          "Field1": 1
        },
        {
          "PK": "3",
          "Name": "XYZ",
        }
        
    ]

I've written the following Aerospike filter in Java. Both Field1 and Field2 are booleans. For some reason, the "filterByField.ValidBoth" condition does not yield true, although the record matches the criteria.

Since it's a boolean, I'm using 1 for true and 0 for false.

Am I missing something?

public Exp getFilterByFieldFilter(FilterByField filterByField) {
    if (filterByField == null || "".equals(filterByField)) {
        return Exp.val(true);
    }
    if (filterByField == filterByField.All) {
        return Exp.val(true);
    } else if (filterByField == filterByField.ValidBoth) {
        return Exp.and(Exp.eq(Exp.intBin("Field1"), Exp.val(0)),
                Exp.eq(Exp.intBin("Field2"), Exp.val(0)));
    }
}

From what I can see from database results through AQL, those which are not set to true are not reflected in the result set.

Should I write my filter is a different way to check this condition? If so what would that condition look like?

I tried checking for Exp.val(NULL) but got error.

Here's my database result set through AQL

 [
        {
          "PK": "1",
          "Name": "ABC",
          "Field1": 1,
          "Field2": 1
        },
        {
          "PK": "2",
          "Name": "EFG",
          "Field1": 1
        },
        {
          "PK": "3",
          "Name": "XYZ",
        }
        
    ]

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

看海 2025-02-04 17:25:48

如果bin name field1和field2包含布尔值,则应以这种方式构造您的表达式(无论所需的逻辑是什么):

Exp.eq(Exp.boolBin("Field1"), Exp.val(false))

我测试了下面的构造,似乎对我有用:

WritePolicy wPolicy = new WritePolicy();

Bin b1 = new Bin("Field1", Value.get(0));
Bin b2 = new Bin("Field2", Value.get(0));
Bin b3 = new Bin("Data", Value.get("data"));

wPolicy.recordExistsAction = RecordExistsAction.REPLACE;

client.put(wPolicy, key, b1, b2, b3);

//client.put(wPolicy, key, b1, b3);

Exp condFilter = Exp.and( 
Exp.eq(Exp.intBin("Field1"),Exp.val(0) ),
Exp.eq(Exp.intBin("Field2"),Exp.val(0) )
);

Policy policy = new Policy();

policy.filterExp = Exp.build(condFilter);
Record record = client.get(policy, key);
System.out.println("Read back the record.");

System.out.println("Record values are:");
System.out.println(record);

//Get record without filter condition
record = client.get(null, key);
System.out.println(record);

有效条件:

Read back the record.
Record values are:
(gen:18),(exp:0),(bins:(Field1:0),(Field2:0),(Data:data))
(gen:18),(exp:0),(bins:(Field1:0),(Field2:0),(Data:data))

无效条件(无field2 bin):

Read back the record.
Record values are:
null
(gen:19),(exp:0),(bins:(Field1:0),(Data:data))

If bin names Field1 and Field2 contain boolean values then your expression should be constructed in this fashion (whatever the desired logic is):

Exp.eq(Exp.boolBin("Field1"), Exp.val(false))

I tested the construct below, seems to work for me:

WritePolicy wPolicy = new WritePolicy();

Bin b1 = new Bin("Field1", Value.get(0));
Bin b2 = new Bin("Field2", Value.get(0));
Bin b3 = new Bin("Data", Value.get("data"));

wPolicy.recordExistsAction = RecordExistsAction.REPLACE;

client.put(wPolicy, key, b1, b2, b3);

//client.put(wPolicy, key, b1, b3);

Exp condFilter = Exp.and( 
Exp.eq(Exp.intBin("Field1"),Exp.val(0) ),
Exp.eq(Exp.intBin("Field2"),Exp.val(0) )
);

Policy policy = new Policy();

policy.filterExp = Exp.build(condFilter);
Record record = client.get(policy, key);
System.out.println("Read back the record.");

System.out.println("Record values are:");
System.out.println(record);

//Get record without filter condition
record = client.get(null, key);
System.out.println(record);

Valid condition:

Read back the record.
Record values are:
(gen:18),(exp:0),(bins:(Field1:0),(Field2:0),(Data:data))
(gen:18),(exp:0),(bins:(Field1:0),(Field2:0),(Data:data))

Invalid Condition (no Field2 bin):

Read back the record.
Record values are:
null
(gen:19),(exp:0),(bins:(Field1:0),(Data:data))
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文