【发布时间】:2020-02-22 10:54:13
【问题描述】:
我在将查询中的转义序列应用于 kdb 服务器时遇到问题。
本机查询是:
select lo:min price, hi:max price by sym from trade where date = 2007.02.28, not cond like "*[BMPQTUWZ]*", corr <= 1
欢迎任何帮助。
我使用 Python 发送它,我在查询中输入了 \" for " 以便传输双引号:
from qpython import qconnection
import pandas as pd
from datetime import datetime
query = 'select lo:min price, hi:max price by sym from trade where date = 2007.02.28, not cond like \"*[BMPQTUWZ]*\", corr <= 1'
#query = '\"2+2\"'
print('Attempt to open a connection...')
q = qconnection.QConnection(host=server, port=server_port, username=user, password=server_password, timeout=server_timeout, pandas = True)
q.open()
print('Connection established...')
print('Attempt to send the query', query)
df = pd.DataFrame(q.sendSync(query))
print('Query <<', query, '>> sent...')
'"2+2"' 的输出和 'select lo:min price, hi:max price by sym from trade where date = 2007.02.28, not cond like \"[BMPQTUWZ] em>\", corr
现在,我遇到了转义字符问题。 如果我将查询发送到 kdb 服务器。 查询被传输。但是当我添加 not cond like \"[BMPQTUWZ]\" 时,出现错误。 操作系统和 Python 语言详细信息:
Windows 10、x64、Python 3.8.1PS G:\atom-projects\test> python.exe .\test-1.py
Attempt to open a connection...
Connection established...
Attempt to send the query "2+2"
Traceback (most recent call last):
File ".\test-1.py", line 23, in <module>
df = pd.DataFrame(q.sendSync(query))
File "C:\Python38\lib\site-packages\pandas\core\frame.py", line 509, in __init__
raise ValueError("DataFrame constructor not properly called!")
ValueError: DataFrame constructor not properly called!
PS G:\atom-projects\test> python.exe .\test-1.py
Attempt to open a connection...
Connection established...
Attempt to send the query select lo:min price, hi:max price by sym from trade where date = 2007.02.28, not cond like "*[BMPQTUWZ]*", corr <= 1
Traceback (most recent call last):
File ".\test-1.py", line 23, in <module>
df = pd.DataFrame(q.sendSync(query))
File "C:\Python38\lib\site-packages\qpython\qconnection.py", line 303, in sendSync
response = self.receive(data_only = False, **options)
File "C:\Python38\lib\site-packages\qpython\qconnection.py", line 380, in receive
result = self._reader.read(**self._options.union_dict(**options))
File "C:\Python38\lib\site-packages\qpython\qreader.py", line 138, in read
message = self.read_header(source)
File "C:\Python38\lib\site-packages\qpython\qreader.py", line 158, in read_header
header = self._read_bytes(8)
File "C:\Python38\lib\site-packages\qpython\qreader.py", line 388, in _read_bytes
data = self._stream.read(length)
File "C:\Python38\lib\socket.py", line 669, in readinto
return self._sock.recv_into(b)
socket.timeout: timed out
query = 'select lo:min price, hi:max price by sym from trade where date = 2007.02.28, corr <= 1'
【问题讨论】: