dbt ls

dbt ls (list) 명령어

dbt ls 명령어는 dbt 프로젝트의 리소스를 나열해요. 선택자(selector) 인자를 받으며, dbt listdbt ls의 별칭이에요. 데이터베이스에 연결하거나 쿼리를 실행하지는 않아요.

출처: 문서

본문

dbt ls 명령어는 dbt 프로젝트의 리소스를 나열해요. dbt run에서 제공되는 것과 유사한 선택자 인자를 받아요. dbt listdbt ls의 별칭이에요. dbt lstarget별 로직을 해결하기 위해 연결 프로필을 읽지만, 데이터베이스에 연결하거나 쿼리를 실행하지는 않아요.

(dbt v2.0 이상 적용) dbt v2를 사용할 때 dbt platform 실행 로그에서 dbt ls·dbt list 노드 결과는 최종 상태가 없으면 No-op으로 나타날 수 있어요. 이는 Unknown을 대체하며 dbt가 노드를 선택했지만 실행하지 않았음을 의미해요.

사용법

dbt ls
     [--resource-type {model,semantic_model,source,seed,snapshot,metric,test,exposure,analysis,function,default,all}]
     [--select SELECTION_ARG [SELECTION_ARG ...]]
     [--models SELECTOR [SELECTOR ...]]
     [--exclude SELECTOR [SELECTOR ...]]
     [--selector YML_SELECTOR_NAME] # legacy flag; use `--select selector:SELECTOR_NAME` in v1.12+
     [--output {json,name,path,selector}]
     [--output-keys KEY_NAME [KEY_NAME]]

dbt에서 리소스를 선택하는 방법에 대한 자세한 내용은 resource selection syntax를 참고하세요.

인자:

  • --resource-type: 이 플래그는 dbt ls 명령어에서 dbt가 반환하는 "리소스 유형"을 제한해요. 기본적으로 dbt ls 결과에는 analysis 유형을 제외한 모든 리소스 유형이 포함돼요.

  • --select: 이 플래그는 dbt ls 명령어가 반환하는 노드를 필터링할 하나 이상의 선택 유형 인자를 지정해요.

  • --models: --select 플래그처럼 노드를 선택하는 데 사용돼요. --resource-type=model을 암시하며 dbt ls 결과에서 모델만 반환해요. 하위 호환성을 위해서만 지원돼요.

  • --exclude: 반환된 노드 목록에서 제외할 선택자를 지정해요.

  • --output: 이 플래그는 dbt ls 명령어의 출력 형식을 제어해요.

  • --output-keys: --output json인 경우 이 플래그는 출력에 포함할 노드 속성을 제어해요.

참고로 dbt ls 명령어는 비활성화된 모델이나 비활성화된 모델에 의존하는 스키마 테스트는 포함하지 않아요. 반환된 모든 리소스는 config.enabled 값이 true예요.

사용 예시

다음 예시는 dbt ls 명령어로 프로젝트의 리소스를 나열하는 방법을 보여줘요.

  • 패키지별 모델 나열
  • 태그 이름별 테스트 나열
  • 인크리멘탈 모델의 스키마 테스트 나열
  • JSON 출력 나열
  • 커스텀 키가 있는 JSON 출력 나열
  • 시맨틱 모델 나열
  • 함수 나열

패키지별 모델 나열

dbt ls --select snowplow.*
snowplow.snowplow_base_events
snowplow.snowplow_base_web_page_context
snowplow.snowplow_id_map
snowplow.snowplow_page_views
snowplow.snowplow_sessions
...

태그 이름별 테스트 나열

dbt ls --select tag:nightly --resource-type test
my_project.schema_test.not_null_orders_order_id
my_project.schema_test.unique_orders_order_id
my_project.schema_test.not_null_products_product_id
my_project.schema_test.unique_products_product_id
...

인크리멘탈 모델의 스키마 테스트 나열

dbt ls --select config.materialized:incremental,test_type:schema
model.my_project.logs_parsed
model.my_project.events_categorized

JSON 출력 나열

dbt ls --select snowplow.* --output json
{"name": "snowplow_events", "resource_type": "model", "package_name": "snowplow",  ...}
{"name": "snowplow_page_views", "resource_type": "model", "package_name": "snowplow",  ...}
...

커스텀 키가 있는 JSON 출력 나열

dbt ls --select snowplow.* --output json --output-keys "name resource_type description"
{"name": "snowplow_events", "description": "This is a pretty cool model",  ...}
{"name": "snowplow_page_views", "description": "This model is even cooler",  ...}
...

시맨틱 모델 나열

orders 시맨틱 모델의 업스트림에 있는 모든 리소스를 나열하세요:

dbt ls -s +semantic_model:orders

파일 경로 나열

dbt ls --select snowplow.* --output path
models/base/snowplow_base_events.sql
models/base/snowplow_base_web_page_context.sql
models/identification/snowplow_id_map.sql
...

함수 나열

프로젝트의 모든 함수를 나열하세요:

dbt list --select "resource_type:function" # or dbt ls --resource-type function
jaffle_shop.area_of_circle
jaffle_shop.whoami

더 알아보기 (Learn more)