天天看点

Kettle连接Clickhouse 自定义插件遇到的问题:注意:

当前环境:

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 

<assembly
        xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
    <id>bin</id>
    <formats>
        <format>zip</format>
    </formats>
    <fileSets>
        <fileSet>
            <directory>${project.build.directory}</directory>
            <outputDirectory>/</outputDirectory>
            <includes>
                <include>*.jar</include>
            </includes>
        </fileSet>
    </fileSets>
    <dependencySets>
        <dependencySet>
            <outputDirectory>lib/</outputDirectory>
            <useProjectArtifact>false</useProjectArtifact>
        </dependencySet>
    </dependencySets>
</assembly>
           

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     

欢迎各位大神二次开发,积极献策。

继续阅读