【发布时间】:2021-08-30 12:26:37
【问题描述】:
我正在尝试使用 python 模块 clickhouse_driver 对 clickhouse 执行选择查询:
from django.conf import settings
from clickhouse_driver import Client
CLICKHOUSE_SETTINGS = settings.CLICKHOUSE
clickhouse_client = Client(**CLICKHOUSE_SETTINGS)
def get_data_1():
data_1 = clickhouse_client.execute("SELECT * from table_1 ")
return data_1
def get_data_2():
data_1 = clickhouse_client.execute("SELECT * from table_2 ")
return data_1
def get_data_3():
data_1 = clickhouse_client.execute("SELECT * from table_3 ")
return data_1
def get_data_4():
data_1 = clickhouse_client.execute("SELECT * from table_4 ")
return data_1
并得到错误:
File "/usr/local/lib/python3.8/site-packages/clickhouse_driver/client.py", line 248, in execute
rv = self.process_ordinary_query(
File "/usr/local/lib/python3.8/site-packages/clickhouse_driver/client.py", line 446, in process_ordinary_query
return self.receive_result(with_column_types=with_column_types,
File "/usr/local/lib/python3.8/site-packages/clickhouse_driver/client.py", line 113, in receive_result
return result.get_result()
File "/usr/local/lib/python3.8/site-packages/clickhouse_driver/result.py", line 50, in get_result
for packet in self.packet_generator:
File "/usr/local/lib/python3.8/site-packages/clickhouse_driver/client.py", line 129, in packet_generator
packet = self.receive_packet()
File "/usr/local/lib/python3.8/site-packages/clickhouse_driver/client.py", line 143, in receive_packet
packet = self.connection.receive_packet()
File "/usr/local/lib/python3.8/site-packages/clickhouse_driver/connection.py", line 490, in receive_packet
raise errors.UnknownPacketFromServerError(
clickhouse_driver.errors.UnknownPacketFromServerError: Code: 100. Unknown packet 4 from server None:None
在这个示例中,我对所有查询都使用了一个客户端实例。但是当我为每个查询创建客户端实例时,一切都很好。
from django.conf import settings
from clickhouse_driver import Client
CLICKHOUSE_SETTINGS = settings.CLICKHOUSE
def get_data_1():
clickhouse_client = Client(**CLICKHOUSE_SETTINGS)
data_1 = clickhouse_client.execute("SELECT * from table_1 ")
return data_1
def get_data_2():
clickhouse_client = Client(**CLICKHOUSE_SETTINGS)
data_1 = clickhouse_client.execute("SELECT * from table_2 ")
return data_1
def get_data_3():
clickhouse_client = Client(**CLICKHOUSE_SETTINGS)
data_1 = clickhouse_client.execute("SELECT * from table_3 ")
return data_1
def get_data_4():
clickhouse_client = Client(**CLICKHOUSE_SETTINGS)
data_1 = clickhouse_client.execute("SELECT * from table_4 ")
return data_1
为什么我在第一种情况下出错了?
【问题讨论】:
-
所有这些方法都一个一个调用吗?不是同时(不是异步)?
标签: python clickhouse