Skip to content

Instantly share code, notes, and snippets.

@developer-sdk
Created April 12, 2017 12:31
Show Gist options
  • Select an option

  • Save developer-sdk/258b031b9b8dcafe0b83a9c86b83a657 to your computer and use it in GitHub Desktop.

Select an option

Save developer-sdk/258b031b9b8dcafe0b83a9c86b83a657 to your computer and use it in GitHub Desktop.
hive complex type table
-- 테이블 생성
CREATE TABLE complex_type_table
(
user_id BIGINT,
new_item ARRAY<STRUCT<product_id:BIGINT, product_name:STRING, timestamps:STRING>>
)
ROW FORMAT DELIMITED
FIELDS TERMINATED BY '\t'
COLLECTION ITEMS TERMINATED BY ','
MAP KEYS TERMINATED BY '='
;
-- complex.txt 내용
1 10=pencil_1=2017-01-01,11=pencil_2=2017-01-01
2 20=eraser_1=2017-01-02,21=eraser_2=2017-01-02
-- 데이터 로드
LOAD DATA LOCAL INPATH './complex.txt' OVERWRITE INTO TABLE complex_type_table;
-- 내용 확인
> select * from complex_type_table;
OK
1 [{"product_id":10,"product_name":"pencil_1","timestamps":"2017-01-01"},{"product_id":11,"product_name":"pencil_2","timestamps":"2017-01-01"}]
2 [{"product_id":20,"product_name":"eraser_1","timestamps":"2017-01-02"},{"product_id":21,"product_name":"eraser_2","timestamps":"2017-01-02"}]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment