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:空白

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

你可能感兴趣的:(数据分析,数据挖掘)