Forum: Building VoltDB Applications

Post: Get the query from callback procedure

Get the query from callback procedure
dogan
Jun 2, 2015
Hi,
Is it possible to get the running query inside callback procedure.

What i am trying to do is, running too many queries using async. calls.
In the client side, i have to map query itself and its results into a hash structure.

Thanks in advance,
nshi
Jun 2, 2015
Hi Dogan,

You can create a callback object for each async invocation. Inside the callback, you can store a unique ID which you can use as the hash keys.
dogan
Jun 2, 2015
Hi nshi,
I need both query and the corresponding results in callback procedure. Using async. calls, i can't achieve to map a query and its results.

Best,
nshi
Jun 2, 2015
Hi,

Are you issuing AdHoc queries or calling stored procedures?

If you are issuing AdHoc queries, you can pass context information, including the query, to the callback when you construct it. When the callback is called, you have all the information to tie it back to the original context.

If you are calling stored procedures, the client doesn't have direct access to the SQL statements used in the procedure, so you need to get that by code sharing. Depends on what you want to do with the query afterwards, there may be other information you can store in the callback without having to get the actual query.
bballard
Jun 2, 2015
In some of our demos we have a "BenchmarkCallback" class that takes a String in the constructor that is the procedure name (or in your case could be the query). The callback class has some private static attributes that are thread-safe data structures that are used for counting statistics of how many of the queries were called, were committed, and were rolled back. It can print a summary report of these metrics for each procedure that was called.

https://github.com/VoltDB/app-nbbo/blob/master/client/src/nbbo/BenchmarkCallback.java

You could make a callback class similar to this where you pass in the query to the constructor, and then later when the callback gets the results it will also have the query. Whether you want to track things internally within the callback class as in this example, or elsewhere, is up to you.
dogan
Jun 2, 2015
Hi,
Thanks for your response.
Yes, I issue AdHoc queries using c++ client library.
How can i pass a context information? Is there an example that i can follow?
..
gVoltDBclient.invoke(procedure, callback);


..

Thanks
nshi
Jun 3, 2015
When you create your callback class by inheriting from the ProcedureCallback class, you can create a constructor that takes the context information and store them as member variables in the callback. For example,


...
class MyCallback : public voltdb::ProcedureCallback
{
public:
    MyCallback(string query) m_query(query) {
        ...
    }

private:
    string m_query;
};
...