Presto Functions

Posted -早起的码农

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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:空白

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

以上是关于Presto Functions的主要内容,如果未能解决你的问题,请参考以下文章

在 Presto 中找出值的数据类型

AWS Athena (Presto) - 如何将时间戳格式化为日期格式?

Presto SQL date_format 提取一年中的一周

使用presto的kafka连接器时presto在哪里存储kafka数据

PHP 在functions.php中使用WordPress自定义更多文本

php Cambiar el“阅读更多”desde el functions.php