Community研究与数据分析github.com

构建 Dagster 资产

使用软件定义资产构建 Dagster 管道 — 包括资产依赖、分区、资源和IO管理器、资产检查以及调度/传感器。适用于创建 Dagster 资产或作业、将数据建模为资产、添加分区或回填、配置资源/IO管理器,或从基于任务编排迁移到资产管理。

构建 Dagster 资产 是什么?

该技能专门用于指导开发者使用 Dagster 的软件定义资产(Software-Defined Assets)范式构建数据管道。它强调从“任务思维”转向“资产思维”,将每个输出(如表、文件、ML模型)建模为一个持久化对象,并通过函数参数自动声明依赖关系,从而让 Dagster 自动构建血缘图。技能覆盖了资产分区(按时间、地域等维度切片)、资源和 IO 管理器的注入、资产检查(数据质量断言)以及调度与传感器的配置。支持平台为 Dagster 框架(Python)。该技能通过详细的工作流模式、Python 代码示例和常见陷阱(如任务思维遗留、IO 写入硬编码、分区非幂等性等)帮助用户高效构建可观测、可测试且具备血缘追踪的生产级数据管道。

兼容平台~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 管理器或资源
- [ ] 添加资产检查以保障数据质量
- [ ] 设置调度/传感器来自动物化
  1. 以资产而非任务来思考。 资产是一个持久化对象(表、文件、模型)。通过将上游资产作为函数参数来声明依赖关系——Dagster 会自动构建血缘图。
  2. 对自然切片的数据(按天、区域)进行分区,以便能够一次物化/回填一个切片。
  3. 资源和 IO 管理器持有连接和读/写逻辑,使资产主体专注于转换,并使其可测试。
  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 管理器 — 注入一个仓库客户端,而不是在资产内部构造它:

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

调度一个分区作业,使得每次运行都能物化最新的分区;使用传感器在上游文件/资产出现时触发物化。

常见陷阱

  • 任务思维 — 对所有操作都使用裸 @op/jobs 会失去血缘关系、可观测性以及资产免费提供的分区感知回填功能。
  • 在资产体内编写 IO — 硬编码连接会使资产无法测试;应使用资源/IO 管理器。
  • 非幂等的分区资产 — 物化一个分区必须能够覆盖该分区,而非追加(参见 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.

相关技能