简体   繁体   English

Aerospike count all filter by TTL

[英]Aerospike count all filter by TTL

I'm trying to perform the following query:我正在尝试执行以下查询:

SELECT COUNT(*) FROM ns123.foo WHERE ttl < 60 * 60 * 24

I found the lua scripts from Aerospike AQL count(*) SQL analogue script to perform the COUNT(*)我从Aerospike AQL count(*) SQL 模拟脚本中找到了 lua 脚本来执行COUNT(*)

Using Python with the above LUA scripts, I tried to apply the UDF with a read policy:将 Python 与上述 LUA 脚本一起使用,我尝试通过读取策略应用 UDF:

        client.udf_put('aggr_functions.lua')
        query = client.query('ns123', 'foo')
        policy = {
            'expressions':
                exp.LT(exp.TTL(), 60 * 60 * 24).compile()
        }
        query.apply('aggr_functions', 'count_star', [])
        records = query.results(policy)
        print(records)

I'm getting thrown with:我被抛出:

Traceback (most recent call last):
  ...
    records = query.results(policy)
exception.UnsupportedFeature: (16, 'AEROSPIKE_ERR_UNSUPPORTED_FEATURE', 'src/main/aerospike/aerospike_query.c', 348, False)

Using Aerospike 6.1.x for both Python3.8 lib and server.对 Python3.8 库和服务器使用 Aerospike 6.1.x。

Aggregations don't support filter expressions.聚合不支持过滤器表达式。 But you can write the filter code in lua add the filter function in the lua aggregation module itself.但是您可以在 lua 中编写过滤器代码,在 lua 聚合模块本身中添加过滤器 function。 (I have a code example for using filters with aggregations in lua posted here: https://discuss.aerospike.com/t/record-manipulation-with-more-than-one-filter-lua/3637 ) (我有一个代码示例用于在 lua 中使用聚合过滤器发布在这里: https://discuss.aerospike.com/t/record-manipulation-with-more-than-one-filter-lua/3637

As stated above, in aggregations, filters should be in the lua script.如上所述,在聚合中,过滤器应该在 lua 脚本中。 The script I'm using:我正在使用的脚本:

function counts(s)
    function mapper(rec)
        local ttl = record.ttl(rec);
        local ttl_threshold = 86400;
        if ttl <= ttl_threshold and ttl > 0 then
            return 1
        else
            return 0
        end
    end
    local function reducer(v1, v2)
        return v1 + v2
    end
    return s : map(mapper) : reduce(reducer)
end

This corresponding to the query这对应于查询

SELECT COUNT(*) FROM ns123.foo WHERE ttl < 60 * 60 * 24 AND ttl > 0

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

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