chdb 简单试用

通过python 模式包体验下chdb

参考使用

  • 安装依赖
pip install chdb
  • 简单代码
from chdb.session import Session
 
db = Session('./db')
db.query("CREATE DATABASE if not exists db")
db.query("USE db")
 
db.query("""
CREATE TABLE if not exists data (id UInt32, x UInt32)
ENGINE MergeTree ORDER BY id SAMPLE BY id
AS
SELECT number+1 AS id, randUniform(1, 100) AS x
FROM numbers(10000);
""")
 
query_sql = """
SELECT
  avg(x) as "avg",
  round(quantile(0.95)(x), 2) AS p95
FROM data
SAMPLE 0.1;
"""
 
res = db.query(query_sql, "PrettyCompactNoEscapes")
print(res, end="")
  • 效果

说明

clickhouse 官方有一个关于chdb 的介绍还是值得学习看看的,内部数据处理参考图

参考资料

https://doc.chdb.io/#/install
https://github.com/chdb-io/chdb
https://clickhouse.com/blog/welcome-chdb-to-clickhouse
https://docs.python.org/3/c-api/memoryview.html

posted on 2024-07-15 07:39  荣锋亮  阅读(10)  评论(0编辑  收藏  举报

导航