hive 之 get_json_object 函数使用
Posted 闭关苦炼内功
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了hive 之 get_json_object 函数使用相关的知识,希望对你有一定的参考价值。
1)数据
["name":"大郎","sex":"男","age":"25","name":"西门庆","sex":"男","age":"47"]
2)取出第一个json对象
select get_json_object('["name":"大郎","sex":"男","age":"25","name":"西门庆","sex":"男","age":"47"]','$[0]');
结果是:
"name":"大郎","sex":"男","age":"25"
3)取出第一个json的age字段的值
SELECT get_json_object('["name":"大郎","sex":"男","age":"25","name":"西门庆","sex":"男","age":"47"]',"$[0].age");
结果是:
25
- 取出第1个json对象
select get_json_object('["name":"大郎","sex":"男","age":"25","name":"西门庆","sex":"男","age":"47"]','$[0]');
- 取出第2个json对象
select get_json_object('["name":"大郎","sex":"男","age":"25","name":"西门庆","sex":"男","age":"47"]','$[1]');
- 取出第1个json对象的age字段的值
select get_json_object('["name":"大郎","sex":"男","age":"25","name":"西门庆","sex":"男","age":"47"]','$[0].age');
- 取出第2个json对象的name字段的值
select get_json_object('["name":"大郎","sex":"男","age":"25","name":"西门庆","sex":"男","age":"47"]','$[1].name');
以上是关于hive 之 get_json_object 函数使用的主要内容,如果未能解决你的问题,请参考以下文章
hive 踩坑 get_json_object 返回NULL或部分可解析部分解析不了