Community研究&データ分析github.com

Dagsterアセットの構築

ソフトウェア定義アセットを使用してDagsterパイプラインを構築します。アセットの依存関係、パーティション、リソースとIOマネージャー、アセットチェック、スケジュール/センサーを扱います。Dagsterアセットやジョブを作成するとき、データをアセットとしてモデル化するとき、パーティションやバックフィルを追加するとき、リソース/IOマネージャーを配線するとき、タスクベースのオーケストレーションからアセットに移行するときに使用します。

Dagsterアセットの構築 とは?

このスキルは、Dagsterのソフトウェア定義アセット(SDA)を用いたデータパイプライン構築を支援します。従来のタスク指向のオーケストレーション(@opやジョブ)ではなく、テーブルやファイル、MLモデルなどの永続的なオブジェクトをアセットとしてモデル化し、関数パラメーターで依存関係を宣言することで、Dagsterが自動的にリネージグラフを構築します。日次や地域などのパーティション分割、リソースやIOマネージャーによる接続と読み書きロジックの外部化、アセットチェックによるデータ品質保証、スケジュールやセンサーによる自動実行をサポートします。主にDagsterを使用する開発者を対象としており、CodexやCursorなどのAIエージェント上で動作します。このスキルは、パーティション付きアセットの依存関係、リソース注入、アセットチェックのパターンを示す具体的なコード例を提供し、よくある落とし穴(タスク思考、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に質問する

このエージェントスキルを事前に読み込んだ状態で新しいチャットを開きます。

ドキュメント

Dagsterアセットの構築 は何をしますか?

使用するタイミング

  • Dagsterのソフトウェア定義アセットやジョブを作成・リファクタリングするとき
  • テーブル/ファイル/MLモデルをリネージ付きのアセットとしてモデル化するとき
  • パーティション、バックフィル、アセットチェック、スケジュール、センサーを追加するとき
  • Airflowには使用しないでください(Airflow用のスキルを使用してください)。

ワークフロー

- [ ] 各出力を @asset としてモデル化し、関数引数で deps を宣言する
- [ ] 時間/カテゴリでスライスされたデータにパーティションを追加する
- [ ] IO(読み取り/書き込み)をIOマネージャーまたはリソースに移動する
- [ ] データ品質のためのアセットチェックを追加する
- [ ] スケジュール/センサーでマテリアライズする
  1. タスクではなくアセットで考える。 アセットとは永続的なオブジェクト(テーブル、ファイル、モデル)です。上流のアセットを関数パラメーターとして参照することで依存関係を宣言します。Dagsterが自動的にリネージグラフを構築します。
  2. パーティション は、自然にスライスされる(日次、地域など)アセットに設定し、一度に1スライスずつマテリアライズ/バックフィルできるようにします。
  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/ジョブを使うと、アセットが無料で提供するリネージ、可観測性、パーティション対応バックフィルが失われます。
  • アセット内部での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.

関連スキル