Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removes support for jdbcURL prefix of jdbc:tc:shardingsphere0clickhouse: #33707

Merged
merged 1 commit into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions RELEASE-NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

### API Changes

1. Infra: Removes support for jdbcURL prefix of `jdbc:tc:shardingsphere0clickhouse:` - [#33707](https://github.com/apache/shardingsphere/pull/33707)

### New Features

### Enhancements
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ Truffle 与 JDK 的向后兼容性矩阵位于 https://medium.com/graalvm/40027a
考虑一个简单的 SPI 实现类,

```java
package org.example;
import org.apache.shardingsphere.infra.expr.spi.InlineExpressionParser;
import java.util.Arrays;
import java.util.List;
Expand All @@ -146,6 +147,12 @@ public final class CustomInlineExpressionParserFixture implements InlineExpressi
}
```

并在项目的 classpath 添加 `META-INF/services/org.apache.shardingsphere.infra.expr.spi.InlineExpressionParser`文件,

```
org.example.CustomInlineExpressionParserFixture
```

此时对于 ShardingSphere 配置文件中的 `actualDataNodes`,
1. 若配置为 `<CUSTOM.FIXTURE>spring`,将被转化为 `t_order_2024_01, t_order_2024_02`。
2. 若配置为 `<CUSTOM.FIXTURE>summer`,将被转化为 `t_order_2024_03, t_order_2024_04`。
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,12 @@ public final class CustomInlineExpressionParserFixture implements InlineExpressi
}
```

And add the file `META-INF/services/org.apache.shardingsphere.infra.expr.spi.InlineExpressionParser` to the project classpath,

```
org.example.CustomInlineExpressionParserFixture
```

At this time, for `actualDataNodes` in the ShardingSphere configuration file,
1. If configured as `<CUSTOM.FIXTURE>spring`, it will be converted to `t_order_2024_01, t_order_2024_02`.
2. If configured as `<CUSTOM.FIXTURE>summer`, it will be converted to `t_order_2024_03, t_order_2024_04`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,14 @@ Apache ShardingSphere 内置的标准分片算法实现类包括:

可配置属性:

| *属性名称* | *数据类型* | *说明* | *默认值* |
|------------------------------|--------|--------------------------------------------------------------------------------------------------------------------------------------------|-------|
| datetime-pattern | String | 分片键的时间戳格式,必须遵循 Java DateTimeFormatter 的格式。例如:yyyy-MM-dd HH:mm:ss,yyyy-MM-dd 或 HH:mm:ss 等。但不支持与 `java.time.chrono.JapaneseDate` 相关的 Gy-MM 等 | |
| datetime-lower | String | 时间分片下界值,格式与 `datetime-pattern` 定义的时间戳格式一致 | |
| datetime-upper (?) | String | 时间分片上界值,格式与 `datetime-pattern` 定义的时间戳格式一致 | 当前时间 |
| sharding-suffix-pattern | String | 分片数据源或真实表的后缀格式,必须遵循 Java DateTimeFormatter 的格式,必须和 `datetime-interval-unit` 保持一致。例如:yyyyMM | |
| datetime-interval-amount (?) | int | 分片键时间间隔,超过该时间间隔将进入下一分片 | 1 |
| datetime-interval-unit (?) | String | 分片键时间间隔单位,必须遵循 Java ChronoUnit 的枚举值。例如:MONTHS | DAYS |
| *属性名称* | *数据类型* | *说明* | *默认值* |
|------------------------------|--------|-----------------------------------------------------------------------------------------------------------------------------------------------|-------|
| datetime-pattern | String | 分片键的时间戳格式,必须遵循 Java DateTimeFormatter 的格式。例如:yyyy-MM-dd HH:mm:ss,yyyy-MM-dd 或 HH:mm:ss 等。但不支持与 `java.time.chrono.JapaneseDate` 相关的 GGGGy-MM 等 | |
| datetime-lower | String | 时间分片下界值,格式与 `datetime-pattern` 定义的时间戳格式一致 | |
| datetime-upper (?) | String | 时间分片上界值,格式与 `datetime-pattern` 定义的时间戳格式一致 | 当前时间 |
| sharding-suffix-pattern | String | 分片数据源或真实表的后缀格式,必须遵循 Java DateTimeFormatter 的格式,必须和 `datetime-interval-unit` 保持一致。例如:yyyyMM | |
| datetime-interval-amount (?) | int | 分片键时间间隔,超过该时间间隔将进入下一分片 | 1 |
| datetime-interval-unit (?) | String | 分片键时间间隔单位,必须遵循 Java ChronoUnit 的枚举值。例如:MONTHS | DAYS |

### 复合分片算法

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,14 @@ Type: INTERVAL

Attributes:

| *Name* | *DataType* | *Description* | *Default Value* |
|------------------------------|------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------|
| datetime-pattern | String | Timestamp pattern of sharding value, must can be transformed to Java LocalDateTime. For example: yyyy-MM-dd HH:mm:ss, yyyy-MM-dd or HH:mm:ss etc. But Gy-MM etc. related to `java.time.chrono.JapaneseDate` are not supported | - |
| datetime-lower | String | Datetime sharding lower boundary, pattern is defined `datetime-pattern` | - |
| datetime-upper (?) | String | Datetime sharding upper boundary, pattern is defined `datetime-pattern` | Now |
| sharding-suffix-pattern | String | Suffix pattern of sharding data sources or tables, must can be transformed to Java LocalDateTime, must be consistent with `datetime-interval-unit`. For example: yyyyMM | - |
| datetime-interval-amount (?) | int | Interval of sharding value, after which the next shard will be entered | 1 |
| datetime-interval-unit (?) | String | Unit of sharding value interval, must can be transformed to Java ChronoUnit's Enum value. For example: MONTHS | DAYS |
| *Name* | *DataType* | *Description* | *Default Value* |
|------------------------------|------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------|
| datetime-pattern | String | Timestamp pattern of sharding value, must can be transformed to Java LocalDateTime. For example: yyyy-MM-dd HH:mm:ss, yyyy-MM-dd or HH:mm:ss etc. But GGGGy-MM etc. related to `java.time.chrono.JapaneseDate` are not supported | - |
| datetime-lower | String | Datetime sharding lower boundary, pattern is defined `datetime-pattern` | - |
| datetime-upper (?) | String | Datetime sharding upper boundary, pattern is defined `datetime-pattern` | Now |
| sharding-suffix-pattern | String | Suffix pattern of sharding data sources or tables, must can be transformed to Java LocalDateTime, must be consistent with `datetime-interval-unit`. For example: yyyyMM | - |
| datetime-interval-amount (?) | int | Interval of sharding value, after which the next shard will be entered | 1 |
| datetime-interval-unit (?) | String | Unit of sharding value interval, must can be transformed to Java ChronoUnit's Enum value. For example: MONTHS | DAYS |

### Complex Sharding Algorithm

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
+++
title = "Testcontainers"
weight = 6
+++

ShardingSphere 默认情况下不提供对 `org.testcontainers.jdbc.ContainerDatabaseDriver` 的 `driverClassName` 的支持。
要在 ShardingSphere 的配置文件为数据节点使用类似 `jdbc:tc:postgresql:17.1-bookworm://test-native-databases-postgres/demo_ds_0` 的 `jdbcUrl`,
可能的 Maven 依赖关系如下,

