strategy
strategy
strategy는 스냅샷이 레코드 변경을 감지할 때 쓸 전략을 정하는 설정이에요. timestamp와 check 두 가지가 기본이며, 차이는 스냅샷 가이드에서 자세히 다뤄요. 필수 설정이라 기본값이 없어요.
출처: 문서
본문
(dbt v1.9 이상 적용) snapshots/.yml
snapshots:
- name: snapshot_name:
relation: source('my_source', 'my_table')
config:
strategy: timestamp
updated_at: column_name
dbt_project.yml
snapshots:
<resource-path>:
+strategy: timestamp
+updated_at: column_name
(dbt v1.9 이상 적용) snapshots/.yml
snapshots:
- name: snapshot_name:
relation: source('my_source', 'my_table')
config:
strategy: check
check_cols: [column_name] | "all"
dbt_project.yml
snapshots:
<resource-path>:
+strategy: check
+check_cols: [column_name] | all
Description
strategy는 dbt가 레코드 변경 감지에 사용할 스냅샷 전략이에요. 두 전략의 차이를 이해하려면 스냅샷 가이드를 읽어보세요.
Default
필수 설정이에요. 기본값이 없어요.
Examples
timestamp 전략 사용하기
(dbt v1.9 이상 적용)
snapshots/timestamp_example.yml
snapshots:
- name: orders_snapshot_timestamp
relation: source('jaffle_shop', 'orders')
config:
schema: snapshots
strategy: timestamp
unique_key: id
updated_at: updated_at
check 전략 사용하기
(dbt v1.9 이상 적용)
snapshots/check_example.yml
snapshots:
- name: orders_snapshot_check
relation: source('jaffle_shop', 'orders')
config:
schema: snapshots
unique_key: id
strategy: check
check_cols:
- status
- is_cancelled
고급: 커스텀 스냅샷 전략 정의하고 사용하기
내부적으로 스냅샷 전략은 snapshot__strategy라는 이름의 매크로로 구현돼요.
- timestamp 전략 소스 코드
- check 전략 소스 코드
같은 이름 패턴의 매크로를 프로젝트에 추가하면 나만의 스냅샷 전략을 구현할 수 있어요. 예를 들어 하드 삭제를 기록하는 timestamp_with_deletes 같은 전략을 만들 수 있죠.
snapshot_timestamp_with_deletes_strategy라는 매크로를 만들어요. 기존 코드를 참고해서 필요에 맞게 조정하세요.strategy설정으로 이 전략을 사용해요.
(dbt v1.9 이상 적용) snapshots/.yml
snapshots:
- name: my_custom_snapshot
relation: source('my_source', 'my_table')
config:
strategy: timestamp_with_deletes
updated_at: updated_at_column
unique_key: id
더 알아보기 (Learn more)
- Snapshots — 스냅샷과 두 전략의 차이.
- updated_at — timestamp 전략에 필요한 컬럼 설정.
- check_cols — check 전략에서 비교할 컬럼 설정.