dbt 시드

중급 dbt

Mike Metzger

Data Engineer

dbt 시드란?

  • 데이터 웨어하우스에 적재할 CSV 파일
  • 보통 변경이 드문 데이터 집합
    • 국가 목록
    • 우편번호 목록
  • 원시 데이터용이 아님

시드

1 Photo by Maddi Bazzocco on Unsplash
중급 dbt

이유

  • 관리가 쉬움
  • 다양한 시나리오에서 사용이 쉬움
  • 형상관리 가능
중급 dbt

시드는 어떻게 정의하나요?

  • seeds 디렉터리에 CSV 파일 추가
  • 첫 행이 헤더인지 확인
  • dbt seed 명령으로 가져오기
zipcode,place,state
99553,Akutan,Alaska
99571,Cold Bay,Alaska
99583,False Pass,Alaska

bash> dbt seed
1 Postal codes provided via https://github.com/zauberware/postal-codes-json-xml-csv
중급 dbt

추가 구성

  • 여러 옵션
    • 어떤 스키마?
    • 어떤 데이터베이스?
    • 컬럼 따옴표 처리
    • 컬럼 데이터 타입
  • 전체 프로젝트 또는 개별 시드에 적용 가능
  • dbt_project.yml 또는 seeds/properties.yml에 추가 가능
중급 dbt

데이터 타입 정의

  • 사용 가능한 데이터 타입은 웨어하우스에 따라 다름
  • 일반적인 타입 제공
    • Integer
    • Varchar
  • 타입을 지정하지 않으면 데이터로부터 추론됨
version: 2

seeds:
  - name: zipcodes
    config:
      column_types:
        zipcode: varchar(5)
중급 dbt

테스트

  • 테스트 지원
  • 모델·소스와 동일하게 동작
version: 2

seeds:
  - name: zipcodes
    config:
      column_types:
        zipcode: varchar(5)
    columns:
      - name: zipcode
        tests:
          - unique
중급 dbt

시드 접근

  • {{ ref() }}로 접근 가능
  • 최초 로드 후 모델처럼 동작
select * from
  {{ ref('zipcodes') }}
중급 dbt

연습해 봅시다!

중급 dbt

Preparing Video For Download...