This is an automated email from the ASF dual-hosted git repository.
jianglongtao pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
The following commit(s) were added to refs/heads/master by this push:
new 02d3b0f350f ADD RESOURCE & CREATE SHARDING distsql test cases (#20350)
02d3b0f350f is described below
commit 02d3b0f350f7c2886e2ba4668dedf9e1c749650a
Author: Xin Huang <[email protected]>
AuthorDate: Fri Aug 26 09:43:36 2022 +0800
ADD RESOURCE & CREATE SHARDING distsql test cases (#20350)
* ADD RESOURCE distsql test case
* CREATE SHARDING distsql test case
* Update distql statement as the version is updated
* Update based on review
---
.../common/constant/DistSQLScriptConstants.java | 15 +--
.../queryable/ConvertYamlConfigurationHandler.java | 6 +-
.../ConvertYamlConfigurationHandlerTest.java | 136 +++++++++++++++++++++
.../resources/conf/convert/config-resource.yaml | 56 +++++++++
.../resources/conf/convert/config-sharding.yaml | 101 +++++++++++++++
.../resources/expected/convert-add-resource.yaml | 35 ++++++
.../expected/convert-create-sharding.yaml | 50 ++++++++
.../ral/impl/QueryableRALStatementAssert.java | 5 +
.../ConvertYamlConfigurationStatementAssert.java | 48 ++++++++
.../jaxb/cases/domain/SQLParserTestCases.java | 4 +
.../ConvertYamlConfigurationStatementTestCase.java | 35 ++++++
.../src/main/resources/case/ral/queryable.xml | 3 +
.../main/resources/sql/supported/ral/queryable.xml | 1 +
13 files changed, 485 insertions(+), 10 deletions(-)
diff --git
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/common/constant/DistSQLScriptConstants.java
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/common/constant/DistSQLScriptConstants.java
index 6ca9e9ae431..cf65335abb6 100644
---
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/common/constant/DistSQLScriptConstants.java
+++
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/common/constant/DistSQLScriptConstants.java
@@ -46,18 +46,19 @@ public final class DistSQLScriptConstants {
+ System.lineSeparator()
+ "URL=\"%s\","
+ System.lineSeparator()
- + "USER=%s,"
+ + "USER=\"%s\","
+ System.lineSeparator()
+ "PASSWORD=\"%s\","
+ System.lineSeparator()
+ "PROPERTIES(%s)"
+ + System.lineSeparator()
+ ")";
public static final String RESOURCE_DEFINITION_WITHOUT_PASSWORD = " %s ("
+ System.lineSeparator()
+ "URL=\"%s\","
+ System.lineSeparator()
- + "USER=%s,"
+ + "USER=\"%s\","
+ System.lineSeparator()
+ "PROPERTIES(%s)"
+ ")";
@@ -68,7 +69,7 @@ public final class DistSQLScriptConstants {
public static final String SHARDING_ALGORITHM = " %s ("
+ System.lineSeparator()
- + "TYPE(NAME=%s, PROPERTIES(%s))"
+ + "TYPE(NAME=\"%s\", PROPERTIES(%s))"
+ System.lineSeparator()
+ ")";
@@ -86,13 +87,13 @@ public final class DistSQLScriptConstants {
public static final String TABLE_STRATEGY = "TABLE_STRATEGY";
- public static final String SHARDING_STRATEGY_STANDARD = "%s(TYPE=%s,
SHARDING_COLUMN=%s, SHARDING_ALGORITHM=%s),"
+ public static final String SHARDING_STRATEGY_STANDARD = "%s(TYPE=\"%s\",
SHARDING_COLUMN=%s, SHARDING_ALGORITHM=%s),"
+ System.lineSeparator();
- public static final String SHARDING_STRATEGY_COMPLEX = "%s(TYPE=%s,
SHARDING_COLUMNS=%s, SHARDING_ALGORITHM=%s),"
+ public static final String SHARDING_STRATEGY_COMPLEX = "%s(TYPE=\"%s\",
SHARDING_COLUMNS=%s, SHARDING_ALGORITHM=%s),"
+ System.lineSeparator();
- public static final String SHARDING_STRATEGY_HINT = "%s(TYPE=%s,
SHARDING_ALGORITHM=%s),"
+ public static final String SHARDING_STRATEGY_HINT = "%s(TYPE=\"%s\",
SHARDING_ALGORITHM=%s),"
+ System.lineSeparator();
public static final String KEY_GENERATOR_STRATEGY =
"KEY_GENERATE_STRATEGY(COLUMN=%s, KEY_GENERATOR=%s),"
@@ -102,7 +103,7 @@ public final class DistSQLScriptConstants {
public static final String KEY_GENERATOR = " %s ("
+ System.lineSeparator()
- + "TYPE(NAME=%s)"
+ + "TYPE(NAME=\"%s\")"
+ System.lineSeparator()
+ ")";
diff --git
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ConvertYamlConfigurationHandler.java
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ConvertYamlConfigurationHandler.java
index 5bfb0160d1a..827a752dd9f 100644
---
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ConvertYamlConfigurationHandler.java
+++
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ConvertYamlConfigurationHandler.java
@@ -105,7 +105,7 @@ public final class ConvertYamlConfigurationHandler extends
QueryableRALBackendHa
DataSourceProperties dataSourceProperties =
DataSourcePropertiesCreator.create(HikariDataSource.class.getName(),
dataSourceConfigSwapper.swap(entry.getValue()));
appendResource(entry.getKey(), dataSourceProperties,
stringBuilder);
if (iterator.hasNext()) {
-
stringBuilder.append(DistSQLScriptConstants.COMMA).append(System.lineSeparator());
+ stringBuilder.append(DistSQLScriptConstants.COMMA);
}
}
stringBuilder.append(DistSQLScriptConstants.SEMI).append(System.lineSeparator());
@@ -263,11 +263,11 @@ public final class ConvertYamlConfigurationHandler
extends QueryableRALBackendHa
}
private void appendShardingBindingTableRules(final
ShardingRuleConfiguration shardingRuleConfig, final StringBuilder
stringBuilder) {
- String bindings =
getBinding(shardingRuleConfig.getBindingTableGroups().iterator());
+ String bindings =
getBindings(shardingRuleConfig.getBindingTableGroups().iterator());
stringBuilder.append(String.format(DistSQLScriptConstants.SHARDING_BINDING_TABLE_RULES,
bindings));
}
- private String getBinding(final Iterator<String> iterator) {
+ private String getBindings(final Iterator<String> iterator) {
StringBuilder result = new StringBuilder();
while (iterator.hasNext()) {
String binding = iterator.next();
diff --git
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ConvertYamlConfigurationHandlerTest.java
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ConvertYamlConfigurationHandlerTest.java
new file mode 100644
index 00000000000..33452a98108
--- /dev/null
+++
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ConvertYamlConfigurationHandlerTest.java
@@ -0,0 +1,136 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.proxy.backend.handler.distsql.ral.queryable;
+
+import lombok.SneakyThrows;
+import
org.apache.shardingsphere.distsql.parser.statement.ral.queryable.ConvertYamlConfigurationStatement;
+import org.apache.shardingsphere.mode.manager.ContextManager;
+import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
+import
org.apache.shardingsphere.proxy.backend.response.header.query.QueryHeader;
+import
org.apache.shardingsphere.proxy.backend.response.header.query.QueryResponseHeader;
+import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
+import org.apache.shardingsphere.proxy.backend.util.ProxyContextRestorer;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.io.BufferedReader;
+import java.io.FileReader;
+import java.io.IOException;
+import java.sql.SQLException;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Objects;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertFalse;
+import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
+import static org.mockito.Mockito.mock;
+
+public final class ConvertYamlConfigurationHandlerTest extends
ProxyContextRestorer {
+
+ private final String resourceFilePath =
"/conf/convert/config-resource.yaml";
+
+ private final String shardingFilePath =
"/conf/convert/config-sharding.yaml";
+
+ private final String resourceExpectedFilePath =
"/expected/convert-add-resource.yaml";
+
+ private final String shardingExpectedFilePath =
"/expected/convert-create-sharding.yaml";
+
+ private final String resource = "resource";
+
+ private final String sharding = "sharding";
+
+ private final Map<String, String> featureMap = new HashMap<>(2, 1);
+
+ @Before
+ public void setup() {
+ featureMap.put(resource, resourceFilePath);
+ featureMap.put(sharding, shardingFilePath);
+ }
+
+ @Before
+ public void init() {
+ ContextManager contextManager = mock(ContextManager.class,
RETURNS_DEEP_STUBS);
+ ProxyContext.init(contextManager);
+ }
+
+ @Test
+ public void assertExecuteWithAddResource() throws SQLException {
+ assertExecute(resource, resourceExpectedFilePath);
+ }
+
+ @Test
+ public void assertExecuteWithCreateSharding() throws SQLException {
+ assertExecute(sharding, shardingExpectedFilePath);
+ }
+
+ public void assertExecute(final String type, final String
expectedFilePath) throws SQLException {
+ ConvertYamlConfigurationHandler handler = new
ConvertYamlConfigurationHandler();
+ handler.init(new
ConvertYamlConfigurationStatement(Objects.requireNonNull(ConvertYamlConfigurationHandlerTest.class.getResource(featureMap.get(type))).getPath()),
+ mock(ConnectionSession.class));
+ assertQueryResponseHeader((QueryResponseHeader) handler.execute());
+ assertTrue(handler.next());
+ assertRowData(handler.getRowData().getData(), expectedFilePath);
+ assertFalse(handler.next());
+ }
+
+ private void assertQueryResponseHeader(final QueryResponseHeader actual) {
+ assertThat(actual.getQueryHeaders().size(), is(1));
+ assertQueryHeader(actual.getQueryHeaders().get(0));
+ }
+
+ private void assertQueryHeader(final QueryHeader actual) {
+ assertThat(actual.getSchema(), is(""));
+ assertThat(actual.getTable(), is(""));
+ assertThat(actual.getColumnLabel(), is("distsql"));
+ assertThat(actual.getColumnName(), is("distsql"));
+ assertThat(actual.getColumnType(), is(1));
+ assertThat(actual.getColumnTypeName(), is("CHAR"));
+ assertThat(actual.getColumnLength(), is(255));
+ assertThat(actual.getDecimals(), is(0));
+ assertFalse(actual.isSigned());
+ assertFalse(actual.isPrimaryKey());
+ assertFalse(actual.isNotNull());
+ assertFalse(actual.isAutoIncrement());
+ }
+
+ private void assertRowData(final Collection<Object> actual, final String
expectedFilePath) {
+ assertThat(actual.size(), is(1));
+ assertThat(actual.iterator().next(),
is(loadExpectedRow(expectedFilePath)));
+ }
+
+ @SneakyThrows(IOException.class)
+ private String loadExpectedRow(final String expectedFilePath) {
+ StringBuilder result = new StringBuilder();
+ String fileName =
Objects.requireNonNull(ConvertYamlConfigurationHandlerTest.class.getResource(expectedFilePath)).getFile();
+ try (
+ FileReader fileReader = new FileReader(fileName);
+ BufferedReader reader = new BufferedReader(fileReader)) {
+ String line;
+ while (null != (line = reader.readLine())) {
+ if (!line.startsWith("#") && !line.trim().isEmpty()) {
+ result.append(line).append(System.lineSeparator());
+ }
+ }
+ }
+ return result.toString();
+ }
+}
diff --git
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/resources/conf/convert/config-resource.yaml
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/resources/conf/convert/config-resource.yaml
new file mode 100644
index 00000000000..9927691b0b2
--- /dev/null
+++
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/resources/conf/convert/config-resource.yaml
@@ -0,0 +1,56 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+databaseName: resource_db
+
+dataSources:
+ ds_0:
+ url: jdbc:mysql://127.0.0.1:3306/demo_ds_0?serverTimezone=UTC&useSSL=false
+ username: root
+ password: 12345678
+ connectionTimeoutMilliseconds: 3000
+ idleTimeoutMilliseconds: 60000
+ maxLifetimeMilliseconds: 1800000
+ maxPoolSize: 50
+ minPoolSize: 1
+ customPoolProps:
+ poolName: datasource-two
+ autoCommit: false
+ ds_1:
+ url: jdbc:mysql://127.0.0.1:3306/demo_ds_1?serverTimezone=UTC&useSSL=false
+ username: root
+ password: 12345678
+ connectionTimeoutMilliseconds: 3000
+ idleTimeoutMilliseconds: 60000
+ maxLifetimeMilliseconds: 1800000
+ maxPoolSize: 50
+ minPoolSize: 1
+ customPoolProps:
+ poolName: datasource-two
+ autoCommit: false
+ ds_2:
+ url: jdbc:mysql://127.0.0.1:3306/demo_ds_2?serverTimezone=UTC&useSSL=false
+ username: root
+ password: 12345678
+ connectionTimeoutMilliseconds: 3000
+ idleTimeoutMilliseconds: 60000
+ maxLifetimeMilliseconds: 1800000
+ maxPoolSize: 50
+ minPoolSize: 1
+ customPoolProps:
+ poolName: datasource-two
+ autoCommit: false
diff --git
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/resources/conf/convert/config-sharding.yaml
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/resources/conf/convert/config-sharding.yaml
new file mode 100644
index 00000000000..283e9d7c779
--- /dev/null
+++
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/resources/conf/convert/config-sharding.yaml
@@ -0,0 +1,101 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+databaseName: sharding_db
+
+dataSources:
+ ds_0:
+ url: jdbc:mysql://127.0.0.1:3306/demo_ds_0?serverTimezone=UTC&useSSL=false
+ username: root
+ password: 12345678
+ connectionTimeoutMilliseconds: 30000
+ idleTimeoutMilliseconds: 60000
+ maxLifetimeMilliseconds: 1800000
+ maxPoolSize: 50
+ minPoolSize: 1
+ ds_1:
+ url: jdbc:mysql://127.0.0.1:3306/demo_ds_1?serverTimezone=UTC&useSSL=false
+ username: root
+ password: 12345678
+ connectionTimeoutMilliseconds: 30000
+ idleTimeoutMilliseconds: 60000
+ maxLifetimeMilliseconds: 1800000
+ maxPoolSize: 50
+ minPoolSize: 1
+
+rules:
+- !SHARDING
+ tables:
+ t_order:
+ actualDataNodes: ds_${0..1}.t_order_${0..1}
+ tableStrategy:
+ complex:
+ shardingColumns: order_id, user_id
+ shardingAlgorithmName: t_order_inline
+ keyGenerateStrategy:
+ column: order_id
+ keyGeneratorName: snowflake
+ auditStrategy:
+ auditorNames:
+ - sharding_key_required_auditor
+ allowHintDisable: true
+ t_order_item:
+ actualDataNodes: ds_${0..1}.t_order_item_${0..1}
+ tableStrategy:
+ complex:
+ shardingColumns: order_id, user_id
+ shardingAlgorithmName: t_order_item_inline
+ keyGenerateStrategy:
+ column: order_item_id
+ keyGeneratorName: snowflake
+ bindingTables:
+ - t_order,t_order_item
+ defaultDatabaseStrategy:
+ standard:
+ shardingColumn: user_id
+ shardingAlgorithmName: database_inline
+ defaultTableStrategy:
+ none:
+ defaultAuditStrategy:
+ auditorNames:
+ - sharding_key_required_auditor
+ allowHintDisable: true
+
+ shardingAlgorithms:
+ database_inline:
+ type: INLINE
+ props:
+ algorithm-expression: ds_${user_id % 2}
+ datetime-lower: "2022-01-01 00:00:00"
+ t_order_inline:
+ type: INLINE
+ props:
+ algorithm-expression: t_order_${order_id % 2}
+ datetime-lower: "2022-01-01 00:00:00"
+ t_order_item_inline:
+ type: INLINE
+ props:
+ algorithm-expression: t_order_item_${order_id % 2}
+ datetime-lower: "2022-01-01 00:00:00"
+
+ keyGenerators:
+ snowflake:
+ type: SNOWFLAKE
+
+ auditors:
+ sharding_key_required_auditor:
+ type: DML_SHARDING_CONDITIONS
diff --git
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/resources/expected/convert-add-resource.yaml
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/resources/expected/convert-add-resource.yaml
new file mode 100644
index 00000000000..d7e391593ea
--- /dev/null
+++
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/resources/expected/convert-add-resource.yaml
@@ -0,0 +1,35 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+CREATE DATABASE resource_db;
+USE resource_db;
+ADD RESOURCE ds_0 (
+URL="jdbc:mysql://127.0.0.1:3306/demo_ds_0?serverTimezone=UTC&useSSL=false",
+USER="root",
+PASSWORD="12345678",
+PROPERTIES("minPoolSize"="1","connectionTimeoutMilliseconds"="3000","maxLifetimeMilliseconds"="1800000","idleTimeoutMilliseconds"="60000","maxPoolSize"="50","autoCommit"="false")
+), ds_1 (
+URL="jdbc:mysql://127.0.0.1:3306/demo_ds_1?serverTimezone=UTC&useSSL=false",
+USER="root",
+PASSWORD="12345678",
+PROPERTIES("minPoolSize"="1","connectionTimeoutMilliseconds"="3000","maxLifetimeMilliseconds"="1800000","idleTimeoutMilliseconds"="60000","maxPoolSize"="50","autoCommit"="false")
+), ds_2 (
+URL="jdbc:mysql://127.0.0.1:3306/demo_ds_2?serverTimezone=UTC&useSSL=false",
+USER="root",
+PASSWORD="12345678",
+PROPERTIES("minPoolSize"="1","connectionTimeoutMilliseconds"="3000","maxLifetimeMilliseconds"="1800000","idleTimeoutMilliseconds"="60000","maxPoolSize"="50","autoCommit"="false")
+);
diff --git
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/resources/expected/convert-create-sharding.yaml
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/resources/expected/convert-create-sharding.yaml
new file mode 100644
index 00000000000..efe09d4e2d6
--- /dev/null
+++
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/resources/expected/convert-create-sharding.yaml
@@ -0,0 +1,50 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+CREATE DATABASE sharding_db;
+USE sharding_db;
+ADD RESOURCE ds_0 (
+URL="jdbc:mysql://127.0.0.1:3306/demo_ds_0?serverTimezone=UTC&useSSL=false",
+USER="root",
+PASSWORD="12345678",
+PROPERTIES("minPoolSize"="1","connectionTimeoutMilliseconds"="30000","maxLifetimeMilliseconds"="1800000","idleTimeoutMilliseconds"="60000","maxPoolSize"="50")
+), ds_1 (
+URL="jdbc:mysql://127.0.0.1:3306/demo_ds_1?serverTimezone=UTC&useSSL=false",
+USER="root",
+PASSWORD="12345678",
+PROPERTIES("minPoolSize"="1","connectionTimeoutMilliseconds"="30000","maxLifetimeMilliseconds"="1800000","idleTimeoutMilliseconds"="60000","maxPoolSize"="50")
+);
+CREATE SHARDING ALGORITHM database_inline (
+TYPE(NAME="inline", PROPERTIES("algorithm-expression"="ds_${user_id %
2}","datetime-lower"="2022-01-01 00:00:00"))
+), t_order_inline (
+TYPE(NAME="inline", PROPERTIES("algorithm-expression"="t_order_${order_id %
2}","datetime-lower"="2022-01-01 00:00:00"))
+), t_order_item_inline (
+TYPE(NAME="inline", PROPERTIES("algorithm-expression"="t_order_item_${order_id
% 2}","datetime-lower"="2022-01-01 00:00:00"))
+);
+CREATE SHARDING KEY GENERATOR snowflake (
+TYPE(NAME="SNOWFLAKE")
+);
+CREATE SHARDING TABLE RULE t_order (
+DATANODES("ds_${0..1}.t_order_${0..1}"),
+TABLE_STRATEGY(TYPE="complex", SHARDING_COLUMNS=order_id, user_id,
SHARDING_ALGORITHM=t_order_inline),
+KEY_GENERATE_STRATEGY(COLUMN=order_id, KEY_GENERATOR=snowflake)
+), t_order_item (
+DATANODES("ds_${0..1}.t_order_item_${0..1}"),
+TABLE_STRATEGY(TYPE="complex", SHARDING_COLUMNS=order_id, user_id,
SHARDING_ALGORITHM=t_order_item_inline),
+KEY_GENERATE_STRATEGY(COLUMN=order_item_id, KEY_GENERATOR=snowflake)
+);
+CREATE SHARDING BINDING TABLE RULES (t_order,t_order_item);
diff --git
a/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/statement/distsql/ral/impl/QueryableRALStatementAssert.java
b/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/statement/distsql/ral/impl/QueryableRALStatementAssert.java
index 20c96a6d999..3da542006d2 100644
---
a/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/statement/distsql/ral/impl/QueryableRALStatementAssert.java
+++
b/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/statement/distsql/ral/impl/QueryableRALStatementAssert.java
@@ -22,6 +22,7 @@ import lombok.NoArgsConstructor;
import
org.apache.shardingsphere.authority.distsql.parser.statement.ShowAuthorityRuleStatement;
import
org.apache.shardingsphere.distsql.parser.statement.ral.QueryableRALStatement;
import
org.apache.shardingsphere.distsql.parser.statement.ral.queryable.ExportDatabaseConfigurationStatement;
+import
org.apache.shardingsphere.distsql.parser.statement.ral.queryable.ConvertYamlConfigurationStatement;
import
org.apache.shardingsphere.distsql.parser.statement.ral.queryable.ShowAllVariableStatement;
import
org.apache.shardingsphere.distsql.parser.statement.ral.queryable.ShowInstanceInfoStatement;
import
org.apache.shardingsphere.distsql.parser.statement.ral.queryable.ShowInstanceListStatement;
@@ -34,6 +35,7 @@ import
org.apache.shardingsphere.distsql.parser.statement.ral.queryable.ShowVari
import
org.apache.shardingsphere.readwritesplitting.distsql.parser.statement.ShowReadwriteSplittingReadResourcesStatement;
import
org.apache.shardingsphere.test.sql.parser.parameterized.asserts.SQLCaseAssertContext;
import
org.apache.shardingsphere.test.sql.parser.parameterized.asserts.statement.distsql.ral.impl.queryable.ExportDatabaseConfigurationStatementAssert;
+import
org.apache.shardingsphere.test.sql.parser.parameterized.asserts.statement.distsql.ral.impl.queryable.ConvertYamlConfigurationStatementAssert;
import
org.apache.shardingsphere.test.sql.parser.parameterized.asserts.statement.distsql.ral.impl.queryable.ShowAllVariableStatementAssert;
import
org.apache.shardingsphere.test.sql.parser.parameterized.asserts.statement.distsql.ral.impl.queryable.ShowAuthorityRuleStatementAssert;
import
org.apache.shardingsphere.test.sql.parser.parameterized.asserts.statement.distsql.ral.impl.queryable.ShowInstanceInfoStatementAssert;
@@ -48,6 +50,7 @@ import
org.apache.shardingsphere.test.sql.parser.parameterized.asserts.statement
import
org.apache.shardingsphere.test.sql.parser.parameterized.asserts.statement.distsql.ral.impl.queryable.ShowVariableStatementAssert;
import
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.SQLParserTestCase;
import
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.distsql.ral.ExportDatabaseConfigurationStatementTestCase;
+import
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.distsql.ral.ConvertYamlConfigurationStatementTestCase;
import
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.distsql.ral.ShowAllVariableStatementTestCase;
import
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.distsql.ral.ShowAuthorityRuleStatementTestCase;
import
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.distsql.ral.ShowInstanceInfoStatementTestCase;
@@ -103,6 +106,8 @@ public final class QueryableRALStatementAssert {
ShowInstanceInfoStatementAssert.assertIs(assertContext,
(ShowInstanceInfoStatement) actual, (ShowInstanceInfoStatementTestCase)
expected);
} else if (actual instanceof ShowModeInfoStatement) {
ShowModeInfoStatementAssert.assertIs(assertContext,
(ShowModeInfoStatement) actual, (ShowModeInfoStatementTestCase) expected);
+ } else if (actual instanceof ConvertYamlConfigurationStatement) {
+ ConvertYamlConfigurationStatementAssert.assertIs(assertContext,
(ConvertYamlConfigurationStatement) actual,
(ConvertYamlConfigurationStatementTestCase) expected);
}
}
}
diff --git
a/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/statement/distsql/ral/impl/queryable/ConvertYamlConfigurationStatementAssert.java
b/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/statement/distsql/ral/impl/queryable/ConvertYamlConfigurationStatementAssert.java
new file mode 100644
index 00000000000..30b58ae0e1f
--- /dev/null
+++
b/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/statement/distsql/ral/impl/queryable/ConvertYamlConfigurationStatementAssert.java
@@ -0,0 +1,48 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package
org.apache.shardingsphere.test.sql.parser.parameterized.asserts.statement.distsql.ral.impl.queryable;
+
+import
org.apache.shardingsphere.distsql.parser.statement.ral.queryable.ConvertYamlConfigurationStatement;
+import
org.apache.shardingsphere.test.sql.parser.parameterized.asserts.SQLCaseAssertContext;
+import
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.distsql.ral.ConvertYamlConfigurationStatementTestCase;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertThat;
+
+/**
+ * Convert yaml configuration statement assert.
+ */
+public final class ConvertYamlConfigurationStatementAssert {
+
+ /**
+ * Assert convert yaml configuration statement is correct with expected
parser result.
+ *
+ * @param assertContext assert context
+ * @param actual actual convert yaml configuration statement statement
+ * @param expected expected convert configuration database statement
statement test case
+ */
+ public static void assertIs(final SQLCaseAssertContext assertContext,
final ConvertYamlConfigurationStatement actual,
+ final
ConvertYamlConfigurationStatementTestCase expected) {
+ if (null == expected) {
+ assertNull(assertContext.getText("Actual statement should no
exist."), actual);
+ } else {
+ assertThat(actual.getFilePath(), is(expected.getFilePath()));
+ }
+ }
+}
diff --git
a/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/jaxb/cases/domain/SQLParserTestCases.java
b/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/jaxb/cases/domain/SQLParserTestCases.java
index 2fb8481c36e..3e5ac55bd08 100644
---
a/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/jaxb/cases/domain/SQLParserTestCases.java
+++
b/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/jaxb/cases/domain/SQLParserTestCases.java
@@ -283,6 +283,7 @@ import
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain
import
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.distsql.ral.DiscardDistSQLStatementTestCase;
import
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.distsql.ral.DropTrafficRuleStatementTestCase;
import
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.distsql.ral.ExportDatabaseConfigurationStatementTestCase;
+import
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.distsql.ral.ConvertYamlConfigurationStatementTestCase;
import
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.distsql.ral.ImportDatabaseConfigurationStatementTestCase;
import
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.distsql.ral.LabelInstanceStatementTestCase;
import
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.distsql.ral.PrepareDistSQLStatementTestCase;
@@ -1443,6 +1444,9 @@ public final class SQLParserTestCases {
@XmlElement(name = "export-database-config")
private final List<ExportDatabaseConfigurationStatementTestCase>
exportDatabaseConfigurationTestCases = new LinkedList<>();
+ @XmlElement(name = "convert-yaml-config")
+ private final List<ConvertYamlConfigurationStatementTestCase>
convertYamlConfigurationStatementTestCases = new LinkedList<>();
+
@XmlElement(name = "show-rules-used-resource")
private final List<ShowRulesUsedResourceStatementTestCase>
showRulesUsedResourceTestCases = new LinkedList<>();
diff --git
a/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/jaxb/cases/domain/statement/distsql/ral/ConvertYamlConfigurationStatementTestCase.java
b/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/jaxb/cases/domain/statement/distsql/ral/ConvertYamlConfigurationStatementTestCase.java
new file mode 100644
index 00000000000..5ddede11f42
--- /dev/null
+++
b/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/jaxb/cases/domain/statement/distsql/ral/ConvertYamlConfigurationStatementTestCase.java
@@ -0,0 +1,35 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.distsql.ral;
+
+import lombok.Getter;
+import lombok.Setter;
+import
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.SQLParserTestCase;
+
+import javax.xml.bind.annotation.XmlElement;
+
+/**
+ * Convert yaml configuration statement test case.
+ */
+@Getter
+@Setter
+public class ConvertYamlConfigurationStatementTestCase extends
SQLParserTestCase {
+
+ @XmlElement(name = "filePath")
+ private String filePath;
+}
diff --git
a/shardingsphere-test/shardingsphere-parser-test/src/main/resources/case/ral/queryable.xml
b/shardingsphere-test/shardingsphere-parser-test/src/main/resources/case/ral/queryable.xml
index 07d76fcbceb..14dc9962db1 100644
---
a/shardingsphere-test/shardingsphere-parser-test/src/main/resources/case/ral/queryable.xml
+++
b/shardingsphere-test/shardingsphere-parser-test/src/main/resources/case/ral/queryable.xml
@@ -40,4 +40,7 @@
<export-database-config sql-case-id="export-database-config">
<database name="database_name" start-index="28" stop-index="40" />
</export-database-config>
+ <convert-yaml-config sql-case-id="convert-yaml-config">
+ <filePath>/yaml/config-resource.yaml</filePath>
+ </convert-yaml-config>
</sql-parser-test-cases>
diff --git
a/shardingsphere-test/shardingsphere-parser-test/src/main/resources/sql/supported/ral/queryable.xml
b/shardingsphere-test/shardingsphere-parser-test/src/main/resources/sql/supported/ral/queryable.xml
index 124fc6354a3..6c4fcdaf9aa 100644
---
a/shardingsphere-test/shardingsphere-parser-test/src/main/resources/sql/supported/ral/queryable.xml
+++
b/shardingsphere-test/shardingsphere-parser-test/src/main/resources/sql/supported/ral/queryable.xml
@@ -35,4 +35,5 @@
<distsql-case id="show-mode-info" value="SHOW MODE INFO" />
<distsql-case id="export-database-config" value="EXPORT DATABASE CONFIG
FROM database_name" />
+ <distsql-case id="convert-yaml-config" value="CONVERT YAML CONFIG
FILE='/yaml/config-resource.yaml'" />
</sql-cases>