Cloudera Hive 설정

Cloudera Hive 설정

dbt-hive 플러그인에서 표준 모델 설정에 더해 테이블을 구성할 때 쓸 수 있는 옵션들을 소개해요. 파티셔닝, 파일 포맷, 저장 위치, 외부 테이블 여부 등 하이브特有의 설정을 모델에 적용하는 방법을 정리해요.

출처: dbt 공식 문서

본문

테이블 구성하기

모델을 table로 materialize할 때 표준 모델 설정에 더해 dbt-hive 플러그인만의 추가 옵션을 몇 가지 쓸 수 있어요.

옵션 설명 필수? 예시
partition_by 컬럼 기준으로 파티션을 나눠요. 보통 파티션마다 디렉터리가 하나씩 생겨요 아니요 partition_by=['name']
clustered_by 파티션된 컬럼의 두 번째 수준 분할 아니요 clustered_by=['age']
file_format 테이블의 기본 저장 포맷. 지원 포맷은 https://cwiki.apache.org/confluence/display/Hive/FileFormats 참고 아니요 file_format='PARQUET'
location 저장 위치. 보통 hdfs 경로 아니요 LOCATION='/user/etl/destination'
comment 테이블에 대한 설명 아니요 comment='this is the cleanest model'
external 외부 테이블인지 여부 - true / false 아니요 external=true
tbl_properties 테이블과 함께 키/값 쌍으로 저장할 수 있는 메타데이터 아니요 tbl_properties="('dbt_test'='1')"
table_type 테이블의 유형을 나타내요 아니요 table_type="iceberg"

Incremental 모델

Incremental 모델에서 지원하는 모드는 다음과 같아요.

  • append (기본값): 기존 데이터를 업데이트하거나 덮어쓰지 않고 새 레코드만 삽입해요.
  • insert_overwrite: 새 레코드는 데이터를 삽입해요. partition 절과 함께 쓰면 변경된 레코드는 데이터를 업데이트하고 새 레코드는 삽입해요.

예시: partition_by 설정 사용하기

hive_partition_by.sql

{{
    config(
        materialized='table',
        unique_key='id',
        partition_by=['city'],
    )
}}

with source_data as (
     select 1 as id, "Name 1" as name, "City 1" as city,
     union all
     select 2 as id, "Name 2" as name, "City 2" as city,
     union all
     select 3 as id, "Name 3" as name, "City 2" as city,
     union all
     select 4 as id, "Name 4" as name, "City 1" as city,
)

select * from source_data

위 예시에서 partition_by와 그 외 설정을 가진 샘플 테이블을 만들었어요. partition_by 옵션을 쓸 때 한 가지 주의할 점은, 위 쿼리의 city 컬럼처럼 select 쿼리에서 partition_by 옵션에 쓴 컬럼 이름이 항상 마지막에 와야 한다는 거예요. partition_by 절이 select 문의 마지막 컬럼과 같지 않으면 Hive는 모델을 만들려고 할 때 오류를 표시해요.

더 알아보기 (Learn more)