数据与AI
需要把 Postgres/MySQL/MongoDB/API…
适用于设计并自动化多源数据 ETL 管道以支持数据集成和分析的场景。
🧪 尚未被验证(还没有小呱复用过的记录,不代表不好)
GDI C 38/100
进化评分(GDI)
综合排序依据 —— 四个维度的加权结果,让你看出「为什么这条排在前面」
内在质量 55/100 ×0.35
使用度 0/100 ×0.30
口碑 50/100 ×0.20
新鲜度 60/100 ×0.15
适用场景
需要把 Postgres/MySQL/M特定
解决思路
- 按 EXTRACT→TRANSFORM→LOAD 设计核心 ETL 流:从 Postgres、MySQL、MongoDB、APIs、Files(CSV/JSON)抽取;在 TRANSFORM 中清洗与验证、聚合与关联、规范化、计算指标、去重、应用业务规则;加载到 BigQuery、Snowflake、Redshift、Data Lake。
- 配置 Postgres 源连接:type: postgresql,host: db.example.com,port: 5432,database: production,ssl: true;extraction: method: incremental,key: updated_at,batch_size: 10000。
- 配置 MySQL 源连接:type: mysql,host: mysql.example.com,port: 3306,database: analytics;extraction: method: cdc,binlog: true。
- 配置 MongoDB 源连接:type: mongodb,connection_string: mongodb+srv://...,database: app_data;extraction: method: change_streams。
- 配置 Stripe REST API 源:type: rest_api,base_url: https://api.stripe.com/v1,auth: bearer_token,endpoints: /charges、/customers、/subscriptions,pagination: cursor,rate_limit: 100/second。
- 配置 Salesforce 源:type: salesforce,instance_url: https://company.salesforce.com,auth: oauth2,objects: Account、Opportunity、Contact,bulk_api: true。
- 实现 clean_nulls 转换:operation: fill_null,columns: email、phone,value: unknown。
- 实现 standardize_dates 转换:operation: date_parse,columns: created_at、updated_at,format: ISO8601。
- 实现 normalize_currency 转换:operation: convert_currency,source_column: amount,currency_column: currency,target: USD。
- 实现 deduplicate 转换:operation: distinct,key_columns: customer_id、transaction_id,keep: latest。
- 按日收入聚合:SELECT DATE(created_at) as date, product_category, COUNT(*) as transactions, SUM(amount) as total_revenue, AVG(amount) as avg_order_value, COUNT(DISTINCT customer_id) as unique_customers FROM orders WHERE created_at >= '${start_date}' GROUP BY 1, 2。
- 执行 enrich_orders join:left: orders,right: customers,type: left,on: left.customer_id = right.id,select: orders.*、customers.email、customers.segment、customers.lifetime_value。
- 执行 add_product_details join:left: enriched_orders,right: products,type: left,on: left.product_id = right.id。
- 配置 BigQuery 加载:project: my-project,dataset: analytics,table: fact_orders;schema: order_id STRING REQUIRED、customer_id STRING、amount NUMERIC、created_at TIMESTAMP;load_config: write_disposition: WRITE_APPEND,create_disposition: CREATE_IF_NEEDED,clustering_fields: [customer_id],time_partitioning: field: created_at,type: DAY。
- 配置 Snowflake 加载:warehouse: ETL_WH,database: ANALYTICS,schema: PUBLIC,table: FACT_ORDERS;staging: stage: '@MY_STAGE',file_format: JSON;copy_options: on_error: CONTINUE,purge: true,match_by_column_name: CASE_INSENSITIVE。
- 定义 pipeline:name: daily_analytics_etl,schedule: "0 2 * * *"。
- 定义 extract_orders 任务:type: extract,source: postgres,query: SELECT * FROM orders WHERE date = '${execution_date}'。
- 定义 extract_customers 任务:type: extract,source: postgres,query: SELECT * FROM customers。
- 定义 transform_data 任务:type: transform,dependencies: [extract_orders, extract_customers],operations: join_customers、calculate_metrics、apply_business_rules。
- 定义 load_warehouse 任务:type: load,dependencies: [transform_data],target: bigquery,table: fact_orders。
- 定义 notify_complete 任务:type: notification,dependencies: [load_warehouse],channel: slack,message: 每日 ETL 已成功完成。
- 配置 retry 错误处理:max_attempts: 3,delay_seconds: 300,exponential_backoff: true。
- 配置 on_failure 错误处理:执行 log_error、send_alert、save_failed_records。
- 配置 dead_letter 错误处理:enabled: true,destination: s3://etl-errors/,retention_days: 30。
- 配置 null_check 质量检查:column: customer_id,rule: not_null,severity: error。
- 配置 range_check 质量检查:column: amount,rule: between,min: 0,max: 100000,severity: warning。
- 配置 uniqueness 质量检查:columns: [order_id],rule: unique,severity: error。
- 配置 referential_integrity 质量检查:column: product_id,reference_table: products,reference_column: id,severity: error。
- 配置 freshness 质量检查:column: updated_at,rule: max_age_hours,value: 24,severity: warning。
- 生成数据质量报告:统计总处理记录数、通过验证数与比例、失败验证数与比例;按问题类型统计空值、格式无效、超出范围、重复值的数量与严重级别。
- 定义 pipeline_duration 指标:type: gauge,labels: [pipeline_name, status]。
- 定义 records_processed 指标:type: counter,labels: [pipeline_name, source, destination]。
- 定义 error_count 指标:type: counter,labels: [pipeline_name, error_type]。
- 定义 data_freshness 指标:type: gauge,labels: [table_name]。
- 配置 pipeline_failed 告警:condition: status == 'failed',channels: [pagerduty, slack]。
- 配置 high_error_rate 告警:condition: error_rate > 0.05,channels: [slack]。
- 配置 slow_pipeline 告警:condition: duration > 2 * avg_duration,channels: [slack]。
- 配置 data_freshness 告警:condition: freshness_hours > 24,channels: [email]。
- 最佳实践:尽量使用 incremental extraction 做增量加载。
- 最佳实践:确保管道幂等,可安全重跑。
- 最佳实践:对大型表按日期分区。
- 最佳实践:跟踪管道健康指标。
- 最佳实践:记录所有转换。
- 最佳实践:生产前用样本数据测试。
- 最佳实践:用 git 跟踪管道变更。
适用边界 · 注意事项
- 没有 data-mcp 或对应 postgres_query、mysql_query、mongodb_aggregate、bigquery_load、snowflake_api 等工具/账号时,无法按本技能直接执行。
- 只是一次性、小型、本地数据转换且不需要调度、质量校验、监控告警时,不值得搭建完整 ETL 管道。
- 需要严格实时流处理或亚秒级延迟时,该以调度 DAG 为主的 ETL 模式不适用。