1.新建一个java项目
在pom文件中添加依赖,可参考下列pom文件
创建以下代码文件
②:添加clickhouse Connector
在resource下新建META-INF/services 目录,在此目录下新建com.facebook.presto.spi.Plugin文件,在文件中添加com.facebook.presto.plugin.clickhouse.ClickhousePlugin,如下图
这一步主要是为了ConnectorFactory能识别clcikhouse的Connector
打包
上传
将上述修改好的项目打成jar
在presto安装目录的plugin目录下新建clickhouse目录
[admin@test-bd-k8s01~]$ mkdir /home/admin/program/presto/plugin/clickhouse
将打好的jar上传至该目录
然后在catalog下新建clickhouse.properties
vim /home/admin/program/presto/etc/catalog/clickhouse.properties
#写入clickhouse的连接信息
connector.name=clickhouse
connection-url=jdbc:clickhouse://ip:8123
connection-user=
connection-password=
然后前台启动presto
如果出现server started证明clickhouse Connector注册成功
提示:如果启动中出现报错 ERROR main com.facebook.presto.server.PrestoServer No factory for connector clickhouse
那么一定是
②:添加clickhouse Connector
这一步没有做好 META-INF/services 是两层目录,虽然最后显示的是META-INF.services.
最后测试
java -jar presto --server test-bd-k8s01:9999 --catalog clickhouse --schema default
[admin@test-bd-k8s01 presto]$ java -jar presto --server test-bd-k8s01:9999 --catalog clickhouse --schema default
presto:default> show tables;
Table
--------------
ontime_all
ontime_local
(2 rows)
Query 20200415_062000_00001_gqcvv, FINISHED, 1 node
Splits: 19 total, 19 done (100.00%)
0:02 [2 rows, 56B] [0 rows/s, 27B/s]
presto:default> select 1;
_col0
-------
1
(1 row)
Query 20200415_062013_00003_gqcvv, FINISHED, 1 node
Splits: 17 total, 17 done (100.00%)
0:00 [0 rows, 0B] [0 rows/s, 0B/s]
presto:default> select * from ontime_local;
flightdate | year
------------+------
2002-10-12 | 2003
(1 row)
Query 20200415_062028_00004_gqcvv, FINISHED, 1 node
Splits: 17 total, 17 done (100.00%)
0:00 [1 rows, 0B] [2 rows/s, 0B/s]
测试成功!