Skip to content

Commit 22a59be

Browse files
committed
clickhouse side table
1 parent b59af8e commit 22a59be

File tree

12 files changed

+555
-12
lines changed

12 files changed

+555
-12
lines changed
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<parent>
6+
<artifactId>sql.side.clickhouse</artifactId>
7+
<groupId>com.dtstack.flink</groupId>
8+
<version>1.0-SNAPSHOT</version>
9+
</parent>
10+
<modelVersion>4.0.0</modelVersion>
11+
12+
<artifactId>sql.side.all.clickhouse</artifactId>
13+
<name>clickhouse-all-side</name>
14+
15+
<packaging>jar</packaging>
16+
17+
<properties>
18+
<sql.side.clickhouse.core.version>1.0-SNAPSHOT</sql.side.clickhouse.core.version>
19+
</properties>
20+
21+
<dependencies>
22+
<dependency>
23+
<groupId>com.dtstack.flink</groupId>
24+
<artifactId>sql.side.clickhouse.core</artifactId>
25+
<version>${sql.side.clickhouse.core.version}</version>
26+
</dependency>
27+
</dependencies>
28+
29+
<build>
30+
<plugins>
31+
<plugin>
32+
<groupId>org.apache.maven.plugins</groupId>
33+
<artifactId>maven-shade-plugin</artifactId>
34+
<version>1.4</version>
35+
<executions>
36+
<execution>
37+
<phase>package</phase>
38+
<goals>
39+
<goal>shade</goal>
40+
</goals>
41+
<configuration>
42+
<artifactSet>
43+
<excludes>
44+
45+
</excludes>
46+
</artifactSet>
47+
<filters>
48+
<filter>
49+
<artifact>*:*</artifact>
50+
<excludes>
51+
<exclude>META-INF/*.SF</exclude>
52+
<exclude>META-INF/*.DSA</exclude>
53+
<exclude>META-INF/*.RSA</exclude>
54+
</excludes>
55+
</filter>
56+
</filters>
57+
</configuration>
58+
</execution>
59+
</executions>
60+
</plugin>
61+
62+
<plugin>
63+
<artifactId>maven-antrun-plugin</artifactId>
64+
<version>1.2</version>
65+
<executions>
66+
<execution>
67+
<id>copy-resources</id>
68+
<!-- here the phase you need -->
69+
<phase>package</phase>
70+
<goals>
71+
<goal>run</goal>
72+
</goals>
73+
<configuration>
74+
<tasks>
75+
<copy todir="${basedir}/../../../plugins/clickhouseallside">
76+
<fileset dir="target/">
77+
<include name="${project.artifactId}-${project.version}.jar"/>
78+
</fileset>
79+
</copy>
80+
81+
<move file="${basedir}/../../../plugins/clickhouseallside/${project.artifactId}-${project.version}.jar"
82+
tofile="${basedir}/../../../plugins/clickhouseallside/${project.name}-${git.branch}.jar"/>
83+
</tasks>
84+
</configuration>
85+
</execution>
86+
</executions>
87+
</plugin>
88+
</plugins>
89+
</build>
90+
91+
92+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
package com.dtstack.flink.sql.side.clickhouse;
20+
21+
import com.dtstack.flink.sql.side.FieldInfo;
22+
import com.dtstack.flink.sql.side.JoinInfo;
23+
import com.dtstack.flink.sql.side.SideTableInfo;
24+
import com.dtstack.flink.sql.side.rdb.all.RdbAllReqRow;
25+
import com.dtstack.flink.sql.util.DtStringUtil;
26+
import org.apache.flink.api.java.typeutils.RowTypeInfo;
27+
import org.apache.flink.shaded.guava18.com.google.common.collect.Maps;
28+
import org.slf4j.Logger;
29+
import org.slf4j.LoggerFactory;
30+
31+
import java.sql.Connection;
32+
import java.sql.DriverManager;
33+
import java.util.List;
34+
import java.util.Map;
35+
36+
37+
public class ClickhouseAllReqRow extends RdbAllReqRow {
38+
39+
private static final Logger LOG = LoggerFactory.getLogger(ClickhouseAllReqRow.class);
40+
41+
private static final String CLICKHOUSE_DRIVER = "ru.yandex.clickhouse.ClickHouseDriver";
42+
43+
public ClickhouseAllReqRow(RowTypeInfo rowTypeInfo, JoinInfo joinInfo, List<FieldInfo> outFieldInfoList, SideTableInfo sideTableInfo) {
44+
super(new ClickhouseAllSideInfo(rowTypeInfo, joinInfo, outFieldInfoList, sideTableInfo));
45+
}
46+
47+
@Override
48+
public Connection getConn(String dbURL, String userName, String password) {
49+
try {
50+
Class.forName(CLICKHOUSE_DRIVER);
51+
//add param useCursorFetch=true
52+
Map<String, String> addParams = Maps.newHashMap();
53+
addParams.put("useCursorFetch", "true");
54+
String targetDbUrl = DtStringUtil.addJdbcParam(dbURL, addParams, true);
55+
return DriverManager.getConnection(targetDbUrl, userName, password);
56+
} catch (Exception e) {
57+
LOG.error("", e);
58+
throw new RuntimeException("", e);
59+
}
60+
}
61+
62+
@Override
63+
public int getFetchSize() {
64+
return Integer.MIN_VALUE;
65+
}
66+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
package com.dtstack.flink.sql.side.clickhouse;
20+
21+
import com.dtstack.flink.sql.side.FieldInfo;
22+
import com.dtstack.flink.sql.side.JoinInfo;
23+
import com.dtstack.flink.sql.side.SideTableInfo;
24+
import com.dtstack.flink.sql.side.rdb.all.RdbAllSideInfo;
25+
import org.apache.flink.api.java.typeutils.RowTypeInfo;
26+
27+
import java.util.List;
28+
29+
30+
public class ClickhouseAllSideInfo extends RdbAllSideInfo {
31+
public ClickhouseAllSideInfo(RowTypeInfo rowTypeInfo, JoinInfo joinInfo, List<FieldInfo> outFieldInfoList, SideTableInfo sideTableInfo) {
32+
super(rowTypeInfo, joinInfo, outFieldInfoList, sideTableInfo);
33+
}
34+
}
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<parent>
6+
<artifactId>sql.side.clickhouse</artifactId>
7+
<groupId>com.dtstack.flink</groupId>
8+
<version>1.0-SNAPSHOT</version>
9+
</parent>
10+
<modelVersion>4.0.0</modelVersion>
11+
12+
<artifactId>sql.side.async.clickhouse</artifactId>
13+
<name>clickhouse-async-side</name>
14+
15+
<packaging>jar</packaging>
16+
17+
<properties>
18+
<sql.side.clickhouse.core.version>1.0-SNAPSHOT</sql.side.clickhouse.core.version>
19+
</properties>
20+
21+
<dependencies>
22+
<dependency>
23+
<groupId>com.dtstack.flink</groupId>
24+
<artifactId>sql.side.clickhouse.core</artifactId>
25+
<version>${sql.side.clickhouse.core.version}</version>
26+
</dependency>
27+
</dependencies>
28+
29+
<build>
30+
<plugins>
31+
<plugin>
32+
<groupId>org.apache.maven.plugins</groupId>
33+
<artifactId>maven-shade-plugin</artifactId>
34+
<version>1.4</version>
35+
<executions>
36+
<execution>
37+
<phase>package</phase>
38+
<goals>
39+
<goal>shade</goal>
40+
</goals>
41+
<configuration>
42+
<artifactSet>
43+
<excludes>
44+
45+
</excludes>
46+
</artifactSet>
47+
<filters>
48+
<filter>
49+
<artifact>*:*</artifact>
50+
<excludes>
51+
<exclude>META-INF/*.SF</exclude>
52+
<exclude>META-INF/*.DSA</exclude>
53+
<exclude>META-INF/*.RSA</exclude>
54+
</excludes>
55+
</filter>
56+
</filters>
57+
</configuration>
58+
</execution>
59+
</executions>
60+
</plugin>
61+
62+
<plugin>
63+
<artifactId>maven-antrun-plugin</artifactId>
64+
<version>1.2</version>
65+
<executions>
66+
<execution>
67+
<id>copy-resources</id>
68+
<!-- here the phase you need -->
69+
<phase>package</phase>
70+
<goals>
71+
<goal>run</goal>
72+
</goals>
73+
<configuration>
74+
<tasks>
75+
<copy todir="${basedir}/../../../plugins/clickhouseasyncside">
76+
<fileset dir="target/">
77+
<include name="${project.artifactId}-${project.version}.jar"/>
78+
</fileset>
79+
</copy>
80+
81+
<move file="${basedir}/../../../plugins/clickhouseasyncside/${project.artifactId}-${project.version}.jar"
82+
tofile="${basedir}/../../../plugins/clickhouseasyncside/${project.name}-${git.branch}.jar"/>
83+
</tasks>
84+
</configuration>
85+
</execution>
86+
</executions>
87+
</plugin>
88+
</plugins>
89+
</build>
90+
91+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
20+
package com.dtstack.flink.sql.side.clickhouse;
21+
22+
import com.dtstack.flink.sql.side.FieldInfo;
23+
import com.dtstack.flink.sql.side.JoinInfo;
24+
import com.dtstack.flink.sql.side.SideTableInfo;
25+
import com.dtstack.flink.sql.side.rdb.async.RdbAsyncReqRow;
26+
import com.dtstack.flink.sql.side.rdb.table.RdbSideTableInfo;
27+
import io.vertx.core.Vertx;
28+
import io.vertx.core.VertxOptions;
29+
import io.vertx.core.json.JsonObject;
30+
import io.vertx.ext.jdbc.JDBCClient;
31+
import org.apache.flink.api.java.typeutils.RowTypeInfo;
32+
import org.apache.flink.configuration.Configuration;
33+
34+
import java.util.List;
35+
36+
37+
public class ClickhouseAsyncReqRow extends RdbAsyncReqRow {
38+
private static final String CLICKHOUSE_DRIVER = "ru.yandex.clickhouse.ClickHouseDriver";
39+
40+
public ClickhouseAsyncReqRow(RowTypeInfo rowTypeInfo, JoinInfo joinInfo, List<FieldInfo> outFieldInfoList, SideTableInfo sideTableInfo) {
41+
super(new ClickhouseAsyncSideInfo(rowTypeInfo, joinInfo, outFieldInfoList, sideTableInfo));
42+
}
43+
44+
45+
@Override
46+
public void open(Configuration parameters) throws Exception {
47+
super.open(parameters);
48+
JsonObject clickhouseClientConfig = new JsonObject();
49+
RdbSideTableInfo rdbSideTableInfo = (RdbSideTableInfo) sideInfo.getSideTableInfo();
50+
clickhouseClientConfig.put("url", rdbSideTableInfo.getUrl())
51+
.put("driver_class", CLICKHOUSE_DRIVER)
52+
.put("max_pool_size", DEFAULT_MAX_DB_CONN_POOL_SIZE)
53+
.put("user", rdbSideTableInfo.getUserName())
54+
.put("password", rdbSideTableInfo.getPassword())
55+
.put("provider_class", DT_PROVIDER_CLASS)
56+
.put("preferred_test_query", PREFERRED_TEST_QUERY_SQL)
57+
.put("idle_connection_test_period", DEFAULT_IDLE_CONNECTION_TEST_PEROID)
58+
.put("test_connection_on_checkin", DEFAULT_TEST_CONNECTION_ON_CHECKIN);
59+
60+
System.setProperty("vertx.disableFileCPResolving", "true");
61+
62+
VertxOptions vo = new VertxOptions();
63+
vo.setEventLoopPoolSize(DEFAULT_VERTX_EVENT_LOOP_POOL_SIZE);
64+
vo.setWorkerPoolSize(DEFAULT_VERTX_WORKER_POOL_SIZE);
65+
vo.setFileResolverCachingEnabled(false);
66+
Vertx vertx = Vertx.vertx(vo);
67+
setRdbSQLClient(JDBCClient.createNonShared(vertx, clickhouseClientConfig));
68+
}
69+
70+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
package com.dtstack.flink.sql.side.clickhouse;
20+
21+
import com.dtstack.flink.sql.side.FieldInfo;
22+
import com.dtstack.flink.sql.side.JoinInfo;
23+
import com.dtstack.flink.sql.side.SideTableInfo;
24+
import com.dtstack.flink.sql.side.rdb.async.RdbAsyncSideInfo;
25+
import org.apache.flink.api.java.typeutils.RowTypeInfo;
26+
27+
import java.util.List;
28+
29+
30+
public class ClickhouseAsyncSideInfo extends RdbAsyncSideInfo {
31+
32+
public ClickhouseAsyncSideInfo(RowTypeInfo rowTypeInfo, JoinInfo joinInfo, List<FieldInfo> outFieldInfoList, SideTableInfo sideTableInfo) {
33+
super(rowTypeInfo, joinInfo, outFieldInfoList, sideTableInfo);
34+
}
35+
}

0 commit comments

Comments
 (0)