Communitygithub.com

dbt (データビルドツール)

SQLモデリング、Jinjaマクロ、テスト、ドキュメント、セマンティックレイヤーをカバーするdbtのエキスパートアシスタンスです。BigQuery、Snowflake、PostgreSQL上のアナリティクスエンジニアリングパイプライン構築時に活用します。

dbt (データビルドツール) とは?

このスキルは、アナリティクスエンジニアリングにおけるdbt(データビルドツール)の専門家としての支援を提供します。v2.0で導入されたFusion Engine(Rust)によるパフォーマンス向上に対応し、Snowflake、BigQuery、Databricks、Redshiftなどの主要なクラウドウェアハウス上でのデータ変換を効率的に行います。Jinjaテンプレートを使用した再利用可能なSQLモデル、DAG依存関係の管理、スキーマテストによるデータ品質保証、そして自動生成されるドキュメントとリネージュグラフといったdbtの主要機能を活用します。インクリメンタルモデル、Jinjaマクロ、ref()/source()による宣言的モデリングなど、実践的なパターンとベストプラクティスを提供します。

対応~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/G1Joshi/Agent-Skills/tree/HEAD/skills/ai-ml/dbt

お気に入りのAIに質問する

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

ドキュメント

dbt (データビルドツール) は何をしますか?

dbtは、SQLを使用してウェアハウス内のデータ変換を管理します。v2.0では、パフォーマンス向上のためのFusion Engine (Rust) が導入されました。

使用するタイミング

  • アナリティクスエンジニアリングとデータ変換: モダンなクラウドウェアハウス (Snowflake、BigQuery、Databricks、Redshift) 内で生データを変換します。
  • Jinjaとバージョン管理によるモジュラーSQL: DAG依存関係とマクロを使用した再利用可能なSQLモデルを構築します。
  • データ品質とスキーマテスト: unique、not_null、参照整合性、カスタム単体テストを実施します。
  • 自動データドキュメントとリネージュ: コードベースのスキーマから対話型の依存関係リネージュグラフを直接生成します。

クイックスタート

-- models/marts/fct_orders.sql
{{ config(materialized='table') }}

with orders as (
    select * from {{ ref('stg_orders') }}
),
payments as (
    select * from {{ ref('stg_payments') }}
)

select
    orders.order_id,
    orders.customer_id,
    orders.order_date,
    coalesce(payments.amount, 0) as total_amount
from orders
left join payments using (order_id)

中核概念

ref() と source() による宣言的SQLモデリング

依存関係を解決した変換モデルの構築:

-- models/marts/core/fct_customer_orders.sql
{{
  config(
    materialized = 'incremental',
    unique_key = 'order_id',
    on_schema_change = 'fail'
  )
}}

with orders as (
    select * from {{ ref('stg_orders') }}
    {% if is_incremental() %}
      where order_date >= (select coalesce(max(order_date), '1970-01-01') from {{ this }})
    {% endif %}
),

customers as (
    select * from {{ ref('stg_customers') }}
)

select
    o.order_id,
    o.customer_id,
    c.full_name as customer_name,
    o.order_date,
    o.total_amount_usd
from orders o
inner join customers c on o.customer_id = c.customer_id

YAMLによるスキーマテストとドキュメント

カラム制約とドキュメントを強制:

# models/marts/core/schema.yml
version: 2

models:
  - name: fct_customer_orders
    description: "ステージングされた注文と顧客ディメンションを組み合わせた日次顧客注文ファクトテーブル。"
    columns:
      - name: order_id
        description: "注文の主キー。"
        tests:
          - unique
          - not_null

      - name: customer_id
        description: "ステージング顧客を参照する外部キー。"
        tests:
          - not_null
          - relationships:
              to: ref('stg_customers')
              field: customer_id

      - name: total_amount_usd
        description: "USDでの取引合計金額。"
        tests:
          - not_null

DRYな再利用可能ロジックのためのJinjaマクロ

カスタムの再利用可能なSQLユーティリティを作成:

-- macros/cents_to_dollars.sql
{% macro cents_to_dollars(column_name, decimal_places=2) -%}
    round(cast(({{ column_name }} / 100.0) as numeric), {{ decimal_places }})
{%- endmacro %}

-- モデル内での使用法:
select
    id,
    {{ cents_to_dollars('amount_in_cents') }} as amount_usd
from {{ ref('stg_payments') }}

一般的なパターン

タイムスタンプフィルタリングによるインクリメンタルモデル

問題: 数十億行のテーブルをdbtの実行のたびに毎回全体を再構築するのは、遅くコストがかかります。

解決策: is_incremental() とともに incremental マテリアライゼーションを使用:

