티스토리 뷰
hive 에서 json 문자열을 map으로 변환하는 방법은 다음과 같다.
<json 문자열의 중괄호 삭제>
SELECT substring("{'a':'1','b':'2'}", 2, length("{'a':'1','b':'2'}")-2);
<맵으로 변환>
SELECT str_to_map(substring("{'a':'1','b':'2'}", 2, length("{'a':'1','b':'2'}")-2), ",", ":");
<explode 를 이용하여 테이블로 사용>
SELECT explode(str_to_map(substring("{'a':'1','b':'2'}", 2, length("{'a':'1','b':'2'}")-2), ",", ":")) as (key,value);
<처리 결과>
hive> SELECT substring("{'a':'1','b':'2'}", 2, length("{'a':'1','b':'2'}")-2);
OK
'a':'1','b':'2'
Time taken: 0.045 seconds, Fetched: 1 row(s)
hive>
> SELECT str_to_map(substring("{'a':'1','b':'2'}", 2, length("{'a':'1','b':'2'}")-2), ",", ":");
OK
{"'b'":"'2'","'a'":"'1'"}
Time taken: 0.052 seconds, Fetched: 1 row(s)
hive>
> SELECT explode(str_to_map(substring("{'a':'1','b':'2'}", 2, length("{'a':'1','b':'2'}")-2), ",", ":")) as (key,value);
OK
'b' '2'
'a' '1'
Time taken: 0.048 seconds, Fetched: 2 row(s)
'빅데이터 > hive' 카테고리의 다른 글
[hive] drop table partitions 의 null 오류 (0) | 2017.12.21 |
---|---|
[hive] 정규식을 이용하여 문자열 검색 (0) | 2017.12.14 |
[hive] 하이브 성능 개선#1 - CBO, Stat 를 이용하여 통계 쿼리 성능 개선 (0) | 2017.11.29 |
[hive] dynamic partition 에서 리듀서를 하나만 사용하는 오류 수정 (0) | 2017.11.15 |
[Hive][Tez] TEZ에서 파일머지를 처리하는 중 App master already running a DAG 오류 처리 방법 (0) | 2017.11.10 |
- Total
- Today
- Yesterday
- emr
- 다이나믹
- SPARK
- 백준
- 오류
- error
- 하이브
- 파이썬
- SQL
- Linux
- HDFS
- yarn
- Python
- S3
- hbase
- nodejs
- oozie
- 정올
- HIVE
- bash
- Tez
- Hadoop
- java
- ubuntu
- build
- 알고리즘
- airflow
- AWS
- mysql
- 하둡
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |