메뉴 건너뛰기

Cloudera, BigData, Semantic IoT, Hadoop, NoSQL

Cloudera CDH/CDP 및 Hadoop EcoSystem, Semantic IoT등의 개발/운영 기술을 정리합니다. gooper@gooper.com로 문의 주세요.


hive json serde사용법

총관리자 2014.04.17 14:07 조회 수 : 1196

1. hive-json-serde-0.2.jar다운로드 한다.

 -> https://code.google.com/p/hive-json-serde/downloads/list

 

2. hive의 lib 디렉토리로 옮긴다.

cp hive-json-serde-0.2.jar.jar /home/hadoop/hive/lib/hive-json-serde-0.2.jar

 

3. data준비(Test.json)

{"field1":"data1","field2":100,"field3":"more data1","field4":123.001}
{"field1":"data2","field2":200,"field3":"more data2","field4":123.002}
{"field1":"data3","field2":300,"field3":"more data3","field4":123.003}
{"field1":"data4","field2":400,"field3":"more data4","field4":123.004}

4.  hive shell에서 jar파일등록

hive> add jar /home/hadoop/hive/lib/hive-json-serde-0.2.jar;
Added /home/hadoop/hive/lib/hive-json-serde-0.2.jar to class path
Added resource: /home/hadoop/hive/lib/hive-json-serde-0.2.jar

5. json serde를 사용하는 table생성

hive> create table my_table(field1 string, field2 int, field3 string, field4 double)
    > row format serde 'org.apache.hadoop.hive.contrib.serde2.JsonSerde';

 

6. data load

hive> load data local inpath '/home/hadoop/hadoop/working/Test.json' into table my_table;
Copying data from file:/home/hadoop/hadoop/working/Test.json
Copying file: file:/home/hadoop/hadoop/working/Test.json
Loading data to table default.my_table
Table default.my_table stats: [num_partitions: 0, num_files: 1, num_rows: 0, total_size: 287, raw_data_size: 0]

7.  my_table조회

hive> select * from my_table;
OK
field1 field2 field3 field4
data1 100 more data1 123.001
data2 200 more data2 123.002
data3 300 more data3 123.003
data4 400 more data4 123.004
Time taken: 0.188 seconds, Fetched: 4 row(s)



 

번호 제목 날짜 조회 수
47 Hive Query Examples from test code (2 of 2) 2014.03.26 11464
46 insert hbase by hive ... error occured after 5 hours..HMaster가 뜨지 않는 장애에 대한 복구 방법 2014.04.29 7236
45 hive 2.0.1 설치및 mariadb로 metastore 설정 2016.06.03 5292
44 Hive 사용법 및 쿼리 샘플코드 2013.03.07 3079
43 Hive+mysql 설치 및 환경구축하기 file 2013.03.07 2797
42 banana pi에 hive 0.13.1+mysql(metastore)설치 file 2014.09.09 2485
41 Hive java connection 설정 file 2013.04.01 2168
40 java.lang.RuntimeException: org.apache.hadoop.hive.ql.metadata.HiveException: Hive Runtime Error: Unable to deserialize reduce input key from...오류해결방법 2015.06.16 1968
39 hive에서 생성된 external table에서 hbase의 table에 값 insert하기 2014.04.11 1819
38 index생성, 삭제, 활용 2014.04.25 1765
37 FAILED: IllegalStateException Variable substitution depth too large: 40 오류발생시 조치사항 2014.08.19 1595
36 upsert구현방법(년-월-일 파티션을 기준으로) 및 테스트 script file 2018.07.03 1573
35 hiverserver2기동시 connection refused가 발생하는 경우 조치방법 2014.05.22 1558
34 json 값 다루기 2014.04.17 1325
33 schema설정없이 hive를 최초에 실행했을때 발생하는 오류메세지및 처리방법 2016.09.25 1299
32 external partition table생성및 data확인 2014.04.03 1297
31 sequence한 번호 생성방법 2014.04.25 1252
30 json으로 존재하는 데이터 parsing하기 2019.03.25 1249
29 Caused by: java.net.URISyntaxException: Relative path in absolute URI: ${system:java.io.tmpdir%7D/$%7Bsystem:user.name%7D오류발생시 조치사항 2016.06.03 1246
» json serde사용법 2014.04.17 1196
위로