Skip to content

Commit bebea25

Browse files
authored
[Plugin] Support ydb for jdbc (#198)
2 parents f59c425 + 4c7709c commit bebea25

File tree

17 files changed

+427
-78
lines changed

17 files changed

+427
-78
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,9 @@ Here are some of the major database solutions that are supported:
105105
</a>&nbsp;
106106
<a href="https://www.snowflake.com/" target="_blank">
107107
<img src="assets/plugin/snowflake.png" alt="Snowflake" height="70" />
108+
</a>&nbsp;
109+
<a href="https://ydb.tech/" target="_blank">
110+
<img src="assets/plugin/ydb.png" alt="YDB" height="50" />
108111
</a>
109112
</p>
110113

assets/plugin/ydb.png

20.4 KB
Loading

docs/docs/reference/database/mysql.md

Lines changed: 0 additions & 77 deletions
This file was deleted.
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#### What is YDB ?
2+
3+
YDB is a fault-tolerant distributed SQL DBMS. YDB provides high availability, horizontal scalability, strict consistency, and ACID transaction support. Queries are made using an SQL dialect (YQL).
4+
5+
#### Environment
6+
7+
!!! note
8+
9+
If you need to use this data source, you need to upgrade the DataCap service to >= `1.4.x`
10+
11+
Support Time: `2023-01-30`
12+
13+
#### Configure
14+
15+
---
16+
17+
DataCap uses configuration files by default [ydb.json](https://github.com/EdurtIO/incubator-datacap/blob/develop/server/src/main/etc/conf/plugins/jdbc/ydb.json)
18+
19+
!!! note
20+
21+
If your YDB service version requires other special configurations, please refer to modifying the configuration file and restarting the DataCap service.
22+
23+
=== "Configure"
24+
25+
| Field | Required | Default Value |
26+
|:------:|:---------------------------------:|:-------------:|
27+
| `Name` | :material-check-circle: { .red } | - |
28+
| `Host` | :material-check-circle: { .red } | `127.0.0.1` |
29+
| `Port` | :material-check-circle: { .red } | `2136` |
30+
31+
=== "Authorization"
32+
33+
| Field | Required | Default Value |
34+
|:----------:|:-----------------------:|:-------------:|
35+
| `Username` | :material-close-circle: | - |
36+
| `Password` | :material-close-circle: | - |
37+
38+
=== "Advanced"
39+
40+
| Field | Required | Default Value |
41+
|:----------:|:---------------------------------:|:-------------:|
42+
| `Database` | :material-check-circle: { .red } | `local` |
43+
44+
#### Version (Validation)
45+
46+
---
47+
48+
!!! warning
49+
50+
The online service has not been tested yet, if you have detailed test results, please submit [issues](https://github.com/EdurtIO/incubator-datacap/issues/new/choose) to us
51+
52+
- [x] 2.1.x

docs/mkdocs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ nav:
122122
- Sql: reference/admin/template/sql/home.md
123123
- Connecting to Databases:
124124
- JDBC:
125+
- Yandex Database: reference/plugin/jdbc/ydb.md
125126
- Snowflake: reference/plugin/jdbc/snowflake.md
126127
- MySQL: reference/plugin/jdbc/mysql.md
127128
- ClickHouse: reference/plugin/jdbc/clickhouse.md
@@ -132,7 +133,6 @@ nav:
132133
- CrateDB: reference/plugin/v120/cratedb.md
133134
- TDengine: reference/plugin/v120/tdengine.md
134135
- Impala: reference/plugin/v120/impala.md
135-
- MySQL: reference/database/mysql.md
136136
- Kylin: reference/database/kylin.md
137137
- Oracle: reference/database/oracle.md
138138
- Update:

plugin/jdbc/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,6 @@
4242
<module>neo4j</module>
4343
<module>iotdb</module>
4444
<module>snowflake</module>
45+
<module>ydb</module>
4546
</modules>
4647
</project>

plugin/jdbc/ydb/pom.xml

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
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+
<modelVersion>4.0.0</modelVersion>
6+
<parent>
7+
<groupId>io.edurt.datacap.plugin.jdbc</groupId>
8+
<artifactId>datacap-plugin-jdbc</artifactId>
9+
<version>1.4.0-SNAPSHOT</version>
10+
</parent>
11+
12+
<artifactId>datacap-plugin-jdbc-ydb</artifactId>
13+
<name>DataCap plugin for jdbc (YDB)</name>
14+
15+
<properties>
16+
<ydb.version>1.45.6</ydb.version>
17+
<plugin.name>jdbc-ydb</plugin.name>
18+
</properties>
19+
20+
<dependencies>
21+
<dependency>
22+
<groupId>io.edurt.datacap</groupId>
23+
<artifactId>datacap-spi</artifactId>
24+
<scope>provided</scope>
25+
</dependency>
26+
<dependency>
27+
<groupId>commons-beanutils</groupId>
28+
<artifactId>commons-beanutils</artifactId>
29+
</dependency>
30+
<dependency>
31+
<groupId>com.yandex.ydb</groupId>
32+
<artifactId>ydb-sdk-jdbc</artifactId>
33+
<version>${ydb.version}</version>
34+
</dependency>
35+
</dependencies>
36+
37+
<build>
38+
<plugins>
39+
<plugin>
40+
<artifactId>maven-assembly-plugin</artifactId>
41+
<version>${assembly-plugin.version}</version>
42+
<configuration>
43+
<finalName>${plugin.name}</finalName>
44+
<descriptors>
45+
<descriptor>../../../configure/assembly/assembly-plugin.xml</descriptor>
46+
</descriptors>
47+
<outputDirectory>../../../dist/plugins/${plugin.name}</outputDirectory>
48+
</configuration>
49+
<executions>
50+
<execution>
51+
<id>make-assembly</id>
52+
<phase>package</phase>
53+
<goals>
54+
<goal>single</goal>
55+
</goals>
56+
</execution>
57+
</executions>
58+
</plugin>
59+
</plugins>
60+
</build>
61+
62+
</project>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package io.edurt.datacap.plugin.jdbc.ydb;
2+
3+
import io.edurt.datacap.spi.adapter.JdbcAdapter;
4+
import io.edurt.datacap.spi.connection.JdbcConnection;
5+
6+
public class YDBAdapter
7+
extends JdbcAdapter
8+
{
9+
public YDBAdapter(JdbcConnection jdbcConnection)
10+
{
11+
super(jdbcConnection);
12+
}
13+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package io.edurt.datacap.plugin.jdbc.ydb;
2+
3+
import io.edurt.datacap.spi.connection.JdbcConfigure;
4+
import io.edurt.datacap.spi.connection.JdbcConnection;
5+
import io.edurt.datacap.spi.model.Response;
6+
7+
import java.util.List;
8+
import java.util.Map;
9+
import java.util.stream.Collectors;
10+
11+
public class YDBConnection
12+
extends JdbcConnection
13+
{
14+
public YDBConnection(JdbcConfigure jdbcConfigure, Response response)
15+
{
16+
super(jdbcConfigure, response);
17+
}
18+
19+
@Override
20+
protected String formatJdbcUrl()
21+
{
22+
JdbcConfigure jdbcConfigure = (JdbcConfigure) this.getConfigure();
23+
StringBuffer buffer = new StringBuffer();
24+
buffer.append("jdbc:");
25+
buffer.append(jdbcConfigure.getJdbcType());
26+
buffer.append(":");
27+
buffer.append(jdbcConfigure.getHost());
28+
buffer.append(":");
29+
buffer.append(jdbcConfigure.getPort());
30+
if (jdbcConfigure.getDatabase().isPresent()) {
31+
buffer.append("/");
32+
buffer.append(jdbcConfigure.getDatabase().get());
33+
}
34+
if (jdbcConfigure.getEnv().isPresent()) {
35+
Map<String, Object> env = jdbcConfigure.getEnv().get();
36+
List<String> flatEnv = env.entrySet()
37+
.stream()
38+
.map(value -> String.format("%s=%s", value.getKey(), value.getValue()))
39+
.collect(Collectors.toList());
40+
if (env.size() > 1) {
41+
buffer.append("?");
42+
}
43+
buffer.append(String.join("&", flatEnv));
44+
}
45+
return buffer.toString();
46+
}
47+
}
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
package io.edurt.datacap.plugin.jdbc.ydb;
2+
3+
import io.edurt.datacap.spi.Plugin;
4+
import io.edurt.datacap.spi.PluginType;
5+
import io.edurt.datacap.spi.adapter.JdbcAdapter;
6+
import io.edurt.datacap.spi.connection.JdbcConfigure;
7+
import io.edurt.datacap.spi.connection.JdbcConnection;
8+
import io.edurt.datacap.spi.model.Configure;
9+
import io.edurt.datacap.spi.model.Response;
10+
import lombok.extern.slf4j.Slf4j;
11+
import org.apache.commons.beanutils.BeanUtils;
12+
import org.apache.commons.lang3.ObjectUtils;
13+
14+
@Slf4j
15+
public class YDBPlugin
16+
implements Plugin
17+
{
18+
private JdbcConfigure jdbcConfigure;
19+
private JdbcConnection connection;
20+
private Response response;
21+
22+
@Override
23+
public String name()
24+
{
25+
return "YDB";
26+
}
27+
28+
@Override
29+
public String description()
30+
{
31+
return "Integrate Yandex Database data sources";
32+
}
33+
34+
@Override
35+
public PluginType type()
36+
{
37+
return PluginType.JDBC;
38+
}
39+
40+
@Override
41+
public String validator()
42+
{
43+
return "SELECT 'ydb'";
44+
}
45+
46+
@Override
47+
public void connect(Configure configure)
48+
{
49+
try {
50+
this.response = new Response();
51+
this.jdbcConfigure = new JdbcConfigure();
52+
BeanUtils.copyProperties(this.jdbcConfigure, configure);
53+
this.jdbcConfigure.setJdbcDriver("com.yandex.ydb.jdbc.YdbDriver");
54+
this.jdbcConfigure.setJdbcType("ydb");
55+
this.connection = new YDBConnection(this.jdbcConfigure, this.response);
56+
}
57+
catch (Exception ex) {
58+
this.response.setIsConnected(Boolean.FALSE);
59+
this.response.setMessage(ex.getMessage());
60+
}
61+
}
62+
63+
@Override
64+
public Response execute(String content)
65+
{
66+
if (ObjectUtils.isNotEmpty(this.connection)) {
67+
log.info("Execute ydb plugin logic started");
68+
this.response = this.connection.getResponse();
69+
JdbcAdapter processor = new YDBAdapter(this.connection);
70+
this.response = processor.handlerExecute(content);
71+
log.info("Execute ydb plugin logic end");
72+
}
73+
return this.response;
74+
}
75+
76+
@Override
77+
public void destroy()
78+
{
79+
if (ObjectUtils.isNotEmpty(this.connection)) {
80+
this.connection.destroy();
81+
}
82+
}
83+
}

0 commit comments

Comments
 (0)