如何使用 Aerospike 表达式通过正则表达式搜索列表项

huangapple go评论113阅读模式
英文:

How to search list items by regex with Aerospike Expressions

问题

我们正在从旧的 Aerospike 版本 3.15.1.4 迁移到版本 6.2.0.7。这涉及从 aerospike-client-go v4.5.2+incompatible 迁移到 aerospike-client-go/v6 v6.6.0。自 Aerospike 数据库 5.2 起,谓词表达式 (PredExp) 已被弃用。它们在 Aerospike 数据库 6.0 中被移除。因此,我们必须转向 Aerospike 表达式。

我们有一个包含字符串列表的 bin。我们想要使用“以...开始”的模式进行搜索。在旧的代码中,我们使用以下代码实现:

as.NewPredExpStringVar("v"),
as.NewPredExpStringValue("^"+regexp.QuoteMeta("search_term")),
as.NewPredExpStringRegex(QueryRegexOptionExtended|QueryRegexOptionIgnoreCase),
as.NewPredExpListBin("ListField"),
as.NewPredExpListIterateOr("v"),

在“新世界”中,以下示例将搜索精确值:

// 作为语句内的过滤器
as.NewContainsFilter("ListField", as.ICT_LIST, "search_term")

// 作为查询策略的 FilterExpression
*as.ExpGreater(
    as.ExpListGetByValue(
        as.ListReturnTypeCount,
        as.ExpStringVal("search_term"),
        as.ExpListBin("ListField")),
    as.ExpIntVal(0),

但是如何使用新的 Aerospike 表达式实现“以...开始”的搜索呢?

我们尝试了以下方法,但没有成功:

*as.ExpRegexCompare(
    "^"+regexp.QuoteMeta("search_term"),
    as.ExpRegexFlagICASE,
    as.ExpListBin("ListField"),
)

在 Aerospike 日志中出现以下警告:

WARNING (exp): (exp.c:1469) build_cmp_regex - error 4 invalid arg type 4 (list) != 3 (str)
WARNING (query): (query.c:1485) basic query job failed msg field processing

更多背景信息,这是数据库的设置:

我们有以下模型存储在 Aerospike 中:

type MyModel struct {
    ListField []string
    [其他字段]
}

以及以下二级索引:
索引名称:idx_MYSET_ListField / 命名空间:myns / 集合:MYSET / bin:ListField / bin:string / 索引:list / 状态:RW

如果我在 aql 中读取一个示例记录:

aql> select PK,ListField from myns.MYSET where PK = 12345
+--------------------+-------------------------------------------------------------------+
| PK | ListField |
+--------------------+-------------------------------------------------------------------+
| 12345 | LIST('["myid:1234", "testid2", "some-other-value", "more-values"]') |
+--------------------+-------------------------------------------------------------------+
英文:

We are migrating from our old aerospike version 3.15.1.4 to version 6.2.0.7. This involves the migration from aerospike-client-go v4.5.2+incompatible to aerospike-client-go/v6 v6.6.0. Predicate Expressions (PredExp) have been deprecated since Aerospike Database 5.2. They were removed in Aerospike Database 6.0. So we have to move to Aerospike Expressions.

We have a bin with a string-list in it. And we want to do a search with a "begins-with" pattern. In the old world, we do that with following code:

as.NewPredExpStringVar("v"),
as.NewPredExpStringValue("^"+regexp.QuoteMeta("search_term")),
as.NewPredExpStringRegex(QueryRegexOptionExtended|QueryRegexOptionIgnoreCase),
as.NewPredExpListBin("ListField"),
as.NewPredExpListIterateOr("v"),

Following examples will search vor exact value in the "new world":

// As filter inside statement
as.NewContainsFilter("ListField", as.ICT_LIST, "search_term")

// As FilterExpression on query-policy
*as.ExpGreater(
    as.ExpListGetByValue(
        as.ListReturnTypeCount,
        as.ExpStringVal("search_term"),
        as.ExpListBin("ListField")),
    as.ExpIntVal(0),

But how can we achive a "begins-with-search" with the new Aerospike Expressions?

We tried the following, without success:

*as.ExpRegexCompare(
    "^"+regexp.QuoteMeta("search_term"),
    as.ExpRegexFlagICASE,
    as.ExpListBin("ListField"),
)

In the aerospike-logs, the following warning appears:

WARNING (exp): (exp.c:1469) build_cmp_regex - error 4 invalid arg type 4 (list) != 3 (str)
WARNING (query): (query.c:1485) basic query job failed msg field processing

For more background-info, this is the db-setup:

We have following model which is getting stored inside aerospike:

type MyModel struct {
    ListField []string
    [some-other-fields]
}

And following secondary index:
Index name: idx_MYSET_ListField / namespace: myns / set: MYSET / bin: ListField / bin: string / index: list / State: RW

And if I read a sample record over aql:

aql> select PK,ListField from myns.MYSET where PK = 12345
+--------------------+-------------------------------------------------------------------+
| PK | ListField |
+--------------------+-------------------------------------------------------------------+
| 12345 | LIST('["myid:1234", "testid2", "some-other-value", "more-values"]') |
+--------------------+-------------------------------------------------------------------+

答案1

得分: 1

表达式不支持对列表或映射进行迭代。列表和映射的API通常提供了通过旧的predexp提供的迭代来解决用例的功能。这是我遇到的第一个无法使用列表/映射API复制的迭代方式的用例。

截至6.3版本,复制此行为的唯一方法可能是使用Stream UDF

英文:

Expressions do not support iteration over lists or maps. The list and map APIs normally provide functionality that would solve the use-cases using the iteration provided by the old predexp. This is the first use-case I've come across that used iteration in a way that cannot be replicated with the list/map APIs.

As of 6.3, the only way to replicate this behavior may be to use a Stream UDF.

huangapple
  • 本文由 发表于 2023年4月28日 15:32:16
  • 转载请务必保留本文链接:https://go.coder-hub.com/76127225.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定