소스에서 quoting 구성하기

소스에서 quoting 구성하기

quoting 속성은 {{ source() }} 함수를 직접 관계 참조로 해석할 때 데이터베이스·스키마·식별자를 인용(quote)할지 여부를 구성해 줘요. 특정 소스 테이블에 대해 지정하면 상위 소스 설정을 덮어써요.

출처: 문서

본문

models/<filename>.yml

sources:
  - name: jaffle_shop
    quoting:
      database: true | false
      schema: true | false
      identifier: true | false
    tables:
      - name: orders
        quoting:
          database: true | false
          schema: true | false
          identifier: true | false

Definition

{{ source() }} 함수를 직접 관계 참조로 해석할 때 dbt가 데이터베이스, 스키마, 식별자를 인용할지 선택적으로 구성해요. 이 구성은 소스의 모든 테이블에 대해 지정하거나 특정 소스 테이블에 대해 지정할 수 있어요. 특정 소스 테이블에 정의된 quoting 구성은 상위 소스에 지정된 quoting 구성을 덮어써요. BigQuery 용어 — BigQuery quoting 구성에서는 databaseschema를 사용하지만, 이 구성은 각각 projectdataset 이름에 적용된다는 점을 기억해 주세요.

Default

기본값은 데이터베이스마다 달라요. 대부분의 어댑터에서 quoting은 기본적으로 true로 설정돼요. 왜 그럴까요? 인용된 식별자든 인용되지 않은 식별자든 관계에서 선택하는 것은 똑같이 쉬워요. quoting은 식별자에 예약어와 특수 문자를 사용할 수 있게 해 주지만, 가능하면 피하는 걸 권장해요. Snowflake에서는 quoting이 기본적으로 false로 설정돼요. 인용된 식별자로 관계를 만들면 해당 식별자도 대소문자를 구분하게 돼요. 이후에 선택하기가 훨씬 어려워져요. 대소문자를 구분하거나 예약어거나 특수 문자를 포함하는 관계 식별자에 대해서는 quoting을 다시 활성화할 수 있지만, 가능하면 최대한 피하는 걸 권장해요.

Example

models/<filename>.yml

sources:
  - name: jaffle_shop
    database: raw
    quoting:
      database: true
      schema: true
      identifier: true
    tables:
      - name: orders
      - name: customers
        # This overrides the `jaffle_shop` quoting config
        quoting:
          identifier: false

다운스트림 모델에서: models/<filename>.yml

select
  ...
-- this should be quoted
from {{ source('jaffle_shop', 'orders') }}
-- here, the identifier should be unquoted
left join {{ source('jaffle_shop', 'customers') }} using (order_id)

이것은 다음과 같이 컴파일돼요:

select
  ...
-- this should be quoted
from "raw"."jaffle_shop"."orders"
-- here, the identifier should be unquoted
left join "raw"."jaffle_shop".customers using (order_id)

더 알아보기 (Learn more)