Aerospike: How to Execute IN Request on PC

How to execute (sql like) IN queries in aerosics. Do we need a UDF for this?

Something like that: Select * from ns.set where PK in (1,2,3)

If it requires a UDF, how to do it since UDF is executed on a key:

EXECUTE <module>.<function>(<args>) ON <ns>[.<set>] WHERE PK = <key>

      

+3


source to share


2 answers


You are mainly looking at getting records from a list of keys. This is a batch read operation in Aerospike. Every language client for Aerospike should have this capability.

For example, in a Python client, this is the Client.get_many method:



from __future__ import print_function
import aerospike
from aerospike.exception import AerospikeError
import sys

config = { 'hosts': [('127.0.0.1', 3000)] }
client = aerospike.client(config).connect()

try:
    # assume the fourth key has no matching record
    keys = [
      ('test', 'demo', '1'),
      ('test', 'demo', '2'),
      ('test', 'demo', '3'),
      ('test', 'demo', '4')
    ]
    records = client.get_many(keys)
    print records
except AerospikeError as e:
    print("Error: {0} [{1}]".format(e.msg, e.code))
    sys.exit(1)
finally:
    client.close()

      

Similarly, in a Java client, the AerospikeClient.get () method can accept a list of keys.

+2


source


In Ver 3.12.1+, you can run queries like this if you store your master key in a bucket and then run predicate filtering in that bucket. See http://www.aerospike.com/docs/guide/predicate.html



Aerospike does not by default store PK in its original string or numeric form as it is assigned. It stores the hash RIPEMD160 of the PK + Set name.

+2


source







All Articles