qpython.sync()返回QProjection而不是查询的数据 [英] qpython.sync() is returning a QProjection instead of the queried data
问题描述
所以我正在运行以下查询而没有问题:
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'])
))
这里self.data_source.connections[]
只是一个包含tickerplant,hdb和rdb连接的字典,而NumpyUtil.parse_symbols()
是一种将参数解析为正确的Numpy类型(已成功测试)的小方法.
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)]
完美:)
当我将其放入此包装方法时,就会出现问题:
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))
当传递 exact 相同的参数时,它会返回其他内容,即QProjection:
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')])
现在,我浏览了我的代码(在使用synced_query()
方法结束之前,数据已经通过某些函数传递了),但是我认为数据已正确解析并传递.
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.
当我查看文档时,q.sync()
方法应该只返回从kdb返回的消息,否则会引发异常.
When I look at the docs the q.sync()
method should only return a message returned from kdb and otherwise raise an exception.
所以我基本上想知道为什么kdb给我这么奇怪的答案.有任何想法吗? :)
So I'm basicly wondering why kdb is giving me such a strange answer. Any ideas? :)
推荐答案
您似乎需要解压缩python列表parameters
中的值.试试:
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))
(请注意*
)
目前,您正在将一个参数(包含3个项目的列表)传递给Q函数,但是您需要传递3个参数.之所以返回kdb Projection类型,是因为您调用的函数的参数比预期的要少.
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.
这篇关于qpython.sync()返回QProjection而不是查询的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!