메뉴 건너뛰기

Bigdata, Semantic IoT, Hadoop, NoSQL

Bigdata, Hadoop ecosystem, Semantic IoT등의 프로젝트를 진행중에 습득한 내용을 정리하는 곳입니다.
필요한 분을 위해서 공개하고 있습니다. 문의사항은 gooper@gooper.com로 메일을 보내주세요.


hive json serde사용법

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

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)



 

번호 제목 글쓴이 날짜 조회 수
110 upsert구현방법(년-월-일 파티션을 기준으로) 및 테스트 script file 총관리자 2018.07.03 1220
109 Caused by: java.net.URISyntaxException: Relative path in absolute URI: ${system:java.io.tmpdir%7D/$%7Bsystem:user.name%7D오류발생시 조치사항 총관리자 2016.06.03 1141
» json serde사용법 총관리자 2014.04.17 1140
107 sequence한 번호 생성방법 총관리자 2014.04.25 1123
106 spark stream처리할때 두개의 client프로그램이 동일한 checkpoint로 접근할때 발생하는 오류 내용 총관리자 2018.01.16 1115
105 hive job실행시 meta정보를 원격의 mysql에 저장하는 경우 설정방법 총관리자 2014.05.28 1088
104 external partition table생성및 data확인 총관리자 2014.04.03 1072
103 Hive Query Examples from test code (1 of 2) 총관리자 2014.03.26 1050
102 impala 설치/설정 총관리자 2016.06.03 1029
101 "Initial job has not accepted any resources; check your cluster UI to ensure that workers are registered and have sufficient resources"오류 발생시 조치사항 총관리자 2016.05.25 1027
100 hive에서 insert overwrite directory.. 로 하면 default column구분자는 'SOH'혹은 't'가 됨 총관리자 2014.05.20 999
99 json으로 존재하는 데이터 parsing하기 총관리자 2019.03.25 973
98 unique한 값 생성 총관리자 2014.04.25 888
97 Hive JDBC Connection과 유형별 에러및 필요한 jar파일 총관리자 2021.05.24 827
96 dual table만들기 총관리자 2014.05.16 824
95 hive query에서 mapreduce돌리지 않고 select하는 방법 총관리자 2014.05.23 810
94 oracle to hive data type정리표 총관리자 2018.08.22 764
93 beeline실행시 User: root is not allowed to impersonate오류 발생시 조치사항 총관리자 2016.06.03 759
92 hive metastore ERD file 총관리자 2018.09.20 728
91 [Impala 3.2버젼]compute incremental stats db명.테이블명 수행시 ERROR: AnalysisException: Incremental stats size estimate exceeds 2000.00MB. 오류 발생원인및 조치방안 gooper 2022.11.30 697

A personal place to organize information learned during the development of such Hadoop, Hive, Hbase, Semantic IoT, etc.
We are open to the required minutes. Please send inquiries to gooper@gooper.com.

위로