【发布时间】:2019-08-23 18:50:54
【问题描述】:
我正在尝试使用 qpython 从 python 客户端实现多行查询。
我想执行以下查询:
a = """
/declare a function that pivots a table on index
piv:{[t;k;p;v]f:{[v;P]`${raze "_" sv x} each string raze P,'/:v};v:(),v; k:(),k; p:(),p;G:group flip k!(t:.Q.v t)k;F:group flip p!t p;key[G]!flip(C:f[v]P:flip value flip key F)!raze{[i;j;k;x;y]a:count[x]#x 0N;a[y]:x y;b:count[x]#0b;b[y]:1b;c:a i;c[k]:first'[a[j]@'where'[b j]];c}[I[;0];I J;J:where 1<>count'[I:value G]]/:\:[t v;value F]};
/get aggregated trades table
tt:0!select last_price:last price, last_qty: last qty, low_qty: min qty by exch,sym,side,1 xbar time.second from trades
/apply pivot function on aggregated trade table
piv[`tt;`second;`exch`sym`side;`last_price`last_qty`low_qty]
"""
下面的qpython 客户端只是调用远程 kdb+/q 服务器来检索对上述查询的响应
with qconnection.QConnection(host='localhost', port=5001, pandas = True) as q:
q.query(qconnection.MessageType.SYNC, a)
msg = q.receive(data_only=False, raw=False)
print(msg)
但是它会引发以下_read_error:
qpython.qtype.QException: b'tt'
但是,在远程服务器 q shell 上执行的相同查询是否正确运行? 我认为这可能与反序列化期间对变量的取消引用有关,但是我不确定这是否是由于上述客户端的错误实现或查询中的逻辑格式错误。
实现上述多行查询的规范方式是什么?
【问题讨论】:
标签: python time-series client kdb