chdb-datastore

作者: clickhouse

DataStore 是一個惰性、基於 ClickHouse 的 pandas 替代方案。您現有的 pandas 程式碼無需修改即可運作——但操作會編譯為最佳化的 SQL,並僅在需要結果時(例如 print()、len()、迭代)才執行。

npx skills add https://github.com/clickhouse/agent-skills --skill chdb-datastore

chdb DataStore — It's Just Faster Pandas

The Key Insight

# Change this:
import pandas as pd
# To this:
import chdb.datastore as pd
# Everything else stays the same.

DataStore is a lazy, ClickHouse-backed pandas replacement. Your existing pandas code works unchanged — but operations compile to optimized SQL and execute only when results are needed (e.g., print(), len(), iteration).

pip install chdb

Decision Tree: Pick the Right Approach

1. "I have a file/database and want to analyze it with pandas"
   → DataStore.from_file() / from_mysql() / from_s3() etc.
   → See references/connectors.md

2. "I need to join data from different sources"
   → Create DataStores from each source, use .join()
   → See examples/examples.md #3-5

3. "My pandas code is too slow"
   → import chdb.datastore as pd — change one line, keep the rest

4. "I need raw SQL queries"
   → Use the chdb-sql skill instead

Connect to Any Data Source — One Pattern

from datastore import DataStore

# Local file (auto-detects .parquet, .csv, .json, .arrow, .orc, .avro, .tsv, .xml)
ds = DataStore.from_file("sales.parquet")

# Database
ds = DataStore.from_mysql(host="db:3306", database="shop", table="orders", user="root", password="pass")

# Cloud storage
ds = DataStore.from_s3("s3://bucket/data.parquet", nosign=True)

# URI shorthand — auto-detects source type
ds = DataStore.uri("mysql://root:pass@db:3306/shop/orders")

All 16+ sources and URI schemes → connectors.md

After Connecting — Full Pandas API

result = ds[ds["age"] > 25]                                          # filter
result = ds[["name", "city"]]                                        # select columns
result = ds.sort_values("revenue", ascending=False)                  # sort
result = ds.groupby("dept")["salary"].mean()                         # groupby
result = ds.assign(margin=lambda x: x["profit"] / x["revenue"])     # computed column
ds["name"].str.upper()                                               # string accessor
ds["date"].dt.year                                                   # datetime accessor
result = ds1.join(ds2, on="id")                                      # join
result = ds.head(10)                                                 # preview
print(ds.to_sql())                                                   # see generated SQL

209 DataFrame methods supported. Full API → api-reference.md

Cross-Source Join — The Killer Feature

from datastore import DataStore

customers = DataStore.from_mysql(host="db:3306", database="crm", table="customers", user="root", password="pass")
orders = DataStore.from_file("orders.parquet")

result = (orders
    .join(customers, left_on="customer_id", right_on="id")
    .groupby("country")
    .agg({"amount": "sum", "rating": "mean"})
    .sort_values("sum", ascending=False))
print(result)

More join examples → examples.md

Writing Data

source = DataStore.from_mysql(host="db:3306", database="shop", table="orders", user="root", password="pass")
target = DataStore("file", path="summary.parquet", format="Parquet")

target.insert_into("category", "total", "count").select_from(
    source.groupby("category").select("category", "sum(amount) AS total", "count() AS count")
).execute()

Troubleshooting

ProblemFix
ImportError: No module named 'chdb'pip install chdb
ImportError: cannot import 'DataStore'Use from datastore import DataStore or from chdb.datastore import DataStore
Database connection timeoutInclude port in host: host="db:3306" not host="db"
Join returns empty resultCheck key types match (both int or both string); use .to_sql() to inspect
Unexpected resultsCall ds.to_sql() to see the generated SQL and debug
Environment checkRun python scripts/verify_install.py (from skill directory)

References

Note: This skill teaches how to use chdb DataStore. For raw SQL queries, use the chdb-sql skill. For contributing to chdb source code, see CLAUDE.md in the project root.

來自 clickhouse 的更多技能

chdb-sql
clickhouse
直接在Python中執行ClickHouse SQL — 無需伺服器。使用完整的ClickHouse SQL功能查詢本地檔案、遠端資料庫和雲端儲存。
official
clickhouse-architecture-advisor
clickhouse
在設計 ClickHouse 架構、選擇資料導入或建模模式,或將最佳實踐轉化為特定工作負載的系統時,必須使用此工具。
official
clickhouse-best-practices
clickhouse
我们要求翻译一段文本,目标语言是繁体中文。文本内容是关于ClickHouse最佳实践的规则,包括模式设计、查询优化和数据摄取策略。需要保留名称"clickhouse-best-practices"(但名称不在<text>内,所以不翻译)。注意不要添加额外内容,只翻译<text>内的文字。 翻译时注意专业术语:schema design -> 模式設計,query optimization -> 查詢優化,data ingestion strategy -> 數據攝取策略,primary key -> 主鍵,data type selection -> 數據類型選擇,immutable design decisions -> 不可變設計決策,JOIN -> JOIN(保留),insert batching -> 插入批次處理,mutation avoidance -> 避免突變,columnar storage -> 列式存儲,sparse index mechanics -> 稀疏索引機制,structured review procedures -> 結構化審查程序。 注意繁体中文用词:规则、组织、涵盖、关键、标记、提供等。 文本末尾有"for...",但原文是"for..."后面没有完整
official
clickhousectl-cloud-deploy
clickhouse
當用戶想要將ClickHouse部署到雲端、上線生產環境、使用ClickHouse Cloud、託管受管理的ClickHouse服務,或從本地遷移時使用。
official
clickhousectl-local-dev
clickhouse
當用戶想要使用 ClickHouse 構建應用程式、設置本地 ClickHouse 開發環境、安裝 ClickHouse、創建本地伺服器時使用,
official
setup
clickhouse
引導用戶設定與此插件捆綁的 ClickHouse MCP 伺服器連線。當用戶首次安裝插件或遇到問題時使用…
official
clickhouse-js-node-coding
clickhouse
參考資料:https://clickhouse.com/docs/integrations/javascript
official
clickhouse-js-node-troubleshooting
clickhouse
參考資料:https://clickhouse.com/docs/integrations/javascript
official