-
Notifications
You must be signed in to change notification settings - Fork 191
/
old_version_shardingsphere
164 lines (152 loc) · 8.71 KB
/
old_version_shardingsphere
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
commit 15c3ada01c5d41b3bb82422de519193d844312e3
Author: Ling Hengqian <[email protected]>
Date: Sat Nov 16 09:39:16 2024 +0800
Add documentation for creating SPI implementations of `InlineExpressionParser` (#33653)
diff --git a/docs/document/content/user-manual/common-config/builtin-algorithm/expr.cn.md b/docs/document/content/user-manual/common-config/builtin-algorithm/expr.cn.md
index e1adee6f297..f615696ecb4 100644
--- a/docs/document/content/user-manual/common-config/builtin-algorithm/expr.cn.md
+++ b/docs/document/content/user-manual/common-config/builtin-algorithm/expr.cn.md
@@ -30,6 +30,8 @@ weight = 10
## 基于固定时间范围的 Key-Value 语法的行表达式
`INTERVAL` 实现引入了 Key-Value 风格的属性语法,来通过单行字符串定义一组时间范围内的字符串。这通常用于简化对 `数据分片` 功能的 `actualDataNodes` 的定义。
+`INTERVAL` 生成的字符串仅适用于单个真实库中的多张表。
+若需要处理多个真实库中的多张表,考虑自行创建 `org.apache.shardingsphere.infra.expr.spi.InlineExpressionParser` 的 SPI 实现类。
`INTERVAL` 实现定义多个属性的方式为 `Key1=Value1;Key2=Value2`,通过 `;` 号分割键值对,通过 `=` 号分割 `Key` 值和 `Value` 值。
@@ -112,6 +114,42 @@ Truffle 与 JDK 的向后兼容性矩阵位于 https://medium.com/graalvm/40027a
- `<ESPRESSO>t_order_${1..3}` 将被转化为 `t_order_1, t_order_2, t_order_3`
- `<ESPRESSO>${['online', 'offline']}_table${1..3}` 将被转化为 `online_table1, online_table2, online_table3, offline_table1, offline_table2, offline_table3`
+## 自定义实现
+
+用户总是可以自行创建 `org.apache.shardingsphere.infra.expr.spi.InlineExpressionParser` 的实现类,
+以覆盖更复杂的场景,包括连接至远程 `ElasticSearch` 集群执行 `ES|QL` 以获得 `java.util.List<String>`。
+
+考虑一个简单的 SPI 实现类,
+
+```java
+import org.apache.shardingsphere.infra.expr.spi.InlineExpressionParser;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Properties;
+public final class CustomInlineExpressionParserFixture implements InlineExpressionParser {
+ private String inlineExpression;
+ @Override
+ public void init(final Properties props) {
+ inlineExpression = props.getProperty(INLINE_EXPRESSION_KEY);
+ }
+ @Override
+ public List<String> splitAndEvaluate() {
+ if ("spring".equals(inlineExpression)) {
+ return Arrays.asList("t_order_2024_01", "t_order_2024_02");
+ }
+ return Arrays.asList("t_order_2024_03", "t_order_2024_04");
+ }
+ @Override
+ public Object getType() {
+ return "CUSTOM.FIXTURE";
+ }
+}
+```
+
+此时对于 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`。
+
## 操作步骤
使用需要使用 `行表达式` 的属性时, 如在 `数据分片` 功能中, 在 `actualDataNodes` 属性下指明特定的 SPI 实现的 Type Name 即可。
diff --git a/docs/document/content/user-manual/common-config/builtin-algorithm/expr.en.md b/docs/document/content/user-manual/common-config/builtin-algorithm/expr.en.md
index 6d122e76f43..40914d27955 100644
--- a/docs/document/content/user-manual/common-config/builtin-algorithm/expr.en.md
+++ b/docs/document/content/user-manual/common-config/builtin-algorithm/expr.en.md
@@ -35,6 +35,9 @@ Example:
The `INTERVAL` implementation introduces a Key-Value style property syntax to define a set of time ranges of strings via a single line string.
This is often used to simplify the definition of `actualDataNodes` for `Sharding` feature.
+The string generated by `INTERVAL` is only applicable to multiple tables in a single real database.
+If you need to process multiple tables in multiple real databases,
+consider creating your own SPI implementation class of `org.apache.shardingsphere.infra.expr.spi.InlineExpressionParser`.
`INTERVAL` implements the method of defining multiple attributes as `Key1=Value1;Key2=Value2`, using `;` to separate key-value pairs, and `=` to separate `Key` values and `Value` values.
@@ -123,6 +126,43 @@ Example:
- `<ESPRESSO>t_order_${1..3}` will be converted to `t_order_1, t_order_2, t_order_3`
- `<ESPRESSO>${['online', 'offline']}_table${1..3}` will be converted to `online_table1, online_table2, online_table3, offline_table1, offline_table2, offline_table3`
+## Custom Implementation
+
+Users can always create their own implementation class of `org.apache.shardingsphere.infra.expr.spi.InlineExpressionParser`,
+to cover more complex scenarios,
+including connecting to a remote `ElasticSearch` cluster to execute `ES|QL` to obtain `java.util.List<String>`.
+
+Consider a simple SPI implementation class,
+
+```java
+import org.apache.shardingsphere.infra.expr.spi.InlineExpressionParser;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Properties;
+public final class CustomInlineExpressionParserFixture implements InlineExpressionParser {
+ private String inlineExpression;
+ @Override
+ public void init(final Properties props) {
+ inlineExpression = props.getProperty(INLINE_EXPRESSION_KEY);
+ }
+ @Override
+ public List<String> splitAndEvaluate() {
+ if ("spring".equals(inlineExpression)) {
+ return Arrays.asList("t_order_2024_01", "t_order_2024_02");
+ }
+ return Arrays.asList("t_order_2024_03", "t_order_2024_04");
+ }
+ @Override
+ public Object getType() {
+ return "CUSTOM.FIXTURE";
+ }
+}
+```
+
+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`.
+
## Procedure
When using attributes that require the use of `Row Value Expressions`, such as in the `data sharding` feature, it is
diff --git a/docs/document/content/user-manual/shardingsphere-jdbc/yaml-config/jdbc-driver/known-implementation/_index.cn.md b/docs/document/content/user-manual/shardingsphere-jdbc/yaml-config/jdbc-driver/known-implementation/_index.cn.md
index 649f2dacab0..266c6183126 100644
--- a/docs/document/content/user-manual/shardingsphere-jdbc/yaml-config/jdbc-driver/known-implementation/_index.cn.md
+++ b/docs/document/content/user-manual/shardingsphere-jdbc/yaml-config/jdbc-driver/known-implementation/_index.cn.md
@@ -195,7 +195,7 @@ public class ExampleUtils {
ds_1:
dataSourceClassName: com.zaxxer.hikari.HikariDataSource
driverClassName: $${FIXTURE_DRIVER_CLASS_NAME::com.mysql.cj.jdbc.Driver}
- jdbcUrl: jdbc:mysql://$${FIXTURE_HOST::}:$${FIXTURE_PORT::}/$${FIXTURE_DATABASE::}?useUnicode=true&characterEncoding=UTF-8
+ jdbcUrl: jdbc:mysql://$${FIXTURE_HOST::}:$${FIXTURE_PORT::}/$${FIXTURE_DATABASE::}?sslMode=REQUIRED
username: $${FIXTURE_USERNAME::}
password: $${FIXTURE_PASSWORD::}
```
@@ -206,7 +206,7 @@ ds_1:
ds_1:
dataSourceClassName: com.zaxxer.hikari.HikariDataSource
driverClassName: com.mysql.cj.jdbc.Driver
- jdbcUrl: jdbc:mysql://127.0.0.1:3306/test?useUnicode=true&characterEncoding=UTF-8
+ jdbcUrl: jdbc:mysql://127.0.0.1:3306/test?sslMode=REQUIRED
username: sa
password:
```
diff --git a/docs/document/content/user-manual/shardingsphere-jdbc/yaml-config/jdbc-driver/known-implementation/_index.en.md b/docs/document/content/user-manual/shardingsphere-jdbc/yaml-config/jdbc-driver/known-implementation/_index.en.md
index b2e7b9bab9b..33322009382 100644
--- a/docs/document/content/user-manual/shardingsphere-jdbc/yaml-config/jdbc-driver/known-implementation/_index.en.md
+++ b/docs/document/content/user-manual/shardingsphere-jdbc/yaml-config/jdbc-driver/known-implementation/_index.en.md
@@ -213,7 +213,7 @@ Then for the intercepted fragment of the following YAML file,
ds_1:
dataSourceClassName: com.zaxxer.hikari.HikariDataSource
driverClassName: $${FIXTURE_DRIVER_CLASS_NAME::com.mysql.cj.jdbc.Driver}
- jdbcUrl: jdbc:mysql://$${FIXTURE_HOST::}:$${FIXTURE_PORT::}/$${FIXTURE_DATABASE::}?useUnicode=true&characterEncoding=UTF-8
+ jdbcUrl: jdbc:mysql://$${FIXTURE_HOST::}:$${FIXTURE_PORT::}/$${FIXTURE_DATABASE::}?sslMode=REQUIRED
username: $${FIXTURE_USERNAME::}
password: $${FIXTURE_PASSWORD::}
```
@@ -224,7 +224,7 @@ This YAML snippet will be parsed as,
ds_1:
dataSourceClassName: com.zaxxer.hikari.HikariDataSource
driverClassName: com.mysql.cj.jdbc.Driver
- jdbcUrl: jdbc:mysql://127.0.0.1:3306/test?useUnicode=true&characterEncoding=UTF-8
+ jdbcUrl: jdbc:mysql://127.0.0.1:3306/test?sslMode=REQUIRED
username: sa
password:
```