前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >[895]Clickhouse

[895]Clickhouse

作者头像
周小董
发布2020-09-21 10:16:32
3.5K0
发布2020-09-21 10:16:32
举报
文章被收录于专栏:python前行者python前行者

一、简介

Yandex在2016年6月15日开源了一个数据分析的数据库,名字叫做ClickHouse,这对保守俄罗斯人来说是个特大事。更让人惊讶的是,这个列式存储数据库的跑分要超过很多流行的商业MPP数据库软件,例如Vertica。如果你没有听过Vertica,那你一定听过 Michael Stonebraker,2014年图灵奖的获得者,PostgreSQL和Ingres发明者(Sybase和SQL Server都是继承Ingres而来的), Paradigm4和SciDB的创办者。Michael Stonebraker于2005年创办Vertica公司,后来该公司被HP收购,HP Vertica成为MPP列式存储商业数据库的高性能代表,Facebook就购买了Vertica数据用于用户行为分析。简单的说,ClickHouse作为分析型数据库,有三大特点:一是跑分快,二是功能多,三是文艺范

官网地址:https://clickhouse.tech/ 官方文档:https://clickhouse.tech/docs/zh/single/

Python接口1

ClickHouse没有官方的Python接口,有个第三方的库,叫clickhouse-driver,GitHub地址是:mymarilyn/clickhouse-driver: ClickHouse Python Driver with native interface support 安装:

代码语言:javascript
复制
pip install clickhouse-driver

使用方法如下:

代码语言:javascript
复制
from clickhouse_driver import Client

client = Client(host='localhost', database='default', user='default', password='')
client.execute('SHOW DATABASES')

==========================================================
>>> from clickhouse_driver import connect
>>>
>>> conn = connect('clickhouse://localhost')
>>> cursor = conn.cursor()
>>>
>>> cursor.execute('SHOW TABLES')
>>> cursor.fetchall()
[('test',)]

Python接口2

代码语言:javascript
复制
pip install clickhouse-sqlalchemy==0.1.4 
pip install sqlalchemy==1.3.19

使用

代码语言:javascript
复制
# -*- coding:utf-8 -*-
from clickhouse_sqlalchemy import make_session
from sqlalchemy import create_engine


conf = {
    "user": "default",
    "password": "",
    "server_host": "47.104",
    "port": "8123",
    "db": "test"
}
connection = 'clickhouse://{user}:{password}@{server_host}:{port}/{db}'.format(**conf)
engine = create_engine(connection, pool_size=100, pool_recycle=3600, pool_timeout=20)


def get_session(engine):
    return make_session(engine)

def execute(sql):
    session = get_session(engine)
    cursor = session.execute(sql)
    try:
        fields = cursor._metadata.keys
        return [dict(zip(fields, item)) for item in cursor.fetchall()]
    finally:
        cursor.close()
        session.close()

query='SHOW TABLES'
result=execute(query)
print(result)

其它阅读

ClickHouse表引擎到底怎么选: https://developer.aliyun.com/article/762461 clickHouse可视化查询工具: https://www.cnblogs.com/treesoft/p/11963831.html Tabix: https://clickhouse.tech/docs/zh/interfaces/third-party/gui/ https://zhuanlan.zhihu.com/p/161383473

参考: https://blog.csdn.net/m0_37739193/article/details/79611560 https://blog.csdn.net/zhangpeterx/article/details/95060788 https://testerhome.com/topics/21135

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2020-09-18 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 一、简介
    • Python接口1
      • Python接口2
        • 其它阅读
        相关产品与服务
        云数据库 SQL Server
        腾讯云数据库 SQL Server (TencentDB for SQL Server)是业界最常用的商用数据库之一,对基于 Windows 架构的应用程序具有完美的支持。TencentDB for SQL Server 拥有微软正版授权,可持续为用户提供最新的功能,避免未授权使用软件的风险。具有即开即用、稳定可靠、安全运行、弹性扩缩等特点。
        领券
        问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档