Community研究與資料分析github.com

Unknown-333/building-dagster-assets

使用軟體定義的資產建立 Dagster 管道——資產依賴、分區、資源與 IO Manager、資產檢查、排程與感測器。當你需要建立 Dagster 資產或任務、將資料建模為資產、新增分區或回填、連接資源/IO Manager,或從任務型編排遷移至資產時使用。

building-dagster-assets 是什麼?

此技能專注於使用 Dagster 的軟體定義資產(Software-Defined Assets)來構建數據管道。它教導開發者如何將表格、檔案或機器學習模型建模為資產,透過函數參數自動聲明資產間的依賴關係(lineage),從而在 Dagster UI 中獲得完整的血緣圖與可觀測性。該技能涵蓋了核心模式:為按時間或類別切分的數據添加 `DailyPartitionsDefinition` 等分區定義、使用資源(Resources)和 IO Manager 來管理外部連接與讀寫邏輯(提升可測試性)、透過 `@asset_check` 附加數據品質斷言,以及利用排程(Schedule)和感測器(Sensor)自動化產生物質化。此外,它還明確指出了常見陷阱,例如避免“任務思考”(只用 `@op`/jobs 而失去資產的線索和分區回填能力)、不要將 IO 邏輯硬編碼在資產函數體內、確保分區定義在不同資產間一致,以及不要跳過資產檢查導致壞數據靜默進入管道。支援平台為 Dagster 框架。

相容平台~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/Unknown-333/awesome-data-engineering-skills/tree/main/skills/building-dagster-assets

Installed? Explore more 研究與資料分析 skills: affaan-m/uspto-database, affaan-m/scholar-evaluation, affaan-m/literature-review · View all 6 →

在你喜歡的 AI 中提問

開啟一個已預先載入此 Agent Skill 的新對話。

說明文件

建構 Dagster 資產

使用時機

  • 建立或重構 Dagster 的軟體定義資產與任務。
  • 將表格/檔案/ML 模型建模成具備血緣關係的資產。
  • 新增分區、回填、資產檢查、排程或感測器。
  • 不要用於 Airflow(請使用 Airflow 專用技能)。

工作流程

- [ ] 將每個輸出建模為 @asset;透過函數參數聲明依賴
- [ ] 為時間/類別切分的數據新增分區
- [ ] 將 IO(讀取/寫入)移至 IO Manager 或資源中
- [ ] 新增資產檢查以確保資料品質
- [ ] 使用排程/感測器來產生物質化
  1. 以資產為思考中心,而非任務。 資產是一個持久化的物件(資料表、檔案、模型)。透過將上游資產作為函數參數來聲明依賴關係——Dagster 會自動建立血緣圖。
  2. 為自然可切分的資產(按天、按區域)新增分區,這樣你就可以一次產生物質化或回填一個切片。
  3. 資源和 IO Manager 負責管理連線與讀寫邏輯,使資產主體專注於轉換邏輯,並讓資產更容易測試。
  4. 資產檢查 將資料品質斷言附加到資產上。

模式

帶有分區的資產及其依賴:

import dagster as dg

daily = dg.DailyPartitionsDefinition(start_date="2026-01-01")

@dg.asset(partitions_def=daily)
def raw_orders(context: dg.AssetExecutionContext) -> None:
    day = context.partition_key
    write_parquet(f"raw/orders/{day}.parquet", fetch_orders(day))

@dg.asset(partitions_def=daily)
def orders_clean(context, raw_orders) -> None:  # 依賴 raw_orders
    day = context.partition_key
    transform_and_load(day)

@dg.asset_check(asset=orders_clean)
def no_null_ids(context) -> dg.AssetCheckResult:
    n = count_null_order_ids(context.partition_key)
    return dg.AssetCheckResult(passed=n == 0, metadata={"null_ids": n})

資源 / IO Manager — 注入倉庫客戶端,而非在資產內部建立:

@dg.asset
def orders_summary(context, warehouse: WarehouseResource, orders_clean):
    warehouse.execute("insert into summary select ...")

