Presto 简要介绍
presto是一个分布式的sql交互式查询引擎,基于内存的,可以达到hive查询效率的5到10倍,支持多种数据源的秒级查询。另外除了基于内存之外,还有优化如下:
- 向量计算
- 动态编译执行计划
- 优化的ORC和Parquet Reader技术
常用时间函数
参考https://prestodb.io/docs/current/functions/datetime.html
Operator | Example | Result |
---|---|---|
+ |
date '2012-08-08' + interval '2' day |
2012-08-10 |
+ |
time '01:00' + interval '3' hour |
04:00:00.000 |
+ |
timestamp '2012-08-08 01:00' + interval '29' hour |
2012-08-09 06:00:00.000 |
+ |
timestamp '2012-10-31 01:00' + interval '1' month |
2012-11-30 01:00:00.000 |
+ |
interval '2' day + interval '3' hour |
2 03:00:00.000 |
+ |
interval '3' year + interval '5' month |
3-5 |
- |
date '2012-08-08' - interval '2' day |
2012-08-06 |
- |
time '01:00' - interval '3' hour |
22:00:00.000 |
- |
timestamp '2012-08-08 01:00' - interval '29' hour |
2012-08-06 20:00:00.000 |
- |
timestamp '2012-10-31 01:00' - interval '1' month |
2012-09-30 01:00:00.000 |
- |
interval '2' day - interval '3' hour |
1 21:00:00.000 |
- |
interval '3' year - interval '5' month |
2-7 |
Json解析函数
presto 对json的处理函数是 json_array_get和 json_extract,其中json_extract与hive的get_json_object用法一致。
-- 用 json_array_get()取出jsonArray的第一个元素
select json_array_get(xjson,0)
from
employee
limit 1;
-- presto查询结果: {"name":"王二","sex":"男","age":"25"}
-- 用 json_extract() 在 {"name":"王二","sex":"男","age":"25"} 中查询 "王二"的年龄
-- json_extract 和 hive中的get_json_object类似
select json_extract('{"name":"王二","sex":"男","age":"25"}', '$.age')
其他更详细参考https://prestodb.io/docs/current/functions/json.html