sybn sybn-util 项目说明文档 - 基于java的跨数据库联合查询

对比 hive jdbc 和 presto jdbc

2021-01-04
sybn

本工具包兼容 hive jdbc 和 presto jdbc. 对于同一张 hive 表, 使用 hive jdbc 和 presto jdbc 的差异如下:

准备环境

  • maven
<dependency>
    <groupId>cn.linpengfei.sybnutil</groupId>
    <artifactId>dbutil-dao</artifactId>
    <version>0.3.27-SNAPSHOT</version>
</dependency>

<dependency>
    <groupId>com.facebook.presto</groupId>
    <artifactId>presto-jdbc</artifactId>
    <version>0.229</version>
</dependency>

<dependency>
    <groupId>org.apache.hive</groupId>
    <artifactId>hive-jdbc</artifactId>
    <version>3.1.1</version>
</dependency>
  • properties
sql.hive_bi_dw=jdbc:hive2://10.0.0.15:10000/bi_dw
sql.hive_bi_dw.databaseAlias=bi_dw_hive
sql.hive_bi_dw.user=sybn
sql.hive_bi_dw.password=sybn2021
sql.hive_bi_dw.driverClassName=org.apache.hive.jdbc.HiveDriver

sql.presto_bi_dw=jdbc:presto://10.0.0.15:9090/hive/bi_dw
sql.presto_bi_dw.databaseAlias=bi_dw_presto
sql.presto_bi_dw.user=sybn
sql.presto_bi_dw.password=sybn2021
sql.presto_bi_dw.driverClassName=com.facebook.presto.jdbc.PrestoDriver

非聚合查询 select * from table

use bi_dw_presto;
-- show tables 
select * from fact_sch_plan_detail where type = 111 limit 10

use bi_dw_hive;
-- show tables 
select * from fact_sch_plan_detail where type = 111 limit 10

  • 结论

只查询少量非聚合数据时, 性能接近.

查询所有字段时, hive 会附带上表名. 查询指定字段时, 两者效果一致.

聚合查询 select count(*) from table

use bi_dw_presto;
-- show tables 
select count(*) from fact_sch_plan_detail where type = 111
use bi_dw_hive;
-- show tables 
select count(*) from fact_sch_plan_detail where type = 111

  • 结论

返回格式一致. presto (0.75秒) 比 hive(20.97秒) 快几十倍.

注: 追求聚合查询速度时, clickhouse 和 es 可以比 presto 再提速几倍.

其他差异

  • presto 的很多函数, 比如 date_add 和 array 相关函数, 与 hive 的写法不一致.

 本工具包为半理解型sql解析, 没有解决不同数据库之间的具体的函数差异问题, 具体请查询官方文档.

  • presto 不支持跨类型比较

比如: 数字与文本比大小 (a=1 合法时 a=’1’ 会报错).

本工具包已经部分解决, 当比较符右边为常量是, 左边的值会强制转化为右边的类型, 如果无法强制转换, 依然会报错.


Similar Posts

Comments

暂不开放评论! 可微信联系