排程一個分區任務,使得每次執行自動產生物質化最新分區;使用感測器在上游檔案/資產出現時觸發產生物質化。

常見陷阱

  • 任務思考 — 到處使用原生的 @op/jobs 會失去資產提供的血緣、可觀測性以及分區感知的回填功能。
  • 在資產函數體內進行 IO — 硬編碼連線使資產難以測試;應使用資源/IO Manager。
  • 非冪等的分區資產 — 產生物質化一個分區時應覆蓋該分區,而不是追加(參見 writing-idempotent-transformations)。
  • 跳過資產檢查 — 不進行檢查時,壞數據會靜默地產生物質化;Dagster 會在 UI 中顯示檢查失敗並可阻止下游。
  • 依賴的資產之間分區定義不匹配 — 確保 partitions_def 一致,以便對應關係能正確解析。

Individual skills in this repo

This repo contains 9 individual skills — each has its own dedicated page.

Unknown-333/authoring-airflow-dags

Write production-grade Apache Airflow DAGs using the TaskFlow API — idempotent tasks, correct scheduling and catchup, retries/SLAs, connections/variables, and avoiding top-level code. Use when creating or reviewing Airflow DAGs, scheduling pipelines, wiring task dependencies, configuring retries/backfills, or fixing non-idempotent tasks.

Unknown-333/building-dbt-models

Build well-structured dbt models — staging/intermediate/marts layers, ref() and source(), materializations, and incremental models with the right strategy. Use when creating or refactoring dbt models, choosing table vs view vs incremental, structuring a dbt project, or writing incremental logic.

Unknown-333/building-feature-pipelines

Build ML feature pipelines and feature stores — point-in-time-correct joins to avoid label leakage, offline/online parity, feature freshness and backfills, and materialization with tools like Feast. Use when engineering features for ML, preventing train/serve skew or data leakage, building a feature store, or backfilling historical features for training.

Unknown-333/building-iceberg-tables

Design and operate Apache Iceberg tables — partitioning and hidden partitioning, partition/schema evolution, snapshots and time travel, compaction and small-file cleanup, and MERGE/upsert for lakehouse tables on Spark, Flink, Trino, or Snowflake. Use when creating or maintaining Iceberg tables, choosing partitioning, evolving schema/partitions, or fixing small-file and metadata bloat.

Unknown-333/building-ingestion-pipelines

Build batch and incremental data ingestion (extract-load) pipelines — full vs incremental extraction, change data capture (CDC), watermarks and high-water marks, API pagination and rate limits, and choosing managed EL tools (Fivetran, Airbyte) vs custom code. Use when ingesting data from databases, APIs, files, or SaaS into a warehouse/lake, or designing incremental extraction and CDC.

Unknown-333/building-kafka-consumers

Build reliable Apache Kafka consumers and producers — consumer groups and partition assignment, offset commit strategy, at-least-once vs exactly-once, idempotent/transactional producers, rebalancing, and dead-letter handling. Use when writing Kafka consumers/producers, configuring offset commits or consumer groups, tuning throughput, or handling rebalances and poison messages.

Unknown-333/debugging-data-pipelines

Systematically root-cause data pipeline failures and data incidents — job errors, wrong or missing data, duplicates, and freshness misses — by tracing lineage upstream, isolating the failing stage, reconciling against source, and planning a safe fix and backfill. Use when a pipeline fails, numbers look wrong, data is missing or duplicated, a dashboard is stale, or a stakeholder reports a data discrepancy.

Unknown-333/designing-backfills-and-replays

Plan and run safe data backfills and replays — idempotent reprocessing of historical windows, partition-by-partition execution, isolating backfill compute from production, verifying results, and avoiding double-counting or changed history. Use when backfilling a new or fixed model, reprocessing after a bug, replaying events, or loading history for a new pipeline without corrupting existing data.

Unknown-333/designing-data-contracts

Define and enforce data contracts between producers and consumers — explicit schema, semantics, ownership, SLAs, and versioning — to prevent silent upstream changes from breaking downstream pipelines. Use when a producer schema change could break consumers, defining an interface between teams/services and the warehouse, or adding schema enforcement at ingestion.

相關技能