Search CTRL + K

overview

metric은 0개 이상의 차원(dimension)을 지원하는 테이블에 대한 집계다.

exposures 과 마찬가지로 metric 은 노드로 표시하며 YAML 파일로 표현할 수 있다. dbt 프로젝트에서 메트릭을 정의하면 중요한 비즈니스 로직을 테스트하거나, version-controlled 코드로 인식할 수 있다. 또한 이러한 메트릭 정의를 downstream tooling 에 추가하여 metric report 의 일관성 및 정확성을 높일 수 있다.

metric profit

다운스트림 도구(downstream tool)에서 메트릭 사양 사용

dbt 컴파일 컨텍스트는 graph.metrics 변수를 통해 메트릭에 접근할 수 있다. manifest 에는 다운스트림 메타데이터 사용에 대한 메트릭을 포함한다.

종속성(dependency) 확인 및 선택

exposure 와 마찬가지로 메트릭으로 롤업되는 모든 것을 확인하고(dbt ls -s +metric:*) dbt docs 에서 시각화할 수 있다.

metric 이용

metrics: in .yml

metrics: 아래로 파일에 정의할 수 있다. metric 네이밍 제약사항은

example

# models/marts/product/schema.yml

version: 2

models:
 - name: dim_customers
   ...

metrics:
  - name: rolling_new_customers
    label: New Customers
    model: ref('dim_customers')
    [description](description): "The 14 day rolling count of paying customers using the product"

    calculation_method: count_distinct
    expression: user_id 

    timestamp: signup_date
    time_grains: [day, week, month, quarter, year]

    dimensions:
      - plan
      - country
    
    window:
      count: 14
      period: day

    filters:
      - field: is_paying
        operator: 'is'
        value: 'true'
      - field: lifetime_value
        operator: '>='
        value: '100'
      - field: company_name
        operator: '!='
        value: "'Acme, Inc'"
      - field: signup_date
        operator: '>='
        value: "'2020-01-01'"
        
    # general properties
    config:
      enabled: true | false
      treat_null_values_as_zero: true | false

    meta: {team: Finance}

dynamic query

dbt_metrics package

reference

Document: Metrics
package: dbt_metrics