dbt Core CLI
$ dbt 官方出品 中风险dbt Core 用于编译模块化 SQL+Jinja 分析模型,并在 Snowflake、BigQuery、Postgres、DuckDB 等数仓上执行 DAG 转换与数据质量测试。支持 --output json 日志、dbt compile 离线渲染及 dbt ls 节点筛选。
brew install dbt dbt compile、dbt ls --output json 与 dbt test 是修改模型时必不可少的本地 CLI 闭环;dbt MCP 更侧重语义层与元数据查询。
Agent 友好度体检单
当前为静态评估(本机尚未安装或尚未运行探针)。可在本地运行 npm run data:probe 并提交 data/probes/ 升级为实测证据。
FCRS-1.0 六维评分拆解
支持 dbt ls --output json、--log-format json、--no-use-colors 及机器可读的 target/manifest.json / run_results.json 产物。
- Structured JSON artifacts (
manifest.json,run_results.json),ls --output json, and--log-format json
dbt compile 可在不触达数仓的情况下本地校验 Jinja/SQL,--select 可严格收敛执行范围;但未加筛选的 dbt run 可能触发全量 DAG 计算。
dbt compiledry-renders SQL;--selectscopes execution
Python 包分发,需按目标数仓额外安装对应适配器(如 dbt-postgres、dbt-snowflake、dbt-duckdb)。
- Requires
dbt-coreplus warehouse-specific adapter package
模块化 SQL 转换、血缘图谱与自动化数据测试的事实标准。
- Compiles, materializes, and tests SQL DAGs cleanly
由 dbt Labs 官方在 dbt-labs/dbt-core 仓库以 Apache-2.0 协议维护。
- Official
dbt-labs/dbt-corerepository
命令参数、节点选择语法与产物格式文档非常完善。
- Official docs at docs.getdbt.com/reference/dbt-commands
安全边界、鉴权与放权指南
数仓凭证配置在 ~/.dbt/profiles.yml 中,推荐通过 Jinja env_var() 从环境变量读取密钥。
dbt Core 基于 Apache-2.0 开源;实际在云数仓执行模型会产生相应的数仓计算费用。
# dbt CLI Agent Rules - Always run `dbt ls` and `dbt compile` before `dbt run` or `dbt build`. - Always scope execution with `--select <model>` (never run unscoped `dbt run` across full prod DAGs). - Pass `--log-format json --no-use-colors` when parsing run artifacts or `target/run_results.json`.
Agent 高频安全命令配方
只读查询(安全推荐)
dbt ls --select +orders --output json
不执行数仓查询即可输出上下游节点的 JSON 清单。
dbt compile --select orders --no-use-colors
将最终 SQL 渲染至 target/compiled/ 目录以安全检查语法与宏展开。
受控写入与预演
dbt build --select orders --log-format json
按 --select 范围物化单个模型并执行 Schema/数据断言,输出 JSON 日志。
核心优势
- +
dbt compile与dbt ls --output json可在零数仓费用下完成血缘与 SQL 校验。 - + 丰富的 JSON 构建产物(
target/manifest.json、target/run_results.json)便于 Agent 定位报错。 - + 支持搭配
dbt-duckdb在本地零成本跑通测试。
注意事项与踩坑点
- ! Python 环境启动与数仓适配器依赖树较重。
- ! 未加
--select限制的全量dbt run/dbt build可能在云数仓产生高额算力费用。