This is an automated email from the ASF dual-hosted git repository.
zhangliang 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 9657f56ccda Use parameterized DistSQLDatabaseRuleQueryExecutorAssert
to instead of DistSQLDatabaseRuleQueryExecutorTest (#37140)
9657f56ccda is described below
commit 9657f56ccda37a16412bf557e8c3ea0614513749
Author: Liang Zhang <[email protected]>
AuthorDate: Wed Nov 19 17:43:23 2025 +0800
Use parameterized DistSQLDatabaseRuleQueryExecutorAssert to instead of
DistSQLDatabaseRuleQueryExecutorTest (#37140)
---
.../ShowDefaultShadowAlgorithmExecutorTest.java | 50 ++++----------------
.../query/ShowShadowAlgorithmsExecutorTest.java | 49 ++++----------------
.../handler/query/ShowShadowRuleExecutorTest.java | 53 ++++------------------
.../query/ShowShadowTableRulesExecutorTest.java | 50 ++++----------------
...ow-default-shadow-algorithm-current-config.yaml | 29 ++++++++++++
.../cases/show-default-shadow-algorithm.xml | 27 +++++++++++
.../show-shadow-algorithms-current-config.yaml | 28 ++++++++++++
.../resources/cases/show-shadow-algorithms.xml | 27 +++++++++++
.../cases/show-shadow-rule-current-config.yaml | 37 +++++++++++++++
.../src/test/resources/cases/show-shadow-rule.xml | 40 ++++++++++++++++
.../show-shadow-table-rules-current-config.yaml | 29 ++++++++++++
.../resources/cases/show-shadow-table-rules.xml | 34 ++++++++++++++
.../parser/core/ShadowDistSQLStatementVisitor.java | 26 ++++++-----
13 files changed, 305 insertions(+), 174 deletions(-)
diff --git
a/features/shadow/distsql/handler/src/test/java/org/apache/shardingsphere/shadow/distsql/handler/query/ShowDefaultShadowAlgorithmExecutorTest.java
b/features/shadow/distsql/handler/src/test/java/org/apache/shardingsphere/shadow/distsql/handler/query/ShowDefaultShadowAlgorithmExecutorTest.java
index 8937e115205..4bc4ebf34b0 100644
---
a/features/shadow/distsql/handler/src/test/java/org/apache/shardingsphere/shadow/distsql/handler/query/ShowDefaultShadowAlgorithmExecutorTest.java
+++
b/features/shadow/distsql/handler/src/test/java/org/apache/shardingsphere/shadow/distsql/handler/query/ShowDefaultShadowAlgorithmExecutorTest.java
@@ -18,57 +18,27 @@
package org.apache.shardingsphere.shadow.distsql.handler.query;
import org.apache.shardingsphere.distsql.statement.DistSQLStatement;
-import
org.apache.shardingsphere.infra.algorithm.core.config.AlgorithmConfiguration;
-import
org.apache.shardingsphere.infra.config.rule.scope.DatabaseRuleConfiguration;
import
org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
-import org.apache.shardingsphere.infra.util.props.PropertiesBuilder;
-import org.apache.shardingsphere.infra.util.props.PropertiesBuilder.Property;
import org.apache.shardingsphere.shadow.config.ShadowRuleConfiguration;
-import org.apache.shardingsphere.shadow.config.table.ShadowTableConfiguration;
-import
org.apache.shardingsphere.shadow.distsql.statement.ShowDefaultShadowAlgorithmStatement;
import org.apache.shardingsphere.shadow.rule.ShadowRule;
-import
org.apache.shardingsphere.test.it.distsql.handler.engine.query.DistSQLDatabaseRuleQueryExecutorTest;
-import org.junit.jupiter.api.extension.ExtensionContext;
+import
org.apache.shardingsphere.test.it.distsql.handler.engine.query.DistSQLDatabaseRuleQueryExecutorAssert;
+import
org.apache.shardingsphere.test.it.distsql.handler.engine.query.DistSQLRuleQueryExecutorSettings;
+import
org.apache.shardingsphere.test.it.distsql.handler.engine.query.DistSQLRuleQueryExecutorTestCaseArgumentsProvider;
import org.junit.jupiter.params.ParameterizedTest;
-import org.junit.jupiter.params.provider.Arguments;
-import org.junit.jupiter.params.provider.ArgumentsProvider;
import org.junit.jupiter.params.provider.ArgumentsSource;
-import org.junit.jupiter.params.support.ParameterDeclarations;
import java.sql.SQLException;
import java.util.Collection;
-import java.util.Collections;
-import java.util.stream.Stream;
import static org.mockito.Mockito.mock;
-class ShowDefaultShadowAlgorithmExecutorTest extends
DistSQLDatabaseRuleQueryExecutorTest {
+@DistSQLRuleQueryExecutorSettings("cases/show-default-shadow-algorithm.xml")
+class ShowDefaultShadowAlgorithmExecutorTest {
- ShowDefaultShadowAlgorithmExecutorTest() {
- super(mock(ShadowRule.class));
- }
-
- @ParameterizedTest(name = "{0}")
- @ArgumentsSource(TestCaseArgumentsProvider.class)
- void assertExecuteQuery(final String name, final DatabaseRuleConfiguration
ruleConfig, final DistSQLStatement sqlStatement,
- final Collection<LocalDataQueryResultRow>
expected) throws SQLException {
- assertQueryResultRows(ruleConfig, sqlStatement, expected);
- }
-
- private static final class TestCaseArgumentsProvider implements
ArgumentsProvider {
-
- @Override
- public Stream<? extends Arguments> provideArguments(final
ParameterDeclarations parameters, final ExtensionContext context) {
- return Stream.of(Arguments.arguments("normal",
createRuleConfiguration(), new ShowDefaultShadowAlgorithmStatement(null),
- Collections.singleton(new
LocalDataQueryResultRow("shadowAlgorithmName", "sql_hint",
"{\"foo\":\"bar\"}"))));
- }
-
- private ShadowRuleConfiguration createRuleConfiguration() {
- ShadowRuleConfiguration result = new ShadowRuleConfiguration();
- result.getTables().put("t_order", new
ShadowTableConfiguration(Collections.emptyList(),
Collections.singleton("shadowAlgorithmName")));
- result.getShadowAlgorithms().put("shadowAlgorithmName", new
AlgorithmConfiguration("sql_hint", PropertiesBuilder.build(new Property("foo",
"bar"))));
- result.setDefaultShadowAlgorithmName("shadowAlgorithmName");
- return result;
- }
+ @ParameterizedTest(name = "DistSQL -> {0}")
+ @ArgumentsSource(DistSQLRuleQueryExecutorTestCaseArgumentsProvider.class)
+ void assertExecuteQuery(@SuppressWarnings("unused") final String distSQL,
final DistSQLStatement sqlStatement,
+ final ShadowRuleConfiguration currentRuleConfig,
final Collection<LocalDataQueryResultRow> expected) throws SQLException {
+ new
DistSQLDatabaseRuleQueryExecutorAssert(mock(ShadowRule.class)).assertQueryResultRows(currentRuleConfig,
sqlStatement, expected);
}
}
diff --git
a/features/shadow/distsql/handler/src/test/java/org/apache/shardingsphere/shadow/distsql/handler/query/ShowShadowAlgorithmsExecutorTest.java
b/features/shadow/distsql/handler/src/test/java/org/apache/shardingsphere/shadow/distsql/handler/query/ShowShadowAlgorithmsExecutorTest.java
index 532996948ba..1c193c36632 100644
---
a/features/shadow/distsql/handler/src/test/java/org/apache/shardingsphere/shadow/distsql/handler/query/ShowShadowAlgorithmsExecutorTest.java
+++
b/features/shadow/distsql/handler/src/test/java/org/apache/shardingsphere/shadow/distsql/handler/query/ShowShadowAlgorithmsExecutorTest.java
@@ -18,56 +18,27 @@
package org.apache.shardingsphere.shadow.distsql.handler.query;
import org.apache.shardingsphere.distsql.statement.DistSQLStatement;
-import
org.apache.shardingsphere.infra.algorithm.core.config.AlgorithmConfiguration;
-import
org.apache.shardingsphere.infra.config.rule.scope.DatabaseRuleConfiguration;
import
org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
-import org.apache.shardingsphere.infra.util.props.PropertiesBuilder;
-import org.apache.shardingsphere.infra.util.props.PropertiesBuilder.Property;
import org.apache.shardingsphere.shadow.config.ShadowRuleConfiguration;
-import org.apache.shardingsphere.shadow.config.table.ShadowTableConfiguration;
-import
org.apache.shardingsphere.shadow.distsql.statement.ShowShadowAlgorithmsStatement;
import org.apache.shardingsphere.shadow.rule.ShadowRule;
-import
org.apache.shardingsphere.test.it.distsql.handler.engine.query.DistSQLDatabaseRuleQueryExecutorTest;
-import org.junit.jupiter.api.extension.ExtensionContext;
+import
org.apache.shardingsphere.test.it.distsql.handler.engine.query.DistSQLDatabaseRuleQueryExecutorAssert;
+import
org.apache.shardingsphere.test.it.distsql.handler.engine.query.DistSQLRuleQueryExecutorSettings;
+import
org.apache.shardingsphere.test.it.distsql.handler.engine.query.DistSQLRuleQueryExecutorTestCaseArgumentsProvider;
import org.junit.jupiter.params.ParameterizedTest;
-import org.junit.jupiter.params.provider.Arguments;
-import org.junit.jupiter.params.provider.ArgumentsProvider;
import org.junit.jupiter.params.provider.ArgumentsSource;
-import org.junit.jupiter.params.support.ParameterDeclarations;
import java.sql.SQLException;
import java.util.Collection;
-import java.util.Collections;
-import java.util.stream.Stream;
import static org.mockito.Mockito.mock;
-class ShowShadowAlgorithmsExecutorTest extends
DistSQLDatabaseRuleQueryExecutorTest {
+@DistSQLRuleQueryExecutorSettings("cases/show-shadow-algorithms.xml")
+class ShowShadowAlgorithmsExecutorTest {
- ShowShadowAlgorithmsExecutorTest() {
- super(mock(ShadowRule.class));
- }
-
- @ParameterizedTest(name = "{0}")
- @ArgumentsSource(TestCaseArgumentsProvider.class)
- void assertExecuteQuery(final String name, final DatabaseRuleConfiguration
ruleConfig, final DistSQLStatement sqlStatement,
- final Collection<LocalDataQueryResultRow>
expected) throws SQLException {
- assertQueryResultRows(ruleConfig, sqlStatement, expected);
- }
-
- private static final class TestCaseArgumentsProvider implements
ArgumentsProvider {
-
- @Override
- public Stream<? extends Arguments> provideArguments(final
ParameterDeclarations parameters, final ExtensionContext context) {
- return Stream.of(Arguments.arguments("normal",
createRuleConfiguration(), new ShowShadowAlgorithmsStatement(null),
- Collections.singleton(new
LocalDataQueryResultRow("shadowAlgorithmName", "sql_hint", "{\"foo\":\"bar\"}",
"false"))));
- }
-
- private ShadowRuleConfiguration createRuleConfiguration() {
- ShadowRuleConfiguration result = new ShadowRuleConfiguration();
- result.getTables().put("t_order", new
ShadowTableConfiguration(Collections.emptyList(),
Collections.singleton("shadowAlgorithmName")));
- result.getShadowAlgorithms().put("shadowAlgorithmName", new
AlgorithmConfiguration("sql_hint", PropertiesBuilder.build(new Property("foo",
"bar"))));
- return result;
- }
+ @ParameterizedTest(name = "DistSQL -> {0}")
+ @ArgumentsSource(DistSQLRuleQueryExecutorTestCaseArgumentsProvider.class)
+ void assertExecuteQuery(@SuppressWarnings("unused") final String distSQL,
final DistSQLStatement sqlStatement,
+ final ShadowRuleConfiguration currentRuleConfig,
final Collection<LocalDataQueryResultRow> expected) throws SQLException {
+ new
DistSQLDatabaseRuleQueryExecutorAssert(mock(ShadowRule.class)).assertQueryResultRows(currentRuleConfig,
sqlStatement, expected);
}
}
diff --git
a/features/shadow/distsql/handler/src/test/java/org/apache/shardingsphere/shadow/distsql/handler/query/ShowShadowRuleExecutorTest.java
b/features/shadow/distsql/handler/src/test/java/org/apache/shardingsphere/shadow/distsql/handler/query/ShowShadowRuleExecutorTest.java
index b6290fe044b..10bb27b2a5d 100644
---
a/features/shadow/distsql/handler/src/test/java/org/apache/shardingsphere/shadow/distsql/handler/query/ShowShadowRuleExecutorTest.java
+++
b/features/shadow/distsql/handler/src/test/java/org/apache/shardingsphere/shadow/distsql/handler/query/ShowShadowRuleExecutorTest.java
@@ -18,60 +18,27 @@
package org.apache.shardingsphere.shadow.distsql.handler.query;
import org.apache.shardingsphere.distsql.statement.DistSQLStatement;
-import
org.apache.shardingsphere.infra.algorithm.core.config.AlgorithmConfiguration;
-import
org.apache.shardingsphere.infra.config.rule.scope.DatabaseRuleConfiguration;
import
org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
import org.apache.shardingsphere.shadow.config.ShadowRuleConfiguration;
-import
org.apache.shardingsphere.shadow.config.datasource.ShadowDataSourceConfiguration;
-import org.apache.shardingsphere.shadow.config.table.ShadowTableConfiguration;
-import
org.apache.shardingsphere.shadow.distsql.statement.ShowShadowRulesStatement;
import org.apache.shardingsphere.shadow.rule.ShadowRule;
-import
org.apache.shardingsphere.test.it.distsql.handler.engine.query.DistSQLDatabaseRuleQueryExecutorTest;
-import org.junit.jupiter.api.extension.ExtensionContext;
+import
org.apache.shardingsphere.test.it.distsql.handler.engine.query.DistSQLDatabaseRuleQueryExecutorAssert;
+import
org.apache.shardingsphere.test.it.distsql.handler.engine.query.DistSQLRuleQueryExecutorSettings;
+import
org.apache.shardingsphere.test.it.distsql.handler.engine.query.DistSQLRuleQueryExecutorTestCaseArgumentsProvider;
import org.junit.jupiter.params.ParameterizedTest;
-import org.junit.jupiter.params.provider.Arguments;
-import org.junit.jupiter.params.provider.ArgumentsProvider;
import org.junit.jupiter.params.provider.ArgumentsSource;
-import org.junit.jupiter.params.support.ParameterDeclarations;
import java.sql.SQLException;
-import java.util.Arrays;
import java.util.Collection;
-import java.util.Collections;
-import java.util.Properties;
-import java.util.stream.Stream;
import static org.mockito.Mockito.mock;
-class ShowShadowRuleExecutorTest extends DistSQLDatabaseRuleQueryExecutorTest {
+@DistSQLRuleQueryExecutorSettings("cases/show-shadow-rule.xml")
+class ShowShadowRuleExecutorTest {
- ShowShadowRuleExecutorTest() {
- super(mock(ShadowRule.class));
- }
-
- @ParameterizedTest(name = "{0}")
- @ArgumentsSource(TestCaseArgumentsProvider.class)
- void assertExecuteQuery(final String name, final DatabaseRuleConfiguration
ruleConfig, final DistSQLStatement sqlStatement,
- final Collection<LocalDataQueryResultRow>
expected) throws SQLException {
- assertQueryResultRows(ruleConfig, sqlStatement, expected);
- }
-
- private static final class TestCaseArgumentsProvider implements
ArgumentsProvider {
-
- @Override
- public Stream<? extends Arguments> provideArguments(final
ParameterDeclarations parameters, final ExtensionContext context) {
- return Stream.of(Arguments.arguments("normal",
createRuleConfiguration(), new ShowShadowRulesStatement(null, null),
- Arrays.asList(new LocalDataQueryResultRow("t_order",
"shadow_rule", "source", "shadow", "REGEX_MATCH", ""),
- new LocalDataQueryResultRow("t_order_item",
"shadow_rule", "source", "shadow", "REGEX_MATCH", ""))));
- }
-
- private ShadowRuleConfiguration createRuleConfiguration() {
- ShadowRuleConfiguration result = new ShadowRuleConfiguration();
- result.getDataSources().add(new
ShadowDataSourceConfiguration("shadow_rule", "source", "shadow"));
- result.getShadowAlgorithms().put("user_id_select_match_algorithm",
new AlgorithmConfiguration("REGEX_MATCH", new Properties()));
- result.getTables().put("t_order", new
ShadowTableConfiguration(Collections.singleton("shadow_rule"),
Collections.singleton("user_id_select_match_algorithm")));
- result.getTables().put("t_order_item", new
ShadowTableConfiguration(Collections.singleton("shadow_rule"),
Collections.singleton("user_id_select_match_algorithm")));
- return result;
- }
+ @ParameterizedTest(name = "DistSQL -> {0}")
+ @ArgumentsSource(DistSQLRuleQueryExecutorTestCaseArgumentsProvider.class)
+ void assertExecuteQuery(@SuppressWarnings("unused") final String distSQL,
final DistSQLStatement sqlStatement,
+ final ShadowRuleConfiguration currentRuleConfig,
final Collection<LocalDataQueryResultRow> expected) throws SQLException {
+ new
DistSQLDatabaseRuleQueryExecutorAssert(mock(ShadowRule.class)).assertQueryResultRows(currentRuleConfig,
sqlStatement, expected);
}
}
diff --git
a/features/shadow/distsql/handler/src/test/java/org/apache/shardingsphere/shadow/distsql/handler/query/ShowShadowTableRulesExecutorTest.java
b/features/shadow/distsql/handler/src/test/java/org/apache/shardingsphere/shadow/distsql/handler/query/ShowShadowTableRulesExecutorTest.java
index b740513aaba..4bf11313da3 100644
---
a/features/shadow/distsql/handler/src/test/java/org/apache/shardingsphere/shadow/distsql/handler/query/ShowShadowTableRulesExecutorTest.java
+++
b/features/shadow/distsql/handler/src/test/java/org/apache/shardingsphere/shadow/distsql/handler/query/ShowShadowTableRulesExecutorTest.java
@@ -18,57 +18,27 @@
package org.apache.shardingsphere.shadow.distsql.handler.query;
import org.apache.shardingsphere.distsql.statement.DistSQLStatement;
-import
org.apache.shardingsphere.infra.algorithm.core.config.AlgorithmConfiguration;
-import
org.apache.shardingsphere.infra.config.rule.scope.DatabaseRuleConfiguration;
import
org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
-import org.apache.shardingsphere.infra.util.props.PropertiesBuilder;
-import org.apache.shardingsphere.infra.util.props.PropertiesBuilder.Property;
import org.apache.shardingsphere.shadow.config.ShadowRuleConfiguration;
-import org.apache.shardingsphere.shadow.config.table.ShadowTableConfiguration;
-import
org.apache.shardingsphere.shadow.distsql.statement.ShowShadowTableRulesStatement;
import org.apache.shardingsphere.shadow.rule.ShadowRule;
-import
org.apache.shardingsphere.test.it.distsql.handler.engine.query.DistSQLDatabaseRuleQueryExecutorTest;
-import org.junit.jupiter.api.extension.ExtensionContext;
+import
org.apache.shardingsphere.test.it.distsql.handler.engine.query.DistSQLDatabaseRuleQueryExecutorAssert;
+import
org.apache.shardingsphere.test.it.distsql.handler.engine.query.DistSQLRuleQueryExecutorSettings;
+import
org.apache.shardingsphere.test.it.distsql.handler.engine.query.DistSQLRuleQueryExecutorTestCaseArgumentsProvider;
import org.junit.jupiter.params.ParameterizedTest;
-import org.junit.jupiter.params.provider.Arguments;
-import org.junit.jupiter.params.provider.ArgumentsProvider;
import org.junit.jupiter.params.provider.ArgumentsSource;
-import org.junit.jupiter.params.support.ParameterDeclarations;
import java.sql.SQLException;
-import java.util.Arrays;
import java.util.Collection;
-import java.util.Collections;
-import java.util.stream.Stream;
import static org.mockito.Mockito.mock;
-class ShowShadowTableRulesExecutorTest extends
DistSQLDatabaseRuleQueryExecutorTest {
+@DistSQLRuleQueryExecutorSettings("cases/show-shadow-table-rules.xml")
+class ShowShadowTableRulesExecutorTest {
- ShowShadowTableRulesExecutorTest() {
- super(mock(ShadowRule.class));
- }
-
- @ParameterizedTest(name = "{0}")
- @ArgumentsSource(TestCaseArgumentsProvider.class)
- void assertExecuteQuery(final String name, final DatabaseRuleConfiguration
ruleConfig, final DistSQLStatement sqlStatement,
- final Collection<LocalDataQueryResultRow>
expected) throws SQLException {
- assertQueryResultRows(ruleConfig, sqlStatement, expected);
- }
-
- private static final class TestCaseArgumentsProvider implements
ArgumentsProvider {
-
- @Override
- public Stream<? extends Arguments> provideArguments(final
ParameterDeclarations parameters, final ExtensionContext context) {
- return Stream.of(Arguments.arguments("normal",
createRuleConfiguration(), new ShowShadowTableRulesStatement(null, null),
- Collections.singleton(new
LocalDataQueryResultRow("t_order",
"shadowAlgorithmName_1,shadowAlgorithmName_2"))));
- }
-
- private ShadowRuleConfiguration createRuleConfiguration() {
- ShadowRuleConfiguration result = new ShadowRuleConfiguration();
- result.getTables().put("t_order", new
ShadowTableConfiguration(Collections.emptyList(),
Arrays.asList("shadowAlgorithmName_1", "shadowAlgorithmName_2")));
- result.getShadowAlgorithms().put("shadowAlgorithmName", new
AlgorithmConfiguration("sql_hint", PropertiesBuilder.build(new Property("foo",
"bar"))));
- return result;
- }
+ @ParameterizedTest(name = "DistSQL -> {0}")
+ @ArgumentsSource(DistSQLRuleQueryExecutorTestCaseArgumentsProvider.class)
+ void assertExecuteQuery(@SuppressWarnings("unused") final String distSQL,
final DistSQLStatement sqlStatement,
+ final ShadowRuleConfiguration currentRuleConfig,
final Collection<LocalDataQueryResultRow> expected) throws SQLException {
+ new
DistSQLDatabaseRuleQueryExecutorAssert(mock(ShadowRule.class)).assertQueryResultRows(currentRuleConfig,
sqlStatement, expected);
}
}
diff --git
a/features/shadow/distsql/handler/src/test/resources/cases/show-default-shadow-algorithm-current-config.yaml
b/features/shadow/distsql/handler/src/test/resources/cases/show-default-shadow-algorithm-current-config.yaml
new file mode 100644
index 00000000000..a44945a1987
--- /dev/null
+++
b/features/shadow/distsql/handler/src/test/resources/cases/show-default-shadow-algorithm-current-config.yaml
@@ -0,0 +1,29 @@
+#
+# 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.
+#
+
+rules:
+ - !SHADOW
+ tables:
+ t_order:
+ shadowAlgorithmNames:
+ - shadowAlgorithmName
+ shadowAlgorithms:
+ shadowAlgorithmName:
+ type: sql_hint
+ props:
+ foo: bar
+ defaultShadowAlgorithmName: shadowAlgorithmName
diff --git
a/features/shadow/distsql/handler/src/test/resources/cases/show-default-shadow-algorithm.xml
b/features/shadow/distsql/handler/src/test/resources/cases/show-default-shadow-algorithm.xml
new file mode 100644
index 00000000000..0068c23cfe9
--- /dev/null
+++
b/features/shadow/distsql/handler/src/test/resources/cases/show-default-shadow-algorithm.xml
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ 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.
+ -->
+
+<distsql-rule-query-executor-test-cases>
+ <test-case dist-sql="SHOW DEFAULT SHADOW ALGORITHM FROM foo_db"
current-rule-config-yaml-file="cases/show-default-shadow-algorithm-current-config.yaml">
+ <expected-query-result-rows>
+ <expected-query-result-row>
+ shadowAlgorithmName|sql_hint|{"foo":"bar"}
+ </expected-query-result-row>
+ </expected-query-result-rows>
+ </test-case>
+</distsql-rule-query-executor-test-cases>
diff --git
a/features/shadow/distsql/handler/src/test/resources/cases/show-shadow-algorithms-current-config.yaml
b/features/shadow/distsql/handler/src/test/resources/cases/show-shadow-algorithms-current-config.yaml
new file mode 100644
index 00000000000..b13163cb7eb
--- /dev/null
+++
b/features/shadow/distsql/handler/src/test/resources/cases/show-shadow-algorithms-current-config.yaml
@@ -0,0 +1,28 @@
+#
+# 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.
+#
+
+rules:
+ - !SHADOW
+ tables:
+ t_order:
+ shadowAlgorithmNames:
+ - shadowAlgorithmName
+ shadowAlgorithms:
+ shadowAlgorithmName:
+ type: sql_hint
+ props:
+ foo: bar
diff --git
a/features/shadow/distsql/handler/src/test/resources/cases/show-shadow-algorithms.xml
b/features/shadow/distsql/handler/src/test/resources/cases/show-shadow-algorithms.xml
new file mode 100644
index 00000000000..f78817d65ac
--- /dev/null
+++
b/features/shadow/distsql/handler/src/test/resources/cases/show-shadow-algorithms.xml
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ 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.
+ -->
+
+<distsql-rule-query-executor-test-cases>
+ <test-case dist-sql="SHOW SHADOW ALGORITHMS FROM foo_db"
current-rule-config-yaml-file="cases/show-shadow-algorithms-current-config.yaml">
+ <expected-query-result-rows>
+ <expected-query-result-row>
+ shadowAlgorithmName|sql_hint|{"foo":"bar"}|false
+ </expected-query-result-row>
+ </expected-query-result-rows>
+ </test-case>
+</distsql-rule-query-executor-test-cases>
diff --git
a/features/shadow/distsql/handler/src/test/resources/cases/show-shadow-rule-current-config.yaml
b/features/shadow/distsql/handler/src/test/resources/cases/show-shadow-rule-current-config.yaml
new file mode 100644
index 00000000000..c3cd21048a7
--- /dev/null
+++
b/features/shadow/distsql/handler/src/test/resources/cases/show-shadow-rule-current-config.yaml
@@ -0,0 +1,37 @@
+#
+# 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.
+#
+
+rules:
+ - !SHADOW
+ dataSources:
+ shadow_rule:
+ productionDataSourceName: source
+ shadowDataSourceName: shadow
+ tables:
+ t_order:
+ dataSourceNames:
+ - shadow_rule
+ shadowAlgorithmNames:
+ - user-id-select-match-algorithm
+ t_order_item:
+ dataSourceNames:
+ - shadow_rule
+ shadowAlgorithmNames:
+ - user-id-select-match-algorithm
+ shadowAlgorithms:
+ user-id-select-match-algorithm:
+ type: REGEX_MATCH
diff --git
a/features/shadow/distsql/handler/src/test/resources/cases/show-shadow-rule.xml
b/features/shadow/distsql/handler/src/test/resources/cases/show-shadow-rule.xml
new file mode 100644
index 00000000000..ac1b768e49a
--- /dev/null
+++
b/features/shadow/distsql/handler/src/test/resources/cases/show-shadow-rule.xml
@@ -0,0 +1,40 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ 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.
+ -->
+
+<distsql-rule-query-executor-test-cases>
+ <test-case dist-sql="SHOW SHADOW RULES FROM foo_db"
current-rule-config-yaml-file="cases/show-shadow-rule-current-config.yaml">
+ <expected-query-result-rows>
+ <expected-query-result-row>
+ t_order|shadow_rule|source|shadow|REGEX_MATCH|
+ </expected-query-result-row>
+ <expected-query-result-row>
+ t_order_item|shadow_rule|source|shadow|REGEX_MATCH|
+ </expected-query-result-row>
+ </expected-query-result-rows>
+ </test-case>
+ <test-case dist-sql="SHOW SHADOW RULE shadow_rule FROM foo_db"
current-rule-config-yaml-file="cases/show-shadow-rule-current-config.yaml">
+ <expected-query-result-rows>
+ <expected-query-result-row>
+ t_order|shadow_rule|source|shadow|REGEX_MATCH|
+ </expected-query-result-row>
+ <expected-query-result-row>
+ t_order_item|shadow_rule|source|shadow|REGEX_MATCH|
+ </expected-query-result-row>
+ </expected-query-result-rows>
+ </test-case>
+</distsql-rule-query-executor-test-cases>
diff --git
a/features/shadow/distsql/handler/src/test/resources/cases/show-shadow-table-rules-current-config.yaml
b/features/shadow/distsql/handler/src/test/resources/cases/show-shadow-table-rules-current-config.yaml
new file mode 100644
index 00000000000..ef87e26d7de
--- /dev/null
+++
b/features/shadow/distsql/handler/src/test/resources/cases/show-shadow-table-rules-current-config.yaml
@@ -0,0 +1,29 @@
+#
+# 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.
+#
+
+rules:
+ - !SHADOW
+ tables:
+ t_order:
+ shadowAlgorithmNames:
+ - shadowAlgorithmName_1
+ - shadowAlgorithmName_2
+ shadowAlgorithms:
+ shadowAlgorithmName_1:
+ type: SQL_HINT
+ shadowAlgorithmName_2:
+ type: SQL_HINT
diff --git
a/features/shadow/distsql/handler/src/test/resources/cases/show-shadow-table-rules.xml
b/features/shadow/distsql/handler/src/test/resources/cases/show-shadow-table-rules.xml
new file mode 100644
index 00000000000..61fc4230eff
--- /dev/null
+++
b/features/shadow/distsql/handler/src/test/resources/cases/show-shadow-table-rules.xml
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ 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.
+ -->
+
+<distsql-rule-query-executor-test-cases>
+ <test-case dist-sql="SHOW SHADOW TABLE RULES FROM foo_db"
current-rule-config-yaml-file="cases/show-shadow-table-rules-current-config.yaml">
+ <expected-query-result-rows>
+ <expected-query-result-row>
+ t_order|shadowAlgorithmName_1,shadowAlgorithmName_2
+ </expected-query-result-row>
+ </expected-query-result-rows>
+ </test-case>
+ <test-case dist-sql="SHOW SHADOW TABLE RULE t_order FROM foo_db"
current-rule-config-yaml-file="cases/show-shadow-table-rules-current-config.yaml">
+ <expected-query-result-rows>
+ <expected-query-result-row>
+ t_order|shadowAlgorithmName_1,shadowAlgorithmName_2
+ </expected-query-result-row>
+ </expected-query-result-rows>
+ </test-case>
+</distsql-rule-query-executor-test-cases>
diff --git
a/features/shadow/distsql/parser/src/main/java/org/apache/shardingsphere/shadow/distsql/parser/core/ShadowDistSQLStatementVisitor.java
b/features/shadow/distsql/parser/src/main/java/org/apache/shardingsphere/shadow/distsql/parser/core/ShadowDistSQLStatementVisitor.java
index 51d03cd8cbb..b97720379cf 100644
---
a/features/shadow/distsql/parser/src/main/java/org/apache/shardingsphere/shadow/distsql/parser/core/ShadowDistSQLStatementVisitor.java
+++
b/features/shadow/distsql/parser/src/main/java/org/apache/shardingsphere/shadow/distsql/parser/core/ShadowDistSQLStatementVisitor.java
@@ -66,6 +66,7 @@ import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
+import java.util.Map.Entry;
import java.util.Properties;
import java.util.stream.Collectors;
@@ -97,6 +98,10 @@ public final class ShadowDistSQLStatementVisitor extends
ShadowDistSQLStatementB
return new ShadowRuleSegment(getIdentifierValue(ctx.ruleName()),
getIdentifierValue(ctx.source()), getIdentifierValue(ctx.shadow()),
shadowAlgorithms);
}
+ private Collection<ShadowAlgorithmSegment> visitShadowAlgorithms(final
List<AlgorithmDefinitionContext> contexts) {
+ return
contexts.stream().map(this::visit).map(ShadowAlgorithmSegment.class::cast).collect(Collectors.toList());
+ }
+
@Override
public ASTNode visitShowShadowAlgorithms(final ShowShadowAlgorithmsContext
ctx) {
return new ShowShadowAlgorithmsStatement(null == ctx.databaseName() ?
null : new FromDatabaseSegment(ctx.FROM().getSymbol().getStartIndex(),
(DatabaseSegment) visit(ctx.databaseName())));
@@ -157,18 +162,15 @@ public final class ShadowDistSQLStatementVisitor extends
ShadowDistSQLStatementB
@Override
public ASTNode visitShowShadowTableRules(final ShowShadowTableRulesContext
ctx) {
- return new ShowShadowTableRulesStatement(null == ctx.databaseName() ?
null : new FromDatabaseSegment(ctx.FROM().getSymbol().getStartIndex(),
(DatabaseSegment) visit(ctx.databaseName())),
- ctx.TABLE().getText());
+ FromDatabaseSegment fromDatabase = null == ctx.databaseName() ? null :
new FromDatabaseSegment(ctx.FROM().getSymbol().getStartIndex(),
(DatabaseSegment) visit(ctx.databaseName()));
+ String tableName = null == ctx.tableRule() ? null :
getIdentifierValue(ctx.tableRule().tableName());
+ return new ShowShadowTableRulesStatement(fromDatabase, tableName);
}
private String getIdentifierValue(final ParserRuleContext ctx) {
return null == ctx || ctx.isEmpty() ? null : new
IdentifierValue(ctx.getText()).getValue();
}
- private Collection<ShadowAlgorithmSegment> visitShadowAlgorithms(final
List<AlgorithmDefinitionContext> contexts) {
- return
contexts.stream().map(this::visit).map(ShadowAlgorithmSegment.class::cast).collect(Collectors.toList());
- }
-
@Override
public ASTNode visitDatabaseName(final DatabaseNameContext ctx) {
return new DatabaseSegment(ctx.getStart().getStartIndex(),
ctx.getStop().getStopIndex(), new IdentifierValue(ctx.getText()));
@@ -186,15 +188,15 @@ public final class ShadowDistSQLStatementVisitor extends
ShadowDistSQLStatementB
}
private void buildShadowRuleSegment(final Collection<ShadowRuleSegment>
collection, final ShadowRuleSegment shadowRuleSegment) {
- Map<String, Collection<ShadowAlgorithmSegment>> shadowTableRules = new
LinkedHashMap<>();
- shadowRuleSegment.getShadowTableRules().forEach((key, value) -> {
+ Map<String, Collection<ShadowAlgorithmSegment>> shadowTableRules = new
LinkedHashMap<>(shadowRuleSegment.getShadowTableRules().size(), 1F);
+ for (Entry<String, Collection<ShadowAlgorithmSegment>> entry :
shadowRuleSegment.getShadowTableRules().entrySet()) {
int index = 0;
Collection<ShadowAlgorithmSegment> shadowAlgorithmSegments = new
LinkedList<>();
- for (ShadowAlgorithmSegment shadowAlgorithmSegment : value) {
-
shadowAlgorithmSegments.add(buildShadowAlgorithmSegment(shadowRuleSegment.getRuleName(),
key, index++, shadowAlgorithmSegment));
+ for (ShadowAlgorithmSegment each : entry.getValue()) {
+
shadowAlgorithmSegments.add(buildShadowAlgorithmSegment(shadowRuleSegment.getRuleName(),
entry.getKey(), index++, each));
}
- shadowTableRules.put(key, shadowAlgorithmSegments);
- });
+ shadowTableRules.put(entry.getKey(), shadowAlgorithmSegments);
+ }
collection.add(new ShadowRuleSegment(shadowRuleSegment.getRuleName(),
shadowRuleSegment.getSource(), shadowRuleSegment.getShadow(),
shadowTableRules));
}