Is it possible to do database queries inside UDF function?


#1

Inside a record/stream UDF function can access a single record or a set of records (stream), from the record’s data is it possible to perform another query in the same/different set?


#2

Justin,

No !!!

But you do not need to :). What are you trying to achieve? – R


#3

@raj

Lets assume I have 2 sets in my Aerospike DB, first I’m executing a record UDF on set 1 which will get a bin’s value and extracts a value from that string. This extracted value will be the key for the 2nd set, if it’s possible to do a DB query from the same record UDF I can access a record from the second set and do further logic.

In this example I have mentioned only 2 sets but there might be more than 2, how this can be achieved?


#4

@raj

In order to over come this we can use multiple UDFs, from the first call need to send back the results to client side and execute the second function and get the results. This will increase the client-server calls also the data has to be passed back and forth, is there a way to avoid this and do all the execution in the server it self?


#5

Justin,

What you say it correct. It is some kind of join operation you are performing across multiple sets. The only way to do that would be two round trip with data moving back and forth.

You may probably have to model data and further denormalize it to avoid join hoping it does not blow up too much.

– R


#6

Will this functionality be added in the next future? If yes, how soon?


#7

Not in plans at this point.

Thanks – Raj


#8

Thank you for your reply raj but such as I’m dealing with some problems, can I use aerospike lua client (http://www.aerospike.com/launchpad/aerospike_lua_client.html) for reading records in lua udf? If it is not possible, how could I do it?


#9

Do we have this feature now? I need this to maintain unique constraints on some bins. This feature could be very helpful in doing that!


#10

It isn’t. You should check those constraints on the application side by fetching the records you need and doing the logic there. It’ll perform better than the UDF approach, even if this was possible.