Presto Functions


1 求数组长度

cardinality(x) → bigint
Returns the cardinality (size) of the array x
eg: select cardinality(array[1,24,3])  
result: 3

2 获取数组第一个元素(下标从1开始)

The [] operator is used to access an element of an array and is indexed starting from one

eg:select array[1,24,3][1]
result: 1

3,数组是否包含某个元素

contains(x, element) → boolean
Returns true if the array x contains the element

eg:select contains(array[1,24,3],3)
result: true

4,数组拼接

concat(array1, array2, ..., arrayN) → array
Concatenates the arrays array1, array2, ..., arrayN. 
This function provides the same functionality as the SQL-standard 
concatenation operator (||)
eg:select concat(array[1,2,3], array[2,3])
result:    [1, 2, 3, 2, 3]

5, 删除数组中元素

array_remove(x, element) → array
Remove all elements that equal element from array x.
eg:select array_remove(array[1,2,3], 2)
result: [1, 3]

6,数组拼接为字符串

array_join(x, delimiter, null_replacement) → varchar
Concatenates the elements of the given array using the delimiter 
and an optional string to replace nulls.
eg:select array_join(array[1,2,3],',')
result:1,2,3
eg:select select array_join(array[1,2,3, null],',','-')
result:1,2,3,-

7, json 解析函数

json_extract(json, json_path) → json
Evaluates the JSONPath-like expression json_path on 
json (a string containing JSON) and returns the result as a JSON string:
eg:SELECT json_extract('{"store":{"book":2}}', '$.store.book');
result:2
eg:SELECT json_extract(json_extract('{"store":{"book":{"book1":3}}}', '$.store.book'),'$.book1');
result:3

8, json 解析函数

json_extract_scalar(json, json_path) → varchar
Like json_extract(), but returns the result value as a string
 (as opposed to being encoded as JSON). The value referenced by json_path
 must be a scalar (boolean, number or string):
eg:SELECT json_extract_scalar('{"store":{"book":{"book1":"hello"}}}', '$.store.book.book1');
result:hello
eg:SELECT json_extract_scalar('{"store":{"book":{"book1":[1,2,3]}}}', '$.store.book.book1[0]');
result:1
eg:SELECT json_extract_scalar('{"store":{"book":{"book1":[1,2,3]}}}', '$.store.book.book1'); 
reuslt:空白

觉得不错扫头像,关注我的公众号,获取更多大数据技能

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值