Skip to main content Switch to mobile version lakehouse-doctor 0.8.0 Zero-cluster offline SQL static auditor, column-level lineage analyzer, and AI Agent toolkit for Apache Doris, StarRocks, Apache Paimon, and Flink SQL.
pip install lakehouse-doctor Copy PIP instructions
面向 Apache Doris、StarRocks、Apache Paimon 与 Flink SQL 的离线 SQL 静态审计、字段级血缘分析、Query Profile 诊断、DQC 生成工具与 MCP 服务。
lakehouse-doctor 无需连接真实数据库集群,通过解析项目中的 CREATE TABLE 建表语句构建内存元数据目录(Catalog),在此基础上执行 Schema-Aware AST 静态检查、跨文件字段血缘影响面追踪与执行计划剖析。
catalog:从 Doris、StarRocks、Paimon 与 Flink SQL 建表及 ALTER TABLE 语句构建离线目录(字段类型、主/分区/分桶键与引擎属性),可选 --dsn 只读拉取 FE 缺失 DDL。
audit:兼容调度宏变量(${biz_date}、#{dt}、{{ ds }}、{{ ref(...) }})与 GBK/UTF-8 文件,运行语法/DDL/DML 静态规则(LH001、LH101–LH212),支持行内豁免注释、归一化健康评分与文本/JSON/SARIF 输出(可选 --explain 做 FE 只读验证 LE001)。
lineage / impact:穿透视图、CTE、SELECT * 与 UNION ALL 构建表级和字段级血缘(标注 DIRECT/DERIVED/FILTER),支持 --upstream 逆向溯源,导出 Mermaid、JSON 或交互式 HTML。
profile:解析 Doris(2.x/3.x/4.x 与传统节点)及 StarRocks Query Profile(LP001–LP009),定位倾斜、阻塞、错位 Join 与内存/Spill 问题,支持 --diff 前后对比、--format ai-json 压缩与 HTML 火焰图。
dqc:结合主键约束与血缘依赖,一键生成新鲜度、主键唯一性、非空、非负指标及上下游行数对账 SQL。
mcp & skills/:内置标准库 stdio MCP Server(lh-doctor mcp)与开放标准 Agent Skills。
离线前提:类型检查(LH203/LH211)、列存在性(LH210)与分区审计(LH202)依赖仓库内已包含对应建表 DDL(或 --dsn 只读拉取);缺少 DDL 时不会瞎报,未命中明细均可在 coverage.missing_tables / ambiguous_tables 中核对。
近似兼容与模板展开:对 Flink/Paimon 方言回退、调度宏占位与 Jinja 条件首分支展开属于静态近似(会在 coverage.parsed_normalized 标出),涉及复杂水位线/窗口语义或实际分区裁剪仍应配合 --explain 或真实引擎校验。
渐进落地:建议新仓库先用 lh-doctor audit ./sql --fail-on none 跑报告模式观察基线,再在明确规则集下接入 PR 门禁。
方式一:发给你的 AI Agent 自动装好(推荐)
直接复制下面这段话发给 Claude Code / Codex / WorkBuddy / Qoder / DeepSeek Harness 等支持 MCP 和 Skills 的编程助手,让它直接从 PyPI 安装、配好 MCP 并跑通首轮体检:
请帮我把 lakehouse-doctor 接入到当前环境(仓库地址:https://github.com/tolgerx/lakehouse-doctor): 1. 直接从 PyPI 安装(`pip install lakehouse-doctor`,如需 `--dsn` 只读连 FE 则装 `pip install "lakehouse-doctor[online]"`;也可使用 `uvx lakehouse-doctor` 免安装运行); 2. 将 `lh-doctor mcp`(或 `uvx lakehouse-doctor mcp`)配进我的 MCP Server 配置,如需使用内置 `skills/*` 可从仓库拉取并关联到 Skills 目录; 3. 完成后调用 `lh-doctor audit`(或 MCP 工具 `audit_sql`)对我当前项目的 SQL 目录做一次检查并汇报结果。 方式二:命令行安装
# 推荐直接从 PyPI 安装 pip install lakehouse-doctor # 如需启用只读 FE 建表补全与在线 EXPLAIN(--dsn / --explain) pip install "lakehouse-doctor[online]" # 或使用 uvx 免安装运行(MCP 可直接配 command: "uvx", args: ["lakehouse-doctor", "mcp"]) uvx lakehouse-doctor --help 如需运行仓库内置的 4 层 Paimon + Doris 示例项目(examples/ecommerce_lakehouse)与示例 Profile(examples/profiles):
git clone https://github.com/tolgerx/lakehouse-doctor.git cd lakehouse-doctor lh-doctor catalog examples/ecommerce_lakehouse lh-doctor audit examples/ecommerce_lakehouse lh-doctor impact examples/ecommerce_lakehouse --column ods_orders.pay_amount lh-doctor impact examples/ecommerce_lakehouse --column ads_gmv_dashboard.total_gmv --upstream lh-doctor lineage examples/ecommerce_lakehouse --format html --output lineage.html lh-doctor profile examples/profiles/doris_skewed_broadcast_join.txt lh-doctor profile examples/profiles/doris_skewed_broadcast_join.txt --diff examples/profiles/doris_skewed_broadcast_join_tuned.txt lh-doctor dqc examples/ecommerce_lakehouse --table dwd_order_detail 输出示例
lh-doctor audit examples/ecommerce_lakehouse
Lakehouse Doctor Audit (files: 8, catalog tables: 5) Summary: 3 CRITICAL | 9 WARNING | 1 INFO Health Score: 8/100 (Grade F) [CRITICAL] LH203 dml/01_dwd_load_order_detail.sql:13 - Implicit type cast in JOIN/WHERE comparison SQL: ON o.user_id = u.id Why: Implicit cast in `o.user_id = u.id`: `ods_orders.user_id` (VARCHAR(64)) vs `ods_users.id` (BIGINT). Fix: Align column types in DDL or explicitly `CAST(o.user_id AS BIGINT)` before joining. [CRITICAL] LH201 dml/01_dwd_load_order_detail.sql:15 - Partition pruning disabled by function wrap SQL: WHERE DATE_FORMAT(o.dt, '%Y-%m') = '2026-11' Why: Partition column `o.dt` is wrapped in `TIME_TO_STR(CAST(o.dt AS TIMESTAMP), '%Y-%m')`, disabling partition pruning. Fix: Rewrite using a half-open range predicate directly on `o.dt` (e.g. `o.dt >= '2026-11-01' AND o.dt < '2026-12-01'`). [CRITICAL] LH202 dml/03_ads_gmv_report.sql:4 - Missing partition filter on partitioned table SQL: SELECT * FROM dws_user_order_1d Why: Partitioned table `dws_user_order_1d` (partitioned by `dt`) is scanned without a partition predicate. Fix: Add a filter on `dt` in `WHERE` (or `JOIN ... ON` for outer-joined tables). lh-doctor impact examples/ecommerce_lakehouse --column ods_orders.pay_amount
Impact Analysis (downstream): ods_orders.pay_amount -> 3 affected target(s) [Hop 1 | DWD] dwd_order_detail.pay_amount [DIRECT] Path: ods_orders.pay_amount -> dwd_order_detail.pay_amount [Hop 2 | DWS] dws_user_order_1d.total_gmv [DERIVED] Path: ods_orders.pay_amount -> dwd_order_detail.pay_amount -> dws_user_order_1d.total_gmv [Hop 3 | ADS] ads_gmv_dashboard.total_gmv [DERIVED] Path: ods_orders.pay_amount -> dwd_order_detail.pay_amount -> dws_user_order_1d.total_gmv -> ads_gmv_dashboard.total_gmv lh-doctor profile examples/profiles/doris_skewed_broadcast_join.txt
Lakehouse Doctor Query Profile (engine: DORIS, total: 14.82s, operators: 5, findings: 6) Query ID: 9f4c2b8a-7e11-4d3a-9c52-88a1e72b1104 [CRITICAL] LP001 Fragment 1 / HASH_JOIN_OPERATOR (id=4) - Severe instance data skew Why: Operator `HASH_JOIN_OPERATOR (id=4)` exhibits 7.9x time skew (max=9820ms vs avg=1240ms) and 8.7x row skew. [CRITICAL] LP002 Fragment 1 / HASH_JOIN_OPERATOR (id=4) - Dominant execution bottleneck operator Why: Operator `HASH_JOIN_OPERATOR (id=4)` accounts for 64.8% of operator max time (max=9820ms). [CRITICAL] LP004 Fragment 1 / HASH_JOIN_OPERATOR (id=4) - Heavy BROADCAST join memory/fan-out risk Why: BROADCAST join `HASH_JOIN_OPERATOR (id=4)` reached 2.85 GB peak memory and processed 84.5M probe/read rows. lh-doctor dqc examples/ecommerce_lakehouse --table dwd_order_detail
SELECT 'DQC_PK_UNIQUE_DWD_ORDER_DETAIL' AS check_id, 'dwd_order_detail' AS table_name, COUNT(*) - COUNT(DISTINCT CONCAT_WS('#', order_id, dt)) AS metric_value, CASE WHEN COUNT(*) = COUNT(DISTINCT CONCAT_WS('#', order_id, dt)) THEN 'PASS' ELSE 'FAIL' END AS status FROM dwd_order_detail WHERE dt = '${biz_date}'; 规则清单
GitHub PR 自动门禁:复制 .github/workflows/sql-guard-template.yml 即可在 PR 中上传 SARIF 扫描结果并自动评论违规 SQL。
项目级配置与行内豁免:运行 lh-doctor init 生成 .lh-doctor.toml(示例见 .lh-doctor.toml.example),可自定义规则开关 ignore、严重级别覆盖、max_buckets、分区列名与目录排除 exclude;同时支持 SQL 行内豁免注释(-- lh-doctor: disable=LH203、disable-file、disable-next-line、-- noqa)。
内置 Agent Skills (skills/) 与斜杠命令 (.claude/commands/):包含 doris-starrocks-modeling、paimon-flink-lakehouse、lakehouse-sql-and-profile-tuning、lakehouse-lineage-and-dqc 及 /lh-audit、/lh-profile、/lh-impact。
MCP 工具清单 (lh-doctor mcp):参考 examples/mcp_config.json,暴露 audit_sql、inspect_catalog、trace_impact、analyze_profile、compare_profiles、generate_dqc。
Released: Dec 2, 2026
Both files in this release have provenance metadata.
View provenance details
Development Status 3 - Alpha
Intended Audience Developers
License OSI Approved :: MIT License
Programming Language Python :: 3
Software Development :: Quality Assurance
Release files for lakehouse-doctor 0.8.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
Built distribution (wheel)
Total release size: 218.4 kB
Release files / lakehouse_doctor-0.8.0.tar.gz
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 2, 2026.
Release files / lakehouse_doctor-0.8.0-py3-none-any.whl
Security for lakehouse-doctor 0.8.0
Both files in this release have been uploaded with provenance metadata.
With provenance lakehouse_doctor-0.8.0.tar.gz Dec 2, 2026
Attestation for lakehouse_doctor-0.8.0.tar.gz
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.
Release history Release notifications | RSS feed
Dec 2, 2026 2 release files Full provenance
Dec 1, 2026 2 release files Full provenance
"PyPI", "Python Package Index", and the blocks logos are registered trademarks of the Python Software Foundation.
© 2026 Python Software Foundation
Deployed from 147871d











