Apache Drill - join HBase and RDBMs

HBase作为Nosql的常用系统之一,在很多大数据应用/平台中广泛使用。例如通过Spark统计后将结果存放到HBase中。通常统计结果还需要进一步和元数据或者字典表关联从而得到最终结果显示,这意味着可能需要将HBase数据跟RDBMS关联查询。
有两种方案:

  • 通过后台服务分别调用HBase和数据库的数据,通过程序做关联;
  • 或者通过现成的查询引擎用SQL对HBase和数据库数据做Join。
    后一方案使用SQL查询更为通用。SQL-on-HADOOP有很多选择,例如Presto,Phoenix,Drill。目前看下来Presto不支持HBase,Phoenix只支持HBase,只有Drill可作为备选方案。

Drill连接HBase的issue

http://blog.sina.com.cn/s/blog_76923bd80102wp99.html

下载HBASE Shaded Client 替换即可,下载地址: http://mvnrepository.com/artifact/org.apache.hbase/hbase-shaded-client/1.2.3
hbase-annotations-1.1.3.jar
hbase-client-1.1.3.jar
hbase-common-1.1.3.jar
hbase-protocol-1.1.3.jar
替换成
hbase-shaded-client-1.2.3.jar

HBase表

hbase(main):001:0> scan 'test'
ROW                                                   COLUMN+CELL                                                                                                                                                  
 x00001|2018-09-18 12|platform|android                column=f:value, timestamp=1538038106882, value=12                                                                                                            
 x00001|2018-09-18 13|platform|android                column=f:value, timestamp=1538038118094, value=22                                                                                                            
 x00001|2018-09-18 14|platform|android                column=f:value, timestamp=1538038123616, value=22                                                                                                            
 x00001|2018-09-18 15|platform|android                column=f:value, timestamp=1538038134952, value=6                                                                                                             
 x00001|2018-09-18 16|platform|android                column=f:value, timestamp=1538038143047, value=10                                                                                                            
 x00001|2018-09-18 17|platform|android                column=f:value, timestamp=1538038153844, value=30                                                                                                            
6 row(s) in 0.0390 seconds

postgres

下载postgres驱动postgresql-9.4.1212.jre7.jar到jars/3rdparty/
创建新的storage:

{
  "type": "jdbc",
  "driver": "org.postgresql.Driver",
  "url": "jdbc:postgresql://localhost/postgres",
  "username": "postgres",
  "password": "111111",
  "enabled": true
}

创建测试表:

select * from platform
name    |description    |
--------|---------------|
android |google android |

Drill join

0: jdbc:drill:zk=local> select SPLIT(CONVERT_FROM(t.row_key, 'UTF8'), '|')[0] AS appk,
. . . . . . . . . . . > SPLIT(CONVERT_FROM(t.row_key, 'UTF8'), '|')[1] AS `hour`,
. . . . . . . . . . . > SPLIT(CONVERT_FROM(t.row_key, 'UTF8'), '|')[3] AS platform,
. . . . . . . . . . . > p.`description`,
. . . . . . . . . . . > cast(t.f.`value` as INT) as x FROM hbase.test t
. . . . . . . . . . . > inner join pg.test.platform p
. . . . . . . . . . . > on SPLIT(CONVERT_FROM(t.row_key, 'UTF8'), '|')[3] =  p.`name`;
+---------+----------------+-----------+-----------------+-----+
|  appk   |      hour      | platform  |   description   |  x  |
+---------+----------------+-----------+-----------------+-----+
| x00001  | 2018-09-18 12  | android   | google android  | 12  |
| x00001  | 2018-09-18 17  | android   | google android  | 30  |
| x00001  | 2018-09-18 16  | android   | google android  | 10  |
| x00001  | 2018-09-18 15  | android   | google android  | 6   |
| x00001  | 2018-09-18 14  | android   | google android  | 22  |
| x00001  | 2018-09-18 13  | android   | google android  | 22  |
+---------+----------------+-----------+-----------------+-----+

性能测试(todo)

posted @ 2018-09-27 22:08  wlu  阅读(748)  评论(1编辑  收藏  举报