{{ config(
    materialized='incremental',
    unique_key='event_id'
) }}

select * from {{ source('raw', 'events') }}

{% if is_incremental() %}
  -- ターゲットテーブルの最新イベント以降に作成された行のみをクエリ
  where event_timestamp > (select max(event_timestamp) from {{ this }})
{% endif %}

ベストプラクティス (2026)

  • 行うべき: プロジェクトを標準的なレイヤー (staging(生ソースと1対1)、intermediate、marts) に整理します。
  • 行うべき: DAGリネージュを維持するために、常に {{ ref('model_name') }} と {{ source('source_name', 'table_name') }} を使用します。
  • 行うべき: 数百万行規模のファクトテーブルにはインクリメンタルモデル (materialized='incremental') を実装します。
  • 行うべき: すべてのプルリクエストに対してCIパイプラインで dbt test を実行し、データスキーマの後退を検出します。
  • 行うべきでない: 生のデータベーステーブル参照 (例: analytics.raw.users) を記述せず、常に source() または ref() を使用します。
  • 行うべきでない: ステージングモデル内でビジネスロジックを実行せず、ステージングでは列のクリーニング、キャスト、リネームのみを行います。
  • 行うべきでない: 環境 (dev 対 prod) をハードコードせず、profiles.yml で target.name 条件分岐を使用します。

トラブルシューティング

エラー原因解決策
Compilation Error: Model '...' depends on a node named '...' which was not found{{ ref('model_name') }} のタイポ、またはモデルファイルが存在しない。モデルファイル名が参照文字列と完全に一致するか確認する。
dbt test failed: unique constraint violated非一意な結合条件により重複キーが生成された。target/compiled/ 内のコンパイル済みSQLで重複キーを調査する。
Schema change error during incremental run上流モデルで列が追加/削除され、既存のインクリメンタルテーブルが壊れた。スキーマを再構築するために dbt run --full-refresh を一度実行する。

リファレンス

Individual skills in this repo

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

G1Joshi/Agent-Skills

Expert Dask distributed computing assistance covering Dask DataFrames, Arrays, Futures, and cluster scaling. Use when analyzing datasets too large for pandas on a single machine or multi-node cluster.

G1Joshi/Agent-Skills

Expert JAX assistance covering Autograd, XLA compilation (`jit`), vectorization (`vmap`), and parallelization (`pmap`). Use when building high-performance numerical computing and cutting-edge deep learning research.

G1Joshi/Agent-Skills

Expert Ray distributed computing assistance covering Ray Core (actors, tasks), Ray Train, Ray Tune, and Ray Serve. Use when scaling Python compute and ML training across multi-node clusters.

G1Joshi/Agent-Skills

Expert Git version control assistance covering branching, interactive rebase, cherry-pick, submodules, worktrees, and conflict resolution. Use when managing source code history and collaboration workflows.

G1Joshi/Agent-Skills

Expert K9s CLI assistance covering terminal Kubernetes cluster navigation, real-time log streaming, port forwarding, and pod debugging. Use when managing and troubleshooting Kubernetes clusters with speed.

G1Joshi/Agent-Skills

Expert SWC assistance covering high-performance Rust-based JavaScript/TypeScript compilation, .swcrc configuration, Jest testing via @swc/jest, and minification. Use when replacing Babel with SWC for faster builds, accelerating test execution, or compiling modern ECMAScript features.

G1Joshi/Agent-Skills

Expert Tig assistance covering text-mode interface for Git, interactive staging, commit graph visualization, diff exploration, and blame navigation. Use when navigating Git commit history in the terminal, staging hunks interactively, browsing file changes, or reviewing revisions.

G1Joshi/Agent-Skills

Expert Vim assistance covering modal editing, .vimrc configuration, registers, macros, search/replace, and plugin management via vim-plug. Use when editing text efficiently in terminal environments, writing Vimscript, recording macros, or configuring core Vim settings.

G1Joshi/Agent-Skills

Expert Zed editor assistance covering high-performance Rust-based text editing, multi-buffer editing, language server protocols (LSP), and AI assistant integrations. Use when configuring Zed settings.json, setting up language extensions, collaborating in real-time channels, or optimizing editor startup speed.

G1Joshi/Agent-Skills

Expert Zsh assistance covering shell customization, Oh My Zsh plugins, Zinit plugin manager, prompt engineering (Starship/Powerlevel10k), and shell scripting. Use when configuring .zshrc, writing Zsh automation scripts, optimizing shell startup time, or configuring tab-completion.

G1Joshi/Agent-Skills

Expert [skill-name] assistance covering [feature 1], [feature 2], and [feature 3]. Use when [working with X], [debugging Y], or [implementing Z].

関連スキル