Loading...
Loading...
Compare original and translation side by side
../analyzing-data/scripts/analyzing-datascripts/cli.pycd../analyzing-data/../analyzing-data/scripts/analyzing-datascripts/cli.py../analyzing-data/.astro/warehouse.md.astro/warehouse.mdcat ~/.astro/agents/warehouse.ymldatabases: [HQ, ANALYTICS, RAW]cat ~/.astro/agents/warehouse.ymldatabases: [HQ, ANALYTICS, RAW]Task(
subagent_type="Explore",
prompt="""
Search for data model documentation in the codebase:
1. dbt models: **/models/**/*.yml, **/schema.yml
- Extract table descriptions, column descriptions
- Note primary keys and tests
2. Gusty/declarative SQL: **/dags/**/*.sql with YAML frontmatter
- Parse frontmatter for: description, primary_key, tests
- Note schema mappings
3. AGENTS.md or CLAUDE.md files with data layer documentation
Return a mapping of:
table_name -> {description, primary_key, important_columns, layer}
"""
)Task(
subagent_type="Explore",
prompt="""
在代码库中搜索数据模型文档:
1. dbt模型:**/models/**/*.yml, **/schema.yml
- 提取表描述、列描述
- 记录主键和测试规则
2. Gusty/声明式SQL:**/dags/**/*.sql文件中的YAML前置内容
- 解析前置内容中的:描述、主键、测试规则
- 记录模式映射关系
3. 包含数据层文档的AGENTS.md或CLAUDE.md文件
返回以下格式的映射关系:
table_name -> {description, primary_key, important_columns, layer}
"""
)For each database in configured_databases:
Task(
subagent_type="general-purpose",
prompt="""
Discover all metadata for database {DATABASE}.
Use the CLI to run SQL queries:
# Scripts are relative to ../analyzing-data/
uv run scripts/cli.py exec "df = run_sql('...')"
uv run scripts/cli.py exec "print(df)"
1. Query schemas:
SELECT SCHEMA_NAME FROM {DATABASE}.INFORMATION_SCHEMA.SCHEMATA
2. Query tables with row counts:
SELECT TABLE_SCHEMA, TABLE_NAME, ROW_COUNT, COMMENT
FROM {DATABASE}.INFORMATION_SCHEMA.TABLES
ORDER BY TABLE_SCHEMA, TABLE_NAME
3. For important schemas (MODEL_*, METRICS_*, MART_*), query columns:
SELECT TABLE_NAME, COLUMN_NAME, DATA_TYPE, COMMENT
FROM {DATABASE}.INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_SCHEMA = 'X'
Return a structured summary:
- Database name
- List of schemas with table counts
- For each table: name, row_count, key columns
- Flag any tables with >100M rows as "large"
"""
)For each database in configured_databases:
Task(
subagent_type="general-purpose",
prompt="""
发现数据库{DATABASE}的所有元数据。
使用CLI执行SQL查询:
# 脚本路径相对于../analyzing-data/
uv run scripts/cli.py exec "df = run_sql('...')"
uv run scripts/cli.py exec "print(df)"
1. 查询模式:
SELECT SCHEMA_NAME FROM {DATABASE}.INFORMATION_SCHEMA.SCHEMATA
2. 查询带行数的表:
SELECT TABLE_SCHEMA, TABLE_NAME, ROW_COUNT, COMMENT
FROM {DATABASE}.INFORMATION_SCHEMA.TABLES
ORDER BY TABLE_SCHEMA, TABLE_NAME
3. 对于重要模式(MODEL_*, METRICS_*, MART_*),查询列信息:
SELECT TABLE_NAME, COLUMN_NAME, DATA_TYPE, COMMENT
FROM {DATABASE}.INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_SCHEMA = 'X'
返回结构化摘要:
- 数据库名称
- 包含表数量的模式列表
- 每个表的:名称、行数、关键字段
- 将行数>1亿的表标记为“大表”
"""
)uv run cli.py exec "df = run_sql('''
SELECT DISTINCT column_name, COUNT(*) as occurrences
FROM table
WHERE column_name IS NOT NULL
GROUP BY column_name
ORDER BY occurrences DESC
LIMIT 50
''')"
uv run cli.py exec "print(df)"Export*uv run cli.py exec "df = run_sql('''
SELECT DISTINCT column_name, COUNT(*) as occurrences
FROM table
WHERE column_name IS NOT NULL
GROUP BY column_name
ORDER BY occurrences DESC
LIMIT 50
''')"
uv run cli.py exec "print(df)"Export*.astro/warehouse.md~/.astro/agents/warehouse.md--global.astro/warehouse.md~/.astro/agents/warehouse.md--globalundefinedundefinedGenerated byon {DATE}. Edit freely to add business context./data:warehouse-init
由于{DATE}生成。可自由编辑以添加业务上下文。/data:warehouse-init
| Concept | Table | Key Column | Date Column |
|---|---|---|---|
| customers | HQ.MODEL_ASTRO.ORGANIZATIONS | ORG_ID | CREATED_AT |
| 概念 | 表 | 关键字段 | 日期字段 |
|---|---|---|---|
| customers | HQ.MODEL_ASTRO.ORGANIZATIONS | ORG_ID | CREATED_AT |
| Table | Column | Value Families |
|---|---|---|
| {TABLE} | {COLUMN} | |
| 表 | 列 | 值族 |
|---|---|---|
| {TABLE} | {COLUMN} | |
reportingmart_*metric_*model_*IN_*| Layer | Prefix | Purpose |
|---|---|---|
| Reporting | | Dashboard-optimized |
| Mart | | Combined analytics |
| Metric | | KPIs at various grains |
| Model | | Cleansed sources of truth |
| Raw | | Source data - avoid |
reportingmart_*metric_*model_*IN_*| 层级 | 前缀 | 用途 |
|---|---|---|
| 报表层 | | 针对仪表板优化 |
| 数据集市 | | 组合分析 |
| 指标层 | | 多粒度KPI |
| 模型层 | | 清洗后的可信数据源 |
| 原始层 | | 源数据 - 避免直接使用 |
| Column | Type | Description |
|---|---|---|
| COL1 | VARCHAR | {from code or inferred} |
| 列 | 类型 | 描述 |
|---|---|---|
| COL1 | VARCHAR | {来自代码或推断的描述} |
{Inferred relationships based on column names like *_ID}undefined{根据*_ID等列名推断的关系}undefined| Option | Effect |
|---|---|
| Generate .astro/warehouse.md |
| Regenerate, preserving user edits |
| Only discover specific database |
| Write to ~/.astro/agents/ instead |
| 选项 | 作用 |
|---|---|
| 生成.astro/warehouse.md |
| 重新生成,保留用户编辑内容 |
| 仅发现指定数据库 |
| 写入到~/.astro/agents/目录 |
undefinedundefinedundefinedundefinedWould you like to add the Quick Reference table to your CLAUDE.md file?This ensures the schema mappings are always in context for data queries, improving accuracy from ~25% to ~100% for complex queries.Options:
- Yes, add to CLAUDE.md (Recommended) - Append Quick Reference section
- No, skip - Use warehouse.md and cache only
.claude/CLAUDE.mdCLAUDE.md.claude/CLAUDE.mdundefined是否要将快速参考表添加到您的CLAUDE.md文件中?这将确保模式映射始终在数据查询的上下文中,将复杂查询的准确率从约25%提升至约100%。选项:
- 是,添加到CLAUDE.md(推荐) - 追加快速参考章节
- 否,跳过 - 仅使用warehouse.md和缓存
.claude/CLAUDE.mdCLAUDE.md.claude/CLAUDE.mdundefined| Concept | Table | Key Column | Date Column |
|---|---|---|---|
| {rows from warehouse.md Quick Reference} |
Auto-generated by. Run/data:warehouse-initto update./data:warehouse-init --refresh
**If yes:** Append the Quick Reference section to `.claude/CLAUDE.md` or `CLAUDE.md`.| 概念 | 表 | 关键字段 | 日期字段 |
|---|---|---|---|
| {来自warehouse.md快速参考的行} |
由自动生成。运行/data:warehouse-init进行更新。/data:warehouse-init --refresh
**如果用户选择是:** 将快速参考章节追加到`.claude/CLAUDE.md`或`CLAUDE.md`中。Generated .astro/warehouse.md
Summary:
- {N} databases, {N} schemas, {N} tables
- {N} tables enriched with code descriptions
- {N} concepts cached for instant lookup
Next steps:
1. Edit .astro/warehouse.md to add business context
2. Commit to version control
3. Run /data:warehouse-init --refresh when schema changes已生成.astro/warehouse.md
摘要:
- {N}个数据库,{N}个模式,{N}张表
- {N}张表已补充来自代码的描述
- {N}个概念已缓存,可即时查询
后续步骤:
1. 编辑.astro/warehouse.md以添加业务上下文
2. 提交到版本控制系统
3. 当模式变更时运行/data:warehouse-init --refresh--refresh<!-- ... --><!-- REMOVED -->--refresh<!-- ... --><!-- REMOVED -->/data:warehouse-init --refresh/data:warehouse-init --refreshundefinedundefinedundefinedundefined| Pattern | Source | What We Extract |
|---|---|---|
| dbt | table/column descriptions, tests |
| gusty | YAML frontmatter (description, primary_key) |
| docs | data layer hierarchy, conventions |
| docs | business context |
| 模式 | 来源 | 提取内容 |
|---|---|---|
| dbt | 表/列描述、测试规则 |
| gusty | YAML前置内容(描述、主键) |
| 文档 | 数据层层级、约定 |
| 文档 | 业务上下文 |
User: /data:warehouse-init
Agent:
→ Reading warehouse configuration...
→ Found 1 warehouse with databases: HQ, PRODUCT
→ Searching codebase for data documentation...
Found: AGENTS.md with data layer hierarchy
Found: 45 SQL files with YAML frontmatter in dags/declarative/
→ Launching parallel warehouse discovery...
[Database: HQ] Discovering schemas...
[Database: PRODUCT] Discovering schemas...
→ HQ: Found 29 schemas, 401 tables
→ PRODUCT: Found 1 schema, 0 tables
→ Merging warehouse metadata with code context...
Enriched 45 tables with descriptions from code
→ Generated .astro/warehouse.md
Summary:
- 2 databases
- 30 schemas
- 401 tables
- 45 tables enriched with code descriptions
- 8 large tables flagged (>100M rows)
Next steps:
1. Review .astro/warehouse.md
2. Add concept mappings to Quick Reference
3. Commit to version control
4. Run /data:warehouse-init --refresh when schema changes用户:/data:warehouse-init
代理:
→ 读取数据仓库配置...
→ 找到1个数据仓库,包含数据库:HQ、PRODUCT
→ 在代码库中搜索数据文档...
找到:包含数据层层级的AGENTS.md
找到:dags/declarative/目录下45个带YAML前置内容的SQL文件
→ 启动并行数据仓库发现...
[数据库:HQ] 正在发现模式...
[数据库:PRODUCT] 正在发现模式...
→ HQ:找到29个模式,401张表
→ PRODUCT:找到1个模式,0张表
→ 整合数据仓库元数据与代码上下文...
为45张表补充了来自代码的描述
→ 生成.astro/warehouse.md
摘要:
- 2个数据库
- 30个模式
- 401张表
- 45张表已补充代码中的描述
- 标记了8张大表(行数>1亿)
后续步骤:
1. 查看.astro/warehouse.md
2. 在快速参考中添加概念映射
3. 提交到版本控制系统
4. 当模式变更时运行/data:warehouse-init --refresh