1. 首先安装presto
安装教程可以参考官网及下面这篇文章
官方文档
presto安装及连接mysql
完毕可以连接mysql测试一下是否安装成功
2. 下载presto-clickhouse
这里已有大佬实现presto-clickhouse的Connectors,我们直接下载来用就好
https://github.com/zeeshanabid94/presto/tree/presto-clickhouse/presto-clickhouse
3. 编译presto-clickhouse
我们只需要编译presto-clickhouse部分,这里有两种方式
直接在下载的项目里编译,不过有很多check,对maven、jdk版本进行检测,这些按照官网要求来,当然也可以在主pom中关掉check
也可以直接新建一个项目编译
这里我选择新建项目
①:新建项目,拷贝代码
这里我们选择新建一个项目,把下载的presto_clickhouse中的代码拷贝进去
②:添加clickhouse Connector
在resource下新建META-INF/services 目录,在此目录下新建com.facebook.presto.spi.Plugin文件,在文件中添加com.facebook.presto.plugin.clickhouse.ClickhousePlugin,如下图
这一步主要是为了ConnectorFactory能识别clcikhouse的Connector
③:修改pom文件
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>base_module</artifactId>
<groupId>idea_workspace</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>presto-clickhouse</artifactId>
<dependencies>
<!--- Clickhouse JDBC Driver -->
<dependency>
<groupId>ru.yandex.clickhouse</groupId>
<artifactId>clickhouse-jdbc</artifactId>
<version>0.1.50</version>
</dependency>
<dependency>
<groupId>com.facebook.presto</groupId>
<artifactId>presto-spi</artifactId>
<version>0.223</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.9.7</version>
</dependency>
<dependency>
<groupId>io.airlift</groupId>
<artifactId>log</artifactId>
<version>0.178</version>
</dependency>
<dependency>
<groupId>io.airlift</groupId>
<artifactId>configuration</artifactId>
<version>0.178</version>
</dependency>
<dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
<version>1</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>24.1-jre</version>
</dependency>
<dependency>
<groupId>com.google.inject</groupId>
<artifactId>guice</artifactId>
<version>4.2.0</version>
</dependency>
<dependency>
<groupId>com.facebook.presto</groupId>
<artifactId>presto-base-jdbc</artifactId>
<version>0.223</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.4.3</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
</excludes>
</filter>
</filters>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
<finalName>presto-clickhouse-0.223</finalName>
</build>
</project>
④:打包上传
将上述修改好的项目打成jar
在presto安装目录的plugin目录下新建clickhouse目录
mkdir /opt/soft/presto-server-0.223/plugin/clickhouse
将打好的jar上传至该目录
然后在catalog下新建clickhouse.properties
vim /opt/soft/presto-server-0.223/etc/catalog/clickhouse.properties
#写入clickhouse的连接信息
connector.name=clickhouse
connection-url=jdbc:clickhouse://ip:8123
connection-user=
connection-password=
然后前台启动presto
bin/launcher run
如果出现server started证明clickhouse Connector注册成功
下面用客户端测试
java -jar presto-cli-0.224-executable.jar --server localhost:9000 --catalog clickhouse --schema test
执行show tables;
如果出现表则成功,如果bin/launcher run 出现ClassNotFoundException异常则是打包过程有问题,看一下缺少什么包引入依赖重新打包即可