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

倖福魔咒の 提交于 2019-12-25 08:49:45

问题


So I am running the following query without problems:

print(self.data_source.connections['history'].sync(
            '{[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 self.data_source.connections[] is just a dictionary with the tickerplant, hdb and rdb connections and the NumpyUtil.parse_symbols() 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'],
      dtype='|S7')])

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

When I look at the docs the q.sync() 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? :)


回答1:


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.



来源:https://stackoverflow.com/questions/45347252/qpython-sync-is-returning-a-qprojection-instead-of-the-queried-data

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!