How to extract selected values from json string in Hive

最后都变了- 提交于 2019-12-05 08:11:28
select col1, get_json_object(col2,'$.variable1') as variable1,
get_json_object(col2,'$.variable2') as variable2,
get_json_object(col2,'$.variable3') as variable3 
from json_test

If you put your output into a table (say json_test), you can parse in this way. You can tweak your query too to obtain these results.

Output:

col1 |variable1 |variable2 |variable3 |
-----|----------|----------|----------|
A    |123       |456       |789       |
B    |222       |333       |444       |
Ramanpreet Kaur Nannre

Step1:

create table in HIVE
create table json_student(student string)  

-----load data in this table
hive>select * from json_variable;`enter code here`
       {"col1":"A","variable1":123,"variable2":456,"variable3":789}
       {"col1":"B","variable1":222,"variable2":333,"variable3":444}

Step2:

create table  json_variable1(col1 string,variable1 int,variable2 int,variable3 int);

Step3:

insert overwrite table json_variable1 
select get_json_object(variable,'$.col1'),get_json_object(variable,'$.variable1'),get_json_object(variable,'$.variable2'),get_json_object(variable,'$.variable3') from json_variable;

hive> Select * from json_variable1;    
A       123     456     789`    `
B       222     333     444`

`
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!