算法艺术创作
algorithmic-art
通过代码和可调参数创作生成艺术与交互式视觉效果。
data-pipeline【设计与创意】Design, build, and debug data pipelines for ETL/ELT, data ingestion, transformation, and orchestration. TRIGGER when: user asks to "build a pipeline", "ETL", "ELT", "data ingestion", "data transformation", "orchestrate data", "airflow DAG", "dbt model", "data workflow", "batch processing", "streaming pipeline", or "move data from X to Y".
独立 GitHub 快照 · 自动分类 · 以原作者文档为准
You are an expert data engineer. When the user asks you to design, build, or debug a data pipeline, follow this structured process.
| Requirement | Options | Impact |
|---|---|---|
| Volume | MB, GB, TB, PB | Technology and architecture choice |
| Velocity | Batch (hourly/daily), micro-batch (minutes), real-time (seconds) | Processing framework |
| Variety | Structured, semi-structured, unstructured | Schema handling approach |
| Source(s) | Database, API, file, stream, SaaS | Connector/extractor choice |
| Destination | Data warehouse, data lake, database, API | Loader choice |
| Frequency | One-time, scheduled, event-driven | Orchestration approach |
| Latency SLA | Minutes, hours, next day | Architecture pattern |
| Idempotency | Must be re-runnable without side effects | Design constraint |
Source --> Extract --> Transform (staging) --> Load --> Destination
Source --> Extract --> Load (raw) --> Transform (in warehouse) --> Curated layer
Source --> Message Broker --> Stream Processor --> Sink
Source --> Ingestion --> Bronze (raw) --> Silver (cleaned) --> Gold (aggregated)
| Source Type | Method | Considerations |
|---|---|---|
| SQL Database | Full load or CDC (Change Data Capture) | CDC for large tables; use watermark columns |
| REST API | Pagination, rate limiting, retry | Handle 429s, implement exponential backoff |
| Files (S3/GCS) | List + read, event-driven (S3 notification) | Handle late-arriving files |
| Streaming | Consumer group, offset management | At-least-once vs exactly-once semantics |
| SaaS tools | Official connectors (Fivetran, Airbyte) | Check API limits and sync frequency |
| Pattern | When to Use | Implementation |
|---|---|---|
| Cleaning | Always | NULL handling, type casting, dedup |
| Filtering | Subset of data needed | WHERE clauses, row-level logic |
| Joining | Enrich with reference data | Lookup tables, dimension joins |
| Aggregation | Summary metrics needed | GROUP BY, window functions |
| Pivoting | Reshape data structure | PIVOT/UNPIVOT, melt/pivot |
| Derivation | Computed columns | Business logic, formulas |
| Validation | Quality gates | Schema checks, range checks, referential integrity |
| Strategy | Description | Use When |
|---|---|---|
| Full replace | DROP + recreate | Small tables, no history needed |
| Append | INSERT new rows | Event/log data, immutable records |
| Upsert (MERGE) | INSERT or UPDATE by key | Dimension tables, mutable entities |
| SCD Type 2 | Track historical changes | Need full audit history |
| Partition overwrite | Replace specific partitions | Time-partitioned fact tables |
# Airflow DAG skeleton
from airflow import DAG
from airflow.operators.python import PythonOperator
from datetime import datetime, timedelta
default_args = {
"owner": "data-team",
"retries": 2,
"retry_delay": timedelta(minutes=5),
"email_on_failure": True,
}
with DAG(
dag_id="pipeline_name",
schedule_interval="0 6 * * *", # Daily at 6 AM UTC
start_date=datetime(2025, 1, 1),
catchup=False,
tags=["production"],
default_args=default_args,
) as dag:
extract = PythonOperator(task_id="extract", python_callable=extract_fn)
transform = PythonOperator(task_id="transform", python_callable=transform_fn)
validate = PythonOperator(task_id="validate", python_callable=validate_fn)
load = PythonOperator(task_id="load", python_callable=load_fn)
extract >> transform >> validate >> load
datetime.now()Build quality checks into the pipeline:
| Check | When | Action on Failure |
|---|---|---|
| Schema validation | After extract | Fail pipeline, alert |
| Row count threshold | After extract | Warn if < expected, fail if zero |
| Null percentage | After transform | Fail if exceeds threshold |
| Uniqueness on keys | Before load | Fail, investigate duplicates |
| Referential integrity | Before load | Warn or fail based on severity |
| Freshness check | After load | Alert if data is stale |
| Value range checks | After transform | Flag anomalous records |
| Reconciliation | After load | Compare source vs destination counts |
# schema.yml
models:
- name: orders
columns:
- name: order_id
tests:
- unique
- not_null
- name: amount
tests:
- not_null
- dbt_utils.accepted_range:
min_value: 0
- name: customer_id
tests:
- relationships:
to: ref('customers')
field: customer_id
| Metric | Alert Threshold |
|---|---|
| Pipeline duration | > 2x historical average |
| Row count | < 50% or > 200% of expected |
| Error rate | > 1% of records |
| Data freshness | > SLA window |
| Resource usage | > 80% memory or CPU |