presto是一个分布式的sql交互式查询引擎。能够达到hive查询效率的5到10倍。支持多种数据源的秒级查询。html
presto是基于内存查询的,这也是它为何查询快的缘由。除了基于内存,presto还使用了java
从而优化查询的速度。mysql
https://prestodb.github.io/docs/current/git
由于咱们解析log最经常使用的就是json解析。
咱们单独说下json解析的方法。直接上代码:github
-- employee表的xjson字段,只有一条数据 [{"name":"王二","sex":"男","age":"25"},{"name":"李四","sex":"男","age":"47"}] |
取出"王二"的年龄:redis
hive sql为:sql
select get_json_object(xjson,'$.[0].age') from employee limit 1; |
hive 查询结果为: 25json
presto 对json的处理函数是 json_array_get() 和 json_extract()分布式
-- 咱们分步操做,先用 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') |
presto查询结果是:25