C.W.K.
Stream
Lesson 04 of 05 · published

dbt — 코드로서의 transformation

~13 min · dbt, modeling, transformations

Level 0구경꾼
0 XP0/47 lessons0/11 achievements
0/120 XP to next level120 XP to go0% complete

Modern data stack 의 transformation layer

dbt (data build tool) — 2026.4 기준 1.9 — 가 modern data team 이 ELT 의 transformation 절반 작성하는 방법. Orchestrator 가 SQL 돌리는 Python 도는 거 대신 dbt 는 SQL transformation 관리 전용 도구: version-controlled 코드로, 테스트, docs, lineage, 배포 스토리와 함께.

dbt 가 관리하는 것

  • Model — dbt 가 테이블 또는 뷰로 materialize 하는 SQL SELECT 문.
  • Source — freshness 체크 있는 선언된 raw upstream 테이블.
  • Test — model 출력에 대한 assertion (uniqueness, non-null, accepted value, custom).
  • Docs — 자동 생성 lineage 그래프 + 문서 사이트.
  • Snapshot — SCD Type 2 이력 테이블의 dbt 이름.
  • Macro — Jinja 템플릿 재사용 가능 SQL.

모두가 dbt 에 있는 이유

dbt 이전에 transformation layer 가 scheduler 가 돌리는 ad-hoc SQL 또는 orchestrator task 안 묻힌 거였어. 어느 쪽이든 SQL 자체가 first-class 산출물 아니었어 — 테스트 없고, docs 없고, version control 규율 없고. dbt 가 SQL 을 산출물로 만들었고, 한 번 그게 일어나니 모든 다른 practice (review, test, lineage) 가 자연스레 따라옴.

Code

ref 기반 의존성, schema, test 있는 dbt model·sql
-- models/marts/orders/fct_orders.sql
-- 테이블로 materialize; ref() 호출이 그래프에 의존성 생성.
{{ config(materialized='table') }}

WITH src AS (
    SELECT * FROM {{ ref('stg_orders') }}
),
customers AS (
    SELECT * FROM {{ ref('dim_customers') }}
)

SELECT
    s.order_id,
    s.line_item_id,
    c.customer_key,
    s.product_key,
    s.date_key,
    s.quantity,
    s.amount_usd,
    s.discount_usd
FROM   src s
LEFT JOIN customers c
  ON   s.customer_id = c.customer_id
  AND  s.order_date >= c.valid_from
  AND  s.order_date <  c.valid_to
schema.yml — 선언적 test + docs 가 model 옆에·yaml
version: 2

models:
  - name: fct_orders
    description: "주문 line item 당 한 row. 주문 시점 dim_customers 와 join."
    columns:
      - name: order_id
        description: "Source 주문 식별자."
        tests:
          - not_null
      - name: line_item_id
        tests:
          - not_null
      - name: customer_key
        tests:
          - relationships:
              to: ref('dim_customers')
              field: customer_key
      - name: amount_usd
        tests:
          - not_null
          - dbt_utils.expression_is_true:
              expression: "amount_usd >= 0"

External links

Exercise

접근 가능한 warehouse 에 dbt-core 설치 (DuckDB local 이 가장 쉬움: pip install dbt-duckdb). dbt init, staging model 하나 + mart model 하나 빌드 (사이 ref), key column 에 not_null test 추가, dbt build 실행. 목표는 test → materialize → docs loop 끝에서 끝까지 느끼는 거.

Progress

Progress is local-only — sign in to sync across devices.
이 페이지에서 버그를 발견하셨거나 피드백이 있으세요?문제 신고

댓글 0

🔔 답글 알림 (로그인 필요)
로그인댓글을 남기려면 로그인해 주세요.

아직 댓글이 없어요. 첫 댓글을 남겨보세요.