본문 바로가기
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.8 기준 dbt-core 1.12) 는 modern data team 이 ELT 의 transformation 절반을 쓰는 방식이야. SQL 을 돌리는 Python 을 orchestrator 가 돌리는 겹겹의 포장 대신, 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 가 돌리는 임시 SQL 이거나 orchestrator task 안에 파묻힌 SQL 이었어. 어느 쪽이든 SQL 자체는 일급 산출물이 아니었지 — 테스트 없고, 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 를 설치해 (제일 쉬운 건 local DuckDB: 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

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

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