我正在尝试使用python模块clickhouse\u驱动程序执行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
为什么我在第一个案例中出错
Django使用clickhouse\u驱动程序不支持的多线程方式向clickhouse发送查询。这就是原因
使用SQLAlchemy修复了我的问题
相关问题 更多 >
编程相关推荐