1 回答
TA贡献1906条经验 获得超10个赞
我正在使用您在第二次更新中创建的新的和修改过的过滤器运行您的测试,它似乎有效。这是我使用的完整代码(基于 Git 存储库中的 Aerospike 示例目录):
/*
* Copyright 2014-2022 Aerospike, Inc.
*
* Portions may be licensed to Aerospike, Inc. under one or more contributor
* license agreements.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package main
import (
"log"
as "github.com/aerospike/aerospike-client-go/v5"
shared "github.com/aerospike/aerospike-client-go/v5/examples/shared"
)
func main() {
testListExp(shared.Client)
log.Println("Example finished successfully.")
}
func testListExp(client *as.Client) {
log.Printf("Test List Expression")
key, _ := as.NewKey(*shared.Namespace, *shared.Set, "mapkey1")
client.Delete(shared.WritePolicy, key)
binHostname := as.NewBin("hostname", "host01")
amap := map[string]string{
"k": "v",
}
list := []string{
"1",
"123456",
"1111",
"222",
}
binCont := as.NewBin("cont", amap)
binNumbers := as.NewBin("numbers", list)
client.PutBins(shared.WritePolicy, key, binHostname, binCont, binNumbers)
key, _ = as.NewKey(*shared.Namespace, *shared.Set, "mapkey2")
binHostname = as.NewBin("hostname", "host02")
list = []string{
"1",
"654321",
"2222",
"3333",
}
binNumbers = as.NewBin("numbers", list)
client.PutBins(shared.WritePolicy, key, binHostname, binCont, binNumbers)
// numbVal := "654321"
getPolicy := as.NewQueryPolicy()
getPolicy.FilterExpression =
as.ExpEq(
as.ExpListGetByValue(
as.ListReturnTypeCount,
as.ExpStringVal("654321"),
as.ExpListBin("numbers")),
as.ExpIntVal(1))
stmt := as.NewStatement(*shared.Namespace, *shared.Set)
recordSet, err := client.Query(getPolicy, stmt)
shared.PanicOnError(err)
for res := range recordSet.Results() {
log.Println(res.Record.Bins)
}
}
输出是:
$ go run listExpression.go -h 172.17.0.3
2022/06/08 12:00:19 hosts: 172.17.0.3
2022/06/08 12:00:19 port: 3000
2022/06/08 12:00:19 user:
2022/06/08 12:00:19 password: *
2022/06/08 12:00:19 namespace: test
2022/06/08 12:00:19 set: testset
2022/06/08 12:00:19 Test List Expression
2022/06/08 12:00:19 map[cont:map[k:v] hostname:host02 numbers:[1 654321 2222 3333]]
2022/06/08 12:00:19 Example finished successfully.
- 1 回答
- 0 关注
- 79 浏览
添加回答
举报