【问题标题】:Clickhouse. Problem using python module clickhouse_driver点击屋。使用 python 模块 clickhouse_driver 的问题
【发布时间】: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


【解决方案1】:

Django 使用 clickhouse_driver 不支持的多线程向 clickhouse 发送查询。这就是原因。

使用 SQLAlchemy 解决了我的问题。

【讨论】:

    猜你喜欢
    • 2020-11-10
    • 2019-11-10
    • 2020-01-20
    • 2012-11-14
    • 2015-09-13
    • 1970-01-01
    • 1970-01-01
    • 2015-03-31
    • 1970-01-01
    相关资源
    最近更新 更多