hive与presto解析json中的字段值

4 篇文章 3 订阅

案例json_str 

{
	"item": {
		"tabid": "新人专享",
		"channelid": "APP",
		"ass_rule": [{
			"lv1": "ass",
			"lv2": "mpp"
		}]
	},
	"name": "99美妆节"
}

一、hive解析get_json_object

语法:get_json_object(string json_string, string path) → varchar

(1)get单层json

hive> select get_json_object(json_str, '$.name');

hive> 99美妆节

(2)get多层json

hive> select get_json_object(json_str, '$.item.tabid');

hive> 新人专享

(3)get json数组

hive> select get_json_object(json_str, '$.item.ass_rule[0]');

hive>  {"lv1":"ass","lv2":"mpp"}

二、presto解析json_extract_scalar

语法:json_extract_scalar(string json, string json_path) → varchar

语法:json_extract(string json, string json_path) → json

(1)get单层json

hive> select json_extract_scalar(json_str, '$.name');

hive> 99美妆节

(2)get多层json

hive> select json_extract_scalar(json_str, '$.item.tabid');

hive>  新人专享

(3)get json数组

          注意这里用的是json_extract

hive> select json_extract(json_str, '$.item.ass_rule[0]');

hive>  {"lv1":"ass","lv2":"mpp"}

参考:JSON Functions and Operators — Presto 0.273.3 Documentationhttps://prestodb.io/docs/current/functions/json.html

  • 7
    点赞
  • 28
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值