![](/img/trans.png)
[英]How to fetch data from Clickhouse in dicitionary/name-tuple using clickhouse-driver (python)?
[英]Export data from clickhouse
請建議使用python從clickhouse導出數據的最佳方法。
現在我正在使用此代碼,但有一個錯誤指出無法訪問 hotsname。
from clickhouse_driver import Client
client=Client(host='http://ipaddress',user='user',password='pass',port=8123)
print(client.execute('select * from table limit 5'))
有沒有其他方法可以做到這一點?
在您提供的代碼示例中,
from clickhouse_driver import Client
client=Client(host='http://ipaddress',user='user',password='pass',port=8123)
print(client.execute('select * from table limit 5'))
您輸入的http://ipaddress
不是有效的主機名,如果您將其更改為有效的主機名,它應該可以正常工作。
clickhouse-driver通過本機協議而不是 HTTP 與 ClickHouse 通信,因此:
我將依靠生成器函數execute-iter來流式傳輸導出數據:
from clickhouse_driver import Client
client = Client(host='localhost')
data = client.execute_iter('SELECT * FROM numbers(1 * 1000 * 1000)')
row_count = 0
for row in data:
# do smth per row
row_count += 1
print(f"Row count is {row_count}.")
# Row count is 1000000.
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.