High Society High Society - 2 years ago 96
Python Question

qpython.sync() is returning a QProjection instead of the queried data

So I am running the following query without problems:

'{[x;y;z]select from trade where date within(x;y), sym in z}',
numpy.datetime64('2014-04-14', 'D'),
numpy.datetime64('2017-08-14', 'D'),
NumpyUtil.parse_symbols(['instr81', 'instr61', 'instr26'])

Here the
is just a dictionary with the tickerplant, hdb and rdb connections and the
is a little method that parses the argument to the correct Numpy type (has been successfully tested).

The result it produces is the following and is as suspected:

[ ('2017-07-20', b'instr26', 31538122, b'instr14', 93.87083689, 77.0477359 , 81)
('2017-07-20', b'instr26', 31543119, b'instr72', 27.69372507, 80.00145357, 8)
('2017-07-20', b'instr26', 31678121, b'instr56', 58.24375362, 13.93626591, 36)
('2017-07-26', b'instr81', 55344040, b'instr95', 18.75910878, 63.28561637, 98)
('2017-07-26', b'instr81', 81898858, b'instr78', 34.76710694, 8.32085477, 69)
('2017-07-26', b'instr81', 81938857, b'instr97', 64.54823106, 0.16524401, 81)]

Perfect :)

My problem arises when I put it into this wrapper method:

def synced_query(self, database, query, parameters):
print(self.connections[database].sync(query, parameters))

When passing the exact same parameters, it returns something else, a QProjection:

QProjection(QLambda('{[x;y;z]select from trade where date within(x;y),sym in z}'), [numpy.datetime64('2012-06-20'), numpy.datetime64('2017-07-30'), QList([b'instr81', b'instr61', b'instr26'],

Now I've looked through my code (the data is passed around through some functions before ending up in the
method) but I believe the data is parsed and passed correctly.

When I look at the docs the
method should only return a message returned from kdb and otherwise raise an exception.

So I'm basicly wondering why kdb is giving me such a strange answer. Any ideas? :)

Answer Source

It looks like you need to unpack the values in your python list parameters. Try:

def synced_query(self, database, query, parameters):
    print(self.connections[database].sync(query, *parameters))

(Notice the *)

As you have it currently, you are passing in one parameter (a list with 3 items) into your Q function, but you need pass in 3 parameters. A kdb Projection type is returned because you have called a function with fewer parameters than it is expecting.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download