project_name 컨텍스트 변수
project_name 컨텍스트 변수
project_name 컨텍스트 변수는 dbt가 실행 중인 루트 레벨 프로젝트의 name을 반환해요. 이 변수는 루트 레벨 프로젝트 매크로가 있다면 실행을 그 매크로로 위임(defer)하는 데 쓸 수 있어요.
출처: 문서
본문
사용 예시
redshift/macros/helper.sql
/*
This macro vacuums tables in a Redshift database. If a macro exists in the
root-level project called `get_tables_to_vacuum`, this macro will call _that_
macro to find the tables to vacuum. If the macro is not defined in the root
project, this macro will use a default implementation instead.
*/
{% macro vacuum_tables() %}
{% set root_project = context[project_name] %}
{% if root_project.get_tables_to_vacuum %}
{% set tables = root_project.get_tables_to_vacuum() %}
{% else %}
{% set tables = redshift.get_tables_to_vacuum() %}
{% endif %}
{% for table in tables %}
{% do redshift.vacuum_table(table) %}
{% endfor %}
{% endmacro %}
더 알아보기 (Learn more)
project_name으로 루트 프로젝트의 매크로를 조건적으로 호출할 수 있어요.- 관련 개념: context, 매크로 정의.