```xml
<dependencies>
<dependency>
<groupId>org.apache.shardingsphere</groupId>
<artifactId>shardingsphere-jdbc</artifactId>
<version>${shardingsphere.version}</version>
</dependency>
<dependency>
<groupId>org.apache.shardingsphere</groupId>
<artifactId>shardingsphere-infra-database-testcontainers</artifactId>
<version>${shardingsphere.version}</version>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>postgresql</artifactId>
<version>1.20.3</version>
<scope>test</scope>
</dependency>
</dependencies>
```

`org.apache.shardingsphere:shardingsphere-infra-database-testcontainers` 为 testcontainers-java 分格的 jdbcURL 提供支持,
包括但不限于,

1. 为 `jdbc:tc:clickhouse:` 的 jdbcURL 前缀提供支持的 Maven 模块 `org.testcontainers:clickhouse:1.20.3`
2. 为 `jdbc:tc:postgresql:` 的 jdbcURL 前缀提供支持的 Maven 模块 `org.testcontainers:postgresql:1.20.3`
3. 为 `jdbc:tc:sqlserver:` 的 jdbcURL 前缀提供支持的 Maven 模块 `org.testcontainers:mssqlserver:1.20.3`
4. 为 `jdbc:tc:mariadb:` 的 jdbcURL 前缀提供支持的 Maven 模块 `org.testcontainers:mariadb:1.20.3`
5. 为 `jdbc:tc:mysql:` 的 jdbcURL 前缀提供支持的 Maven 模块 `org.testcontainers:mysql:1.20.3`
6. 为 `jdbc:tc:oracle:` 的 jdbcURL 前缀提供支持的 Maven 模块 `org.testcontainers:oracle-xe:1.20.3` 和 `org.testcontainers:oracle-free:1.20.3`
7. 为 `jdbc:tc:tidb:` 的 jdbcURL 前缀提供支持的 Maven 模块 `org.testcontainers:tidb:1.20.3`
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
+++
title = "Testcontainers"
weight = 6
+++

ShardingSphere does not provide support for `driverClassName` of `org.testcontainers.jdbc.ContainerDatabaseDriver` by default.
To use `jdbcUrl` like `jdbc:tc:postgresql:17.1-bookworm://test-native-databases-postgres/demo_ds_0` for data nodes in ShardingSphere's configuration file,
the possible Maven dependencies are as follows,

