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
參考文章