Impala JSON函数

在impala 6.3 版本中加入JSON解析函数,此前的版本则没有提供JSON解析函数需要自己编译安装。

The following characters are supported in the selector JSON path:
$ : Denotes the root object
. : Denotes the child operator
[] : Denotes the subscript operator for array
* : Denotes the wildcard for [] or .

示例:

 SELECT GET_JSON_OBJECT ('{"a":true, "b":false, "c":true}', '$.*') result

result
 [true,false,true]




SELECT GET_JSON_OBJECT(t.json, '$.a.b.c') FROM (VALUES (
 ('{"a": {"b": {"c": 1}}}' AS json),
 ('{"a": {"b": {"c": 2}}}'),
 ('{"a": {"b": {"c": 3}}}')
)) t


num
  1
  2
  3


SELECT GET_JSON_OBJECT(t.json, '$.a') a,
 GET_JSON_OBJECT(t.json, '$.b') b,
 GET_JSON_OBJECT(t.json, '$.c') c
FROM (VALUES (
 ('{"a":1, "b":2, "c":3}' AS json),
 ('{"b":2, "c":3}'),
 ('{"c":3}')
)) t

a	     b	    c
1	     2	    3
NULL	 2	    3
NULL	 NULL	3


SELECT GET_JSON_OBJECT(t.json, '$[1]'),
 GET_JSON_OBJECT(t.json, '$[*]')
FROM (VALUES (
 ('["a", "b", "c"]' AS json),
 ('["a", "b"]'),
 ('["a"]')
)) t

seq	items
 b	 ["a","b","c"]
 b	 ["a","b"]
 NULL	 a

参考:

https://docs.cloudera.com/documentation/enterprise/latest/topics/impala_misc_functions.html#misc_functions__get_json_object

https://github.com/nazgul33/impala-get-json-object-udf

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值