2016-07-06 1 views

답변

0

하이브 버전이 0.14 이상이면 CSV Serde (https://cwiki.apache.org/confluence/display/Hive/CSV+Serde)를 사용할 수 있습니다. 이 SerDe에 대한 DEFAULT_QUOTE_CHARACTER는 이전 하이브 버전이있는 경우

가 수동으로 https://github.com/ogrodnek/csv-serde

는 것은 Serde 이것은 매우 큰 문제가되지 않습니다. 문자열로 배열을 취급합니다, 당신은 변환 할 수 있습니다이 serde을 추가하려고 "입니다 배열 컬럼을 선택하고 또는 같은 추가적인 뷰를 작성할 때

예 :.. I 텍스트 파일을 생성하고 테이블 위치에 넣어

DROP TABLE my_table; 
CREATE EXTERNAL TABLE my_table(col1 int , col2 string, col3 int) 
row format SERDE 'org.apache.hadoop.hive.serde2.OpenCSVSerde' 
stored as textfile; 

파일 내용 : 이제

23,"we,are",100 
23,"you,are",100 

, 데이터를 얻을 :

hive> create view my_table_view as select col1, split(col2,",") as col2, col3 from my_table; 
OK 
Time taken: 0.427 seconds 
hive> select * from my_table_view; 
OK 
23  ["we","are"] 100 
23  ["you","are"] 100 
Time taken: 0.369 seconds, Fetched: 2 row(s) 

--select 배열 요소 :

hive> select col1,col2[0] as col2_1, col2[1] as col2_2, col3 from my_table_view; 
OK 
23  we  are  100 
23  you  are  100 
Time taken: 0.09 seconds, Fetched: 2 row(s) 

hive> select col1, split(col2,",") as col2, col3 from my_table; 
OK 
23  ["we","are"] 100 
23  ["you","are"] 100 

은 또한 당신이보기를 만들 수 있습니다

+0

테이블 및로드 데이터 샘플 ddl 줄 수 ... –

+0

완료. 내 개선 된 대답을 참조하십시오 – leftjoin

+0

배열을 포함하는 테이블을 만들지 만, 어쨌든 serde는 문자열로 취급합니다. 이것은 동일하게 작동합니다 : CREATE EXTERNAL TABLE my_table (col1 int, col2 array , col3 int) ... – leftjoin

관련 문제