Search code examples
pythonaerospike

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(*)

Using Python with the above LUA scripts, I tried to apply the UDF with a read policy:

        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.


Solution

  • 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. (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 )