Data Engineering/SQL Skin

Hive csv export/import

quantapia 2019. 8. 8. 18:13

이번엔 data migration의 가장 기본적인 csv export / import 방법을 소개합니다.

 

1. hive export

hive > insert overwrite local directory '/home/user/temp'

row format delimited fields terminated by ','

select * from scema.tb_import_test where base_dt = '2019-07-01';

 

2. table create

create table schema.tb_import_test (

guid string,

uuid string

.

.

.)

partitioned by (base_dt string)

row format delimited fields terminated by ','

stored as textfile

 

위 두줄이 없으면  아래 3번 수행 시 하나의 컬럼에 모든 데이터가 들어갑니다.

 

3. import 

hive>load data local inpath '/home/user/temp/'

overwrite into table schema.tb_import_test

partition (base_dt='2019-07-01');

 

 

4. data validation

select * from schema.tb_import_test