```xml
<dependencies>
<dependency>
<groupId>org.apache.shardingsphere</groupId>
<artifactId>shardingsphere-jdbc</artifactId>
<version>${shardingsphere.version}</version>
</dependency>
<dependency>
<groupId>org.apache.shardingsphere</groupId>
<artifactId>shardingsphere-infra-database-testcontainers</artifactId>
<version>${shardingsphere.version}</version>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>postgresql</artifactId>
<version>1.20.3</version>
<scope>test</scope>
</dependency>
</dependencies>
```

`org.apache.shardingsphere:shardingsphere-infra-database-testcontainers` provides support for jdbcURL in the testcontainers-java partition,
including but not limited to,

1. Maven module `org.testcontainers:clickhouse:1.20.3` that provides support for jdbcURL prefixes for `jdbc:tc:clickhouse:`
2. Maven module `org.testcontainers:postgresql:1.20.3` that provides support for jdbcURL prefixes for `jdbc:tc:postgresql:`
3. Maven module `org.testcontainers:mssqlserver:1.20.3` that provides support for jdbcURL prefixes for `jdbc:tc:sqlserver:`
4. Maven module `org.testcontainers:mariadb:1.20.3` that provides support for jdbcURL prefixes for `jdbc:tc:mariadb:`
5. Maven module `org.testcontainers:mysql:1.20.3` that provides support for jdbcURL prefixes of `jdbc:tc:mysql:`
6. Maven modules `org.testcontainers:oracle-xe:1.20.3` and `org.testcontainers:oracle-free:1.20.3` that provide support for jdbcURL prefixes of `jdbc:tc:oracle:`
7. Maven module `org.testcontainers:tidb:1.20.3` that provides support for jdbcURL prefixes of `jdbc:tc:tidb:`
2 changes: 1 addition & 1 deletion examples/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@

<profiles>
<profile>
<id>jdk11-22</id>
<id>jdk11+</id>
<activation>
<jdk>[11,)</jdk>
</activation>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,18 @@
import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;

import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Optional;

/**
* Database type of ClickHouse in testcontainers-java.
*/
public final class TcClickHouseDatabaseType implements TestcontainersDatabaseType {

/**
* TODO See the JavaDoc for `org.apache.shardingsphere.test.natived.jdbc.commons.testcontainers.ClickHouseProvider`.
*
* @return prefixes of JDBC URL
*/
@Override
public Collection<String> getJdbcUrlPrefixes() {
return Arrays.asList("jdbc:tc:clickhouse:", "jdbc:tc:shardingsphere0clickhouse:");
return Collections.singletonList("jdbc:tc:clickhouse:");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import org.apache.shardingsphere.infra.spi.type.typed.TypedSPILoader;
import org.junit.jupiter.api.Test;

import java.util.Arrays;
import java.util.Collections;

import static org.hamcrest.CoreMatchers.is;
Expand All @@ -31,7 +30,7 @@ class TestcontainersDatabaseTypeTest {

@Test
void assertGetJdbcUrlPrefixes() {
assertThat(TypedSPILoader.getService(DatabaseType.class, "TC-ClickHouse").getJdbcUrlPrefixes(), is(Arrays.asList("jdbc:tc:clickhouse:", "jdbc:tc:shardingsphere0clickhouse:")));
assertThat(TypedSPILoader.getService(DatabaseType.class, "TC-ClickHouse").getJdbcUrlPrefixes(), is(Collections.singletonList("jdbc:tc:clickhouse:")));
assertThat(TypedSPILoader.getService(DatabaseType.class, "TC-MariaDB").getJdbcUrlPrefixes(), is(Collections.singleton("jdbc:tc:mariadb:")));
assertThat(TypedSPILoader.getService(DatabaseType.class, "TC-MySQL").getJdbcUrlPrefixes(), is(Collections.singleton("jdbc:tc:mysql:")));
assertThat(TypedSPILoader.getService(DatabaseType.class, "TC-Oracle").getJdbcUrlPrefixes(), is(Collections.singleton("jdbc:tc:oracle:")));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,18 @@
"includes":[{
"condition":{"typeReachable":"com.clickhouse.logging.LoggerFactory"},
"pattern":"\\QMETA-INF/services/com.clickhouse.logging.LoggerFactory\\E"
}, {
"condition":{"typeReachable":"com.clickhouse.client.ClickHouseRequestManager"},
"pattern":"\\QMETA-INF/services/com.clickhouse.client.ClickHouseRequestManager\\E"
}, {
"condition":{"typeReachable":"com.clickhouse.data.ClickHouseDataStreamFactory"},
"pattern":"\\QMETA-INF/services/com.clickhouse.data.ClickHouseDataStreamFactory\\E"
}, {
"condition":{"typeReachable":"com.clickhouse.jdbc.JdbcTypeMapping"},
"pattern":"\\QMETA-INF/services/com.clickhouse.jdbc.JdbcTypeMapping\\E"
}, {
"condition":{"typeReachable":"com.clickhouse.client.internal.jpountz.lz4.LZ4JNI"},
"pattern":"\\Qcom/clickhouse/client/internal/jpountz/util/linux/amd64/liblz4-java.so\\E"
}]},
"bundles":[]
}
Loading