目前環境:
clickhouse 19.15.1.1 (19年的老版本ch ,還未更新過)
kettle 8.1.0.0-365 (因為8.1對parquet 支援較好,是以選了這個版本)
目前問題:kettle -8 目前提供的JDBC 沒有clickhouse。 需要自己手寫插件,內建到kettle 系統。
前期準備:搜到過類似新增JDBC的文章,包括:官網提供的自定義連接配接的方法 和 神通資料庫的案例。
官網提示位址:https://help.pentaho.com/Documentation/8.1/Developer_Center/PDI/Extend/020
思路:即固定資料庫連接配接,讀取plugins目錄下的jar 包。
0.建立maven 工程 編輯pom.xml
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.pentaho</groupId>
<artifactId>pentaho-ce-jar-parent-pom</artifactId>
<version>8.1.0.0-365</version>
</parent>
<groupId>com.xxxxr</groupId>
<artifactId>MyDev</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>MyDev</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<eula-wrap_create-dist-phase></eula-wrap_create-dist-phase>
<eula-wrap_assign-deps-to-properties-phase></eula-wrap_assign-deps-to-properties-phase>
<mockito.version>1.10.19</mockito.version>
<pentaho-metadata.version>8.1.0.0-365</pentaho-metadata.version>
<eula-wrap_create-izpack-installer-jar-phase></eula-wrap_create-izpack-installer-jar-phase>
<pdi.version>8.1.0.0-365</pdi.version>
<eula-wrap_attach-dist-phase></eula-wrap_attach-dist-phase>
<junit.version>4.12</junit.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>xerces</groupId>
<artifactId>xercesImpl</artifactId>
<version>2.8.1</version>
</dependency>
<dependency>
<groupId>net.jpountz.lz4</groupId>
<artifactId>lz4</artifactId>
<version>1.2.0</version>
</dependency>
<dependency>
<groupId>ru.yandex.clickhouse</groupId>
<artifactId>clickhouse-jdbc</artifactId>
<version>0.1.50</version>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>pentaho-kettle</groupId>
<artifactId>kettle-core</artifactId>
<version>${pdi.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>net.jpountz.lz4</groupId>
<artifactId>lz4</artifactId>
<version>1.3.0</version>
</dependency>
<dependency>
<groupId>ru.yandex.clickhouse</groupId>
<artifactId>clickhouse-jdbc</artifactId>
<version>0.1.50</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<id>distro-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<appendAssemblyId>false</appendAssemblyId>
<descriptors>
<descriptor>src/main/assembly/assembly.xml</descriptor>
</descriptors>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
1. Clickhouse 類繼承一下接口
class ClickhouseDatabaseMeta extends BaseDatabaseMeta implements DatabaseInterface
2.Override其方法
包含 AccessTypeList、DefaultDatabasePort(對應用戶端預設接口)、supportsAutoInc()、SQLQueryFields 等, 挑能用到的重寫就可以
3. 添加assembly.xml
|
4.打jar包,并把所有依賴包打進去。上傳jar到 plugins 下 建立clickhouse-plugins檔案夾下。
同時 ,去 https://mvnrepository.com/ 下載下傳一個 clickhouse-jdbc的 jar 包 。放在 libswt /win64/下 。 和以往kettle依賴 mysql driver ,mssql driver 一樣的。 找不到下載下傳源也可以去下載下傳我上傳的 driver
重新開機 kettle 。測試 ok
遇到的問題:
一、
錯誤連接配接資料庫 [clickhouse] : org.pentaho.di.core.exception.KettleDatabaseException:
Error occurred while trying to connect to the database
Error connecting to database: (using class ru.yandex.clickhouse.ClickHouseDriver)
net/jpountz/lz4/LZ4Factory
Caused by: java.lang.NoClassDefFoundError: net/jpountz/lz4/LZ4Factory
Caused by: java.lang.ClassNotFoundException: net.jpountz.lz4.LZ4Factory
解決方法:添加pom依賴:
<dependency>
<groupId>net.jpountz.lz4</groupId>
<artifactId>lz4</artifactId>
<version>1.2.0</version>
</dependency>
<dependency>
<groupId>ru.yandex.clickhouse</groupId>
<artifactId>clickhouse-jdbc</artifactId>
<version>0.1.50</version>
</dependency>
注意,若是依賴性的問題讀不到。則把依賴添加的自己的plugins\pentaho-cassandra-plugin\lib下 ,或者 其他lib 類目錄下。
不同版本依賴路徑可能不一樣。靈活一點。
二、
錯誤連接配接資料庫 [c] : org.pentaho.di.core.exception.KettleDatabaseException:
Error occurred while trying to connect to the database
Error connecting to database: (using class ru.yandex.clickhouse.ClickHouseDriver)
Could not initialize class ru.yandex.clickhouse.response.ClickHouseLZ4Stream
jar包問題,打到一起解決了。
三、
Caused by: org.apache.http.conn.HttpHostConnectException: Connect to 10.96.149.53:8123 [/10.96.149.53] failed: Connection refused: connect
Caused by: java.net.ConnectException: Connection refused: connect
server port 問題,確定server 可以遠端通路即可
注意:
1.上傳我的v2版本jar包至plugin/clickhouse-plugin
2.上傳maven 的 driver v0.1.50 至 libswt/win64/
driver 版本 要和依賴一緻。
3.重新開機kettle8。
若還有問題,請留言評論,共同探讨解決,互相學習。
具體kettle To Clickhouse JDBC(KettleJDBCClickhouse )、以及clickhouse-jdbc.jar (Driver)已上傳至資源。請下載下傳新版本v2
github 源碼 : https://github.com/aaa8210/kettle2clickhouse
歡迎各位大神二次開發,積極獻策。