Persisting memory allocated in UDF across queries

Hello,

I need to maintain a data structure in C++ UDF that persists and can be used acropss queries.

I have created a few struct objects in ExprUtils.hpp that I was expecting to persist across query calls. But, I am seeing that for every query they seem to be reinitialized. Is dlopen and dlclose done on UDF shared lib for every query. Is there a way to have it persist so that one query sets certain things up which can be used by another query?

Thanks for your help!

Kumar

did you try static accumulators?

https://docs.tigergraph.com/dev/gsql-ref/querying/accumulators#static-global-accumulators

So that works on gsql side. I needed static retained object on udf c++ side.

can you try user-defined-tuple and persist the tuple in static accumulator?

for examples of udt with accumulator, see bi_13.gsql, ot other queries therein.

I am seeing that even within one query, across calls to two different UDFs, the static or global objects in ExprUtils.hpp are being reconstructed. Is that by design or a bug?

How do we have objects persist across calls of udf and across calls of query without maintaining a static accumulator on gsql side? It needs to be efficient. so I cannot pass things back to static accumulators and then pass accumulator back to another udf call. If I can have c++ side global or static objects simply stay, that would solve the problem.

Or, Is there a different better way to integrate tigergraph tightly with another tool using c++? I am trying to integrate Xilinx Alveo accelerator FPGA card with tigergraph and need to maintain states that should persist as long as the gpe server process is up and running.

Hi Kumar,

SHARE STATIC VARIABLES IN UDF OF THE SAME QUERY : You can define static variables inside UDF (it behaves the same as c++ static variable, it just has the namespace of the current query name) so that it can share among different calls of the UDF in the same query.

QUERY CALLING QUERY : The static accumulator is per query and it can not be shared across queries with a different query name. It is a static variable that has a namespace of the query name so that each different name of queries will have their own static variables. We currently only support return one value for the query calling query feature and if you want to return multiple variables you have to use tuple (Define a tuple inside the schema so that different queries can return the same type of tuple). However, sharing accumulators for the query calling query is on our road map.

Best Wishes,

Dan