You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by pa...@apache.org on 2021/09/19 13:14:16 UTC
[shardingsphere] branch master updated: Shadow DistSQL show related
statements and `drop shadow algorithm` statement (#12564)
This is an automated email from the ASF dual-hosted git repository.
panjuan 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 1784854 Shadow DistSQL show related statements and `drop shadow algorithm` statement (#12564)
1784854 is described below
commit 1784854e789e8e2ed2d7bfcb9a68a7d8b039cf31
Author: lanchengx <52...@users.noreply.github.com>
AuthorDate: Sun Sep 19 08:13:40 2021 -0500
Shadow DistSQL show related statements and `drop shadow algorithm` statement (#12564)
* shadow DistSQL show statement
* shadow DistSQL show algorithms statement
* Shadow DistSQL drop algorithms statement
* show shadow rules related tests.
* show shadow algorithms related tests.
* fixed some bugs
* Add `show shadow table rules` statement
* Adjust `show rules` and `show algorithm` statement
* reformat
* Add `show shadow table rules` & `drop shadow algorithm` related tests
* Adjust naming and format
* Adjust naming and format
---
.../query/ShadowAlgorithmQueryResultSet.java | 84 +++++++++++++++
.../handler/query/ShadowRuleQueryResultSet.java | 120 +++++++++++++++++++++
.../query/ShadowTableRuleQueryResultSet.java | 95 ++++++++++++++++
.../DropShadowAlgorithmStatementUpdater.java | 103 ++++++++++++++++++
...ingsphere.infra.distsql.query.DistSQLResultSet} | 7 +-
...here.infra.distsql.update.RuleDefinitionUpdater | 1 +
.../query/ShadowAlgorithmQueryResultSetTest.java | 65 +++++++++++
.../query/ShadowRuleQueryResultSetTest.java | 64 +++++++++++
.../query/ShadowTableRuleQueryResultSetTest.java | 65 +++++++++++
.../src/main/antlr4/imports/shadow/RDLStatement.g4 | 7 +-
.../src/main/antlr4/imports/shadow/RQLStatement.g4 | 14 ++-
.../parser/autogen/ShadowDistSQLStatement.g4 | 4 +
.../parser/core/ShadowDistSQLStatementVisitor.java | 40 +++++++
.../statement/DropShadowAlgorithmStatement.java} | 26 ++---
.../statement/ShowShadowAlgorithmsStatement.java} | 27 ++---
.../statement/ShowShadowRulesStatement.java} | 30 +++---
.../statement/ShowShadowTableRulesStatement.java} | 27 ++---
.../distsql/DistSQLBackendHandlerFactoryTest.java | 49 +++++++++
.../impl/DropShadowAlgorithmStatementAssert.java | 52 +++++++++
.../distsql/rql/impl/ShowRulesStatementAssert.java | 10 ++
.../rule/ShowShadowAlgorithmsStatementAssert.java | 51 +++++++++
.../impl/rule/ShowShadowRulesStatementAssert.java | 51 +++++++++
.../rule/ShowShadowTableRulesStatementAssert.java | 51 +++++++++
.../jaxb/cases/domain/SQLParserTestCases.java | 20 ++++
.../drop/DropShadowAlgorithmStatementTestCase.java | 27 ++---
.../rql/ShowShadowAlgorithmsStatementTestCase.java | 28 ++---
.../rql/ShowShadowRulesStatementTestCase.java | 32 +++---
.../rql/ShowShadowTableRulesStatementTestCase.java | 28 ++---
.../src/main/resources/case/rdl/drop.xml | 5 +
.../src/main/resources/case/rql/show.xml | 12 +++
.../src/main/resources/sql/supported/rdl/drop.xml | 1 +
.../src/main/resources/sql/supported/rql/show.xml | 3 +
32 files changed, 1094 insertions(+), 105 deletions(-)
diff --git a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/query/ShadowAlgorithmQueryResultSet.java b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/query/ShadowAlgorithmQueryResultSet.java
new file mode 100644
index 0000000..afa3dd9
--- /dev/null
+++ b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/query/ShadowAlgorithmQueryResultSet.java
@@ -0,0 +1,84 @@
+/*
+ * 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.shadow.distsql.handler.query;
+
+import org.apache.shardingsphere.infra.config.algorithm.ShardingSphereAlgorithmConfiguration;
+import org.apache.shardingsphere.infra.distsql.query.DistSQLResultSet;
+import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
+import org.apache.shardingsphere.infra.properties.PropertiesConverter;
+import org.apache.shardingsphere.shadow.api.config.ShadowRuleConfiguration;
+import org.apache.shardingsphere.shadow.distsql.parser.statement.ShowShadowAlgorithmsStatement;
+import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.Map.Entry;
+import java.util.Objects;
+import java.util.Optional;
+import java.util.Properties;
+
+/**
+ * Result set for shadow algorithm.
+ */
+public final class ShadowAlgorithmQueryResultSet implements DistSQLResultSet {
+
+ private static final String SHADOW_ALGORITHM_NAME = "shadow_algorithm_name";
+
+ private static final String TYPE = "type";
+
+ private static final String PROPERTIES = "properties";
+
+ private Iterator<Entry<String, ShardingSphereAlgorithmConfiguration>> data = Collections.emptyIterator();
+
+ @Override
+ public void init(final ShardingSphereMetaData metaData, final SQLStatement sqlStatement) {
+ Optional<ShadowRuleConfiguration> rule = metaData.getRuleMetaData().getConfigurations()
+ .stream().filter(each -> each instanceof ShadowRuleConfiguration).map(each -> (ShadowRuleConfiguration) each).findAny();
+ rule.ifPresent(configuration -> data = configuration.getShadowAlgorithms().entrySet().iterator());
+ }
+
+ @Override
+ public Collection<String> getColumnNames() {
+ return Arrays.asList(SHADOW_ALGORITHM_NAME, TYPE, PROPERTIES);
+ }
+
+ @Override
+ public boolean next() {
+ return data.hasNext();
+ }
+
+ @Override
+ public Collection<Object> getRowData() {
+ return buildTableRowData(data.next());
+ }
+
+ private Collection<Object> buildTableRowData(final Entry<String, ShardingSphereAlgorithmConfiguration> data) {
+ return Arrays.asList(data.getKey(), data.getValue().getType(), convertToString(data.getValue().getProps()));
+ }
+
+ private String convertToString(final Properties props) {
+ return Objects.nonNull(props) ? PropertiesConverter.convert(props) : "";
+ }
+
+ @Override
+ public String getType() {
+ return ShowShadowAlgorithmsStatement.class.getCanonicalName();
+ }
+}
diff --git a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/query/ShadowRuleQueryResultSet.java b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/query/ShadowRuleQueryResultSet.java
new file mode 100644
index 0000000..01a75a2
--- /dev/null
+++ b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/query/ShadowRuleQueryResultSet.java
@@ -0,0 +1,120 @@
+/*
+ * 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.shadow.distsql.handler.query;
+
+import org.apache.shardingsphere.infra.distsql.query.DistSQLResultSet;
+import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
+import org.apache.shardingsphere.shadow.api.config.ShadowRuleConfiguration;
+import org.apache.shardingsphere.shadow.api.config.datasource.ShadowDataSourceConfiguration;
+import org.apache.shardingsphere.shadow.api.config.table.ShadowTableConfiguration;
+import org.apache.shardingsphere.shadow.distsql.parser.statement.ShowShadowRulesStatement;
+import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Optional;
+import java.util.stream.Collectors;
+
+/**
+ * Result set for show shadow rules.
+ */
+public final class ShadowRuleQueryResultSet implements DistSQLResultSet {
+
+ private static final String RULE_NAME = "rule_name";
+
+ private static final String SOURCE_NAME = "source_name";
+
+ private static final String SHADOW_NAME = "shadow_name";
+
+ private static final String SHADOW_TABLE = "shadow_table";
+
+ private Iterator<Map<String, String>> data = Collections.emptyIterator();
+
+ @Override
+ public void init(final ShardingSphereMetaData metaData, final SQLStatement sqlStatement) {
+ Optional<ShadowRuleConfiguration> ruleConfigurations = metaData.getRuleMetaData().getConfigurations().stream()
+ .filter(each -> each instanceof ShadowRuleConfiguration).map(each -> (ShadowRuleConfiguration) each).findAny();
+ ruleConfigurations.ifPresent(configuration -> buildDataSourceIterator(configuration, (ShowShadowRulesStatement) sqlStatement));
+ }
+
+ private void buildDataSourceIterator(final ShadowRuleConfiguration configuration, final ShowShadowRulesStatement sqlStatement) {
+ Map<String, Map<String, ShadowTableConfiguration>> dataSourceTableMap = convertToDataSourceTableMap(configuration.getTables());
+ Collection<Entry<String, ShadowDataSourceConfiguration>> specifiedConfigurations = !isSpecified(sqlStatement) ? configuration.getDataSources().entrySet()
+ : configuration.getDataSources().entrySet().stream().filter(entry -> entry.getKey().equalsIgnoreCase(sqlStatement.getRuleName())).collect(Collectors.toList());
+ data = specifiedConfigurations.stream().map(each -> buildDataItem(each, dataSourceTableMap)).collect(Collectors.toList()).iterator();
+ }
+
+ private Map<String, Map<String, ShadowTableConfiguration>> convertToDataSourceTableMap(final Map<String, ShadowTableConfiguration> tables) {
+ return tables.entrySet().stream().collect(Collectors.groupingBy(entry -> entry.getValue().getDataSourceName(), Collectors.toMap(Entry::getKey, Entry::getValue)));
+ }
+
+ private boolean isSpecified(final ShowShadowRulesStatement sqlStatement) {
+ return null != sqlStatement.getRuleName() && !sqlStatement.getRuleName().isEmpty();
+ }
+
+ private Map<String, String> buildDataItem(final Entry<String, ShadowDataSourceConfiguration> dataSource, final Map<String, Map<String, ShadowTableConfiguration>> dataSourceTableMap) {
+ Map<String, String> result = convertToDataSourceMap(dataSource);
+ Map<String, ShadowTableConfiguration> dataSourceTable = dataSourceTableMap.getOrDefault(result.get(RULE_NAME), Collections.emptyMap());
+ result.put(SHADOW_TABLE, convertToString(dataSourceTable.keySet()));
+ return result;
+ }
+
+ private Map<String, String> convertToDataSourceMap(final Entry<String, ShadowDataSourceConfiguration> dataSource) {
+ Map<String, String> result = new HashMap<>();
+ result.put(RULE_NAME, dataSource.getKey());
+ result.put(SOURCE_NAME, dataSource.getValue().getSourceDataSourceName());
+ result.put(SHADOW_NAME, dataSource.getValue().getShadowDataSourceName());
+ return result;
+ }
+
+ private String convertToString(final Collection<String> shadowTables) {
+ if (null != shadowTables) {
+ return String.join(",", shadowTables);
+ }
+ return "";
+ }
+
+ @Override
+ public Collection<String> getColumnNames() {
+ return Arrays.asList(RULE_NAME, SOURCE_NAME, SHADOW_NAME, SHADOW_TABLE);
+ }
+
+ @Override
+ public boolean next() {
+ return data.hasNext();
+ }
+
+ @Override
+ public Collection<Object> getRowData() {
+ return buildRowData(data.next());
+ }
+
+ private Collection<Object> buildRowData(final Map<String, String> data) {
+ return Arrays.asList(data.get(RULE_NAME), data.get(SOURCE_NAME), data.get(SHADOW_NAME), data.getOrDefault(SHADOW_TABLE, ""));
+ }
+
+ @Override
+ public String getType() {
+ return ShowShadowRulesStatement.class.getCanonicalName();
+ }
+}
diff --git a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/query/ShadowTableRuleQueryResultSet.java b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/query/ShadowTableRuleQueryResultSet.java
new file mode 100644
index 0000000..05e7455
--- /dev/null
+++ b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/query/ShadowTableRuleQueryResultSet.java
@@ -0,0 +1,95 @@
+/*
+ * 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.shadow.distsql.handler.query;
+
+import org.apache.shardingsphere.infra.distsql.query.DistSQLResultSet;
+import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
+import org.apache.shardingsphere.shadow.api.config.ShadowRuleConfiguration;
+import org.apache.shardingsphere.shadow.distsql.parser.statement.ShowShadowTableRulesStatement;
+import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+
+/**
+ * Result set for shadow table rule.
+ */
+public final class ShadowTableRuleQueryResultSet implements DistSQLResultSet {
+
+ private static final String SHADOW_TABLE = "shadow_table";
+
+ private static final String SHADOW_ALGORITHM_NAME = "shadow_algorithm_name";
+
+ private Iterator<Map<String, String>> data = Collections.emptyIterator();
+
+ @Override
+ public void init(final ShardingSphereMetaData metaData, final SQLStatement sqlStatement) {
+ Optional<ShadowRuleConfiguration> rule = metaData.getRuleMetaData().getConfigurations()
+ .stream().filter(each -> each instanceof ShadowRuleConfiguration).map(each -> (ShadowRuleConfiguration) each).findAny();
+ rule.ifPresent(configuration -> data = buildData(configuration).iterator());
+ }
+
+ private List<Map<String, String>> buildData(final ShadowRuleConfiguration shadowRuleConfiguration) {
+ List<Map<String, String>> result = new ArrayList<>();
+ shadowRuleConfiguration.getTables().forEach((key, value) -> {
+ Map<String, String> map = new HashMap<>();
+ map.put(SHADOW_TABLE, key);
+ map.put(SHADOW_ALGORITHM_NAME, convertToString(value.getShadowAlgorithmNames()));
+ result.add(map);
+ });
+ return result;
+ }
+
+ @Override
+ public Collection<String> getColumnNames() {
+ return Arrays.asList(SHADOW_TABLE, SHADOW_ALGORITHM_NAME);
+ }
+
+ @Override
+ public boolean next() {
+ return data.hasNext();
+ }
+
+ @Override
+ public Collection<Object> getRowData() {
+ return buildTableRowData(data.next());
+ }
+
+ private Collection<Object> buildTableRowData(final Map<String, String> data) {
+ return Arrays.asList(data.get(SHADOW_TABLE), data.get(SHADOW_ALGORITHM_NAME));
+ }
+
+ private String convertToString(final Collection<String> shadowTables) {
+ if (null != shadowTables) {
+ return String.join(",", shadowTables);
+ }
+ return "";
+ }
+
+ @Override
+ public String getType() {
+ return ShowShadowTableRulesStatement.class.getCanonicalName();
+ }
+}
diff --git a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/update/DropShadowAlgorithmStatementUpdater.java b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/update/DropShadowAlgorithmStatementUpdater.java
new file mode 100644
index 0000000..a3510d0
--- /dev/null
+++ b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/update/DropShadowAlgorithmStatementUpdater.java
@@ -0,0 +1,103 @@
+/*
+ * 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.shadow.distsql.handler.update;
+
+import org.apache.shardingsphere.infra.distsql.exception.DistSQLException;
+import org.apache.shardingsphere.infra.distsql.exception.rule.AlgorithmInUsedException;
+import org.apache.shardingsphere.infra.distsql.exception.rule.RequiredAlgorithmMissedException;
+import org.apache.shardingsphere.infra.distsql.exception.rule.RequiredRuleMissedException;
+import org.apache.shardingsphere.infra.distsql.update.RuleDefinitionDropUpdater;
+import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
+import org.apache.shardingsphere.shadow.api.config.ShadowRuleConfiguration;
+import org.apache.shardingsphere.shadow.api.config.table.ShadowTableConfiguration;
+import org.apache.shardingsphere.shadow.distsql.parser.statement.DropShadowAlgorithmStatement;
+
+import java.util.Collection;
+import java.util.Set;
+import java.util.function.Function;
+import java.util.stream.Collectors;
+
+/**
+ * Drop shadow algorithm statement updater.
+ */
+public final class DropShadowAlgorithmStatementUpdater implements RuleDefinitionDropUpdater<DropShadowAlgorithmStatement, ShadowRuleConfiguration> {
+
+ private static final String SHADOW = "shadow";
+
+ @Override
+ public void checkSQLStatement(final ShardingSphereMetaData metaData, final DropShadowAlgorithmStatement sqlStatement, final ShadowRuleConfiguration currentRuleConfig) throws DistSQLException {
+ String schemaName = metaData.getName();
+ checkConfigurationExist(schemaName, currentRuleConfig);
+ checkAlgorithm(schemaName, sqlStatement, currentRuleConfig);
+ }
+
+ private void checkAlgorithm(final String schemaName, final DropShadowAlgorithmStatement sqlStatement, final ShadowRuleConfiguration currentRuleConfig) throws DistSQLException {
+ Collection<String> currentAlgorithms = getCurrentAlgorithms(currentRuleConfig);
+ Collection<String> requireAlgorithms = sqlStatement.getAlgorithmNames();
+ checkDifferent(requireAlgorithms, currentAlgorithms, different -> new RequiredAlgorithmMissedException(SHADOW, schemaName, different));
+ checkIdentical(requireAlgorithms, getAlgorithmInUse(currentRuleConfig), identical -> new AlgorithmInUsedException(schemaName, identical));
+ }
+
+ private Set<String> getAlgorithmInUse(final ShadowRuleConfiguration currentRuleConfig) {
+ return currentRuleConfig.getTables().values().stream().map(ShadowTableConfiguration::getShadowAlgorithmNames).flatMap(Collection::stream).collect(Collectors.toSet());
+ }
+
+ private void checkConfigurationExist(final String schemaName, final ShadowRuleConfiguration currentRuleConfig) throws DistSQLException {
+ DistSQLException.predictionThrow(currentRuleConfig != null, new RequiredRuleMissedException(SHADOW, schemaName));
+ }
+
+ private void checkIdentical(final Collection<String> require, final Collection<String> current, final Function<Set<String>, DistSQLException> thrower) throws DistSQLException {
+ Set<String> identical = getIdentical(require, current);
+ DistSQLException.predictionThrow(identical.isEmpty(), thrower.apply(identical));
+ }
+
+ private void checkDifferent(final Collection<String> require, final Collection<String> current, final Function<Set<String>, DistSQLException> thrower) throws DistSQLException {
+ Set<String> duplicateRequire = getDifferent(require, current);
+ DistSQLException.predictionThrow(duplicateRequire.isEmpty(), thrower.apply(duplicateRequire));
+ }
+
+ private Set<String> getDifferent(final Collection<String> require, final Collection<String> current) {
+ return require.stream().filter(each -> !current.contains(each)).collect(Collectors.toSet());
+ }
+
+ private Set<String> getIdentical(final Collection<String> require, final Collection<String> current) {
+ return require.stream().filter(current::contains).collect(Collectors.toSet());
+ }
+
+ private Collection<String> getCurrentAlgorithms(final ShadowRuleConfiguration configuration) {
+ return configuration.getShadowAlgorithms().keySet();
+ }
+
+ @Override
+ public boolean updateCurrentRuleConfiguration(final DropShadowAlgorithmStatement sqlStatement, final ShadowRuleConfiguration currentRuleConfig) {
+ sqlStatement.getAlgorithmNames().forEach(each -> {
+ getCurrentAlgorithms(currentRuleConfig).removeIf(each::equalsIgnoreCase);
+ });
+ return false;
+ }
+
+ @Override
+ public Class<ShadowRuleConfiguration> getRuleConfigurationClass() {
+ return ShadowRuleConfiguration.class;
+ }
+
+ @Override
+ public String getType() {
+ return DropShadowAlgorithmStatement.class.getCanonicalName();
+ }
+}
diff --git a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-handler/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.distsql.update.RuleDefinitionUpdater b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-handler/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.distsql.query.DistSQLResultSet
similarity index 68%
copy from shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-handler/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.distsql.update.RuleDefinitionUpdater
copy to shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-handler/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.distsql.query.DistSQLResultSet
index 7af7586..caf8afc 100644
--- a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-handler/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.distsql.update.RuleDefinitionUpdater
+++ b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-handler/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.distsql.query.DistSQLResultSet
@@ -15,7 +15,6 @@
# limitations under the License.
#
-org.apache.shardingsphere.shadow.distsql.handler.update.DropShadowRuleStatementUpdater
-org.apache.shardingsphere.shadow.distsql.handler.update.CreateShadowRuleStatementUpdater
-org.apache.shardingsphere.shadow.distsql.handler.update.AlterShadowRuleStatementUpdater
-org.apache.shardingsphere.shadow.distsql.handler.update.AlterShadowAlgorithmStatementUpdater
+org.apache.shardingsphere.shadow.distsql.handler.query.ShadowRuleQueryResultSet
+org.apache.shardingsphere.shadow.distsql.handler.query.ShadowAlgorithmQueryResultSet
+org.apache.shardingsphere.shadow.distsql.handler.query.ShadowTableRuleQueryResultSet
diff --git a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-handler/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.distsql.update.RuleDefinitionUpdater b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-handler/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.distsql.update.RuleDefinitionUpdater
index 7af7586..0da4f67 100644
--- a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-handler/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.distsql.update.RuleDefinitionUpdater
+++ b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-handler/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.distsql.update.RuleDefinitionUpdater
@@ -17,5 +17,6 @@
org.apache.shardingsphere.shadow.distsql.handler.update.DropShadowRuleStatementUpdater
org.apache.shardingsphere.shadow.distsql.handler.update.CreateShadowRuleStatementUpdater
+org.apache.shardingsphere.shadow.distsql.handler.update.DropShadowAlgorithmStatementUpdater
org.apache.shardingsphere.shadow.distsql.handler.update.AlterShadowRuleStatementUpdater
org.apache.shardingsphere.shadow.distsql.handler.update.AlterShadowAlgorithmStatementUpdater
diff --git a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-handler/src/test/java/org/apache/shardingsphere/shadow/distsql/query/ShadowAlgorithmQueryResultSetTest.java b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-handler/src/test/java/org/apache/shardingsphere/shadow/distsql/query/ShadowAlgorithmQueryResultSetTest.java
new file mode 100644
index 0000000..416b438
--- /dev/null
+++ b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-handler/src/test/java/org/apache/shardingsphere/shadow/distsql/query/ShadowAlgorithmQueryResultSetTest.java
@@ -0,0 +1,65 @@
+/*
+ * 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.shadow.distsql.query;
+
+import org.apache.shardingsphere.infra.config.RuleConfiguration;
+import org.apache.shardingsphere.infra.config.algorithm.ShardingSphereAlgorithmConfiguration;
+import org.apache.shardingsphere.infra.distsql.query.DistSQLResultSet;
+import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
+import org.apache.shardingsphere.shadow.api.config.ShadowRuleConfiguration;
+import org.apache.shardingsphere.shadow.api.config.table.ShadowTableConfiguration;
+import org.apache.shardingsphere.shadow.distsql.handler.query.ShadowAlgorithmQueryResultSet;
+import org.apache.shardingsphere.shadow.distsql.parser.statement.ShowShadowAlgorithmsStatement;
+import org.junit.Test;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Properties;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+public final class ShadowAlgorithmQueryResultSetTest {
+
+ @Test
+ public void assertGetRowData() {
+ ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class, RETURNS_DEEP_STUBS);
+ when(metaData.getRuleMetaData().getConfigurations()).thenReturn(Collections.singleton(createRuleConfiguration()));
+ DistSQLResultSet resultSet = new ShadowAlgorithmQueryResultSet();
+ resultSet.init(metaData, mock(ShowShadowAlgorithmsStatement.class));
+ List<Object> actual = new ArrayList<>(resultSet.getRowData());
+ assertThat(actual.size(), is(3));
+ assertThat(actual.get(0), is("shadowAlgorithmName"));
+ assertThat(actual.get(1), is("simple_note"));
+ assertThat(actual.get(2), is("foo=bar"));
+ }
+
+ private RuleConfiguration createRuleConfiguration() {
+ // FIXME because the defined final attribute will be removed, here is just for the new object
+ ShadowRuleConfiguration result = new ShadowRuleConfiguration("removed", Collections.singletonList("removed"), Collections.singletonList("removed"));
+ Properties properties = new Properties();
+ properties.setProperty("foo", "bar");
+ result.getTables().put("t_order", new ShadowTableConfiguration("", Collections.singletonList("shadowAlgorithmName")));
+ result.getShadowAlgorithms().put("shadowAlgorithmName", new ShardingSphereAlgorithmConfiguration("simple_note", properties));
+ return result;
+ }
+}
diff --git a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-handler/src/test/java/org/apache/shardingsphere/shadow/distsql/query/ShadowRuleQueryResultSetTest.java b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-handler/src/test/java/org/apache/shardingsphere/shadow/distsql/query/ShadowRuleQueryResultSetTest.java
new file mode 100644
index 0000000..c40f932
--- /dev/null
+++ b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-handler/src/test/java/org/apache/shardingsphere/shadow/distsql/query/ShadowRuleQueryResultSetTest.java
@@ -0,0 +1,64 @@
+/*
+ * 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.shadow.distsql.query;
+
+import org.apache.shardingsphere.infra.config.RuleConfiguration;
+import org.apache.shardingsphere.infra.distsql.query.DistSQLResultSet;
+import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
+import org.apache.shardingsphere.shadow.api.config.ShadowRuleConfiguration;
+import org.apache.shardingsphere.shadow.api.config.datasource.ShadowDataSourceConfiguration;
+import org.apache.shardingsphere.shadow.api.config.table.ShadowTableConfiguration;
+import org.apache.shardingsphere.shadow.distsql.handler.query.ShadowRuleQueryResultSet;
+import org.apache.shardingsphere.shadow.distsql.parser.statement.ShowShadowRulesStatement;
+import org.junit.Test;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+public final class ShadowRuleQueryResultSetTest {
+
+ @Test
+ public void assertGetRowData() {
+ ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class, RETURNS_DEEP_STUBS);
+ when(metaData.getRuleMetaData().getConfigurations()).thenReturn(Collections.singleton(createRuleConfiguration()));
+ DistSQLResultSet resultSet = new ShadowRuleQueryResultSet();
+ resultSet.init(metaData, mock(ShowShadowRulesStatement.class));
+ List<Object> actual = new ArrayList<>(resultSet.getRowData());
+ assertThat(actual.size(), is(4));
+ assertThat(actual.get(0), is("shadow_rule"));
+ assertThat(actual.get(1), is("source"));
+ assertThat(actual.get(2), is("shadow"));
+ assertThat(actual.get(3), is("t_order,t_order_1"));
+ }
+
+ private RuleConfiguration createRuleConfiguration() {
+ // FIXME because the defined final attribute will be removed, here is just for the new object
+ ShadowRuleConfiguration result = new ShadowRuleConfiguration("removed", Collections.singletonList("removed"), Collections.singletonList("removed"));
+ result.getDataSources().put("shadow_rule", new ShadowDataSourceConfiguration("source", "shadow"));
+ result.getTables().put("t_order", new ShadowTableConfiguration("shadow_rule", Collections.emptyList()));
+ result.getTables().put("t_order_1", new ShadowTableConfiguration("shadow_rule", Collections.emptyList()));
+ return result;
+ }
+}
diff --git a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-handler/src/test/java/org/apache/shardingsphere/shadow/distsql/query/ShadowTableRuleQueryResultSetTest.java b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-handler/src/test/java/org/apache/shardingsphere/shadow/distsql/query/ShadowTableRuleQueryResultSetTest.java
new file mode 100644
index 0000000..0c50d81
--- /dev/null
+++ b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-handler/src/test/java/org/apache/shardingsphere/shadow/distsql/query/ShadowTableRuleQueryResultSetTest.java
@@ -0,0 +1,65 @@
+/*
+ * 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.shadow.distsql.query;
+
+import org.apache.shardingsphere.infra.config.RuleConfiguration;
+import org.apache.shardingsphere.infra.config.algorithm.ShardingSphereAlgorithmConfiguration;
+import org.apache.shardingsphere.infra.distsql.query.DistSQLResultSet;
+import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
+import org.apache.shardingsphere.shadow.api.config.ShadowRuleConfiguration;
+import org.apache.shardingsphere.shadow.api.config.table.ShadowTableConfiguration;
+import org.apache.shardingsphere.shadow.distsql.handler.query.ShadowTableRuleQueryResultSet;
+import org.apache.shardingsphere.shadow.distsql.parser.statement.ShowShadowAlgorithmsStatement;
+import org.junit.Test;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import java.util.Properties;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+public final class ShadowTableRuleQueryResultSetTest {
+
+ @Test
+ public void assertGetRowData() {
+ ShardingSphereMetaData metaData = mock(ShardingSphereMetaData.class, RETURNS_DEEP_STUBS);
+ when(metaData.getRuleMetaData().getConfigurations()).thenReturn(Collections.singleton(createRuleConfiguration()));
+ DistSQLResultSet resultSet = new ShadowTableRuleQueryResultSet();
+ resultSet.init(metaData, mock(ShowShadowAlgorithmsStatement.class));
+ List<Object> actual = new ArrayList<>(resultSet.getRowData());
+ assertThat(actual.size(), is(2));
+ assertThat(actual.get(0), is("t_order"));
+ assertThat(actual.get(1), is("shadowAlgorithmName_1,shadowAlgorithmName_2"));
+ }
+
+ private RuleConfiguration createRuleConfiguration() {
+ // FIXME because the defined final attribute will be removed, here is just for the new object
+ ShadowRuleConfiguration result = new ShadowRuleConfiguration("removed", Collections.singletonList("removed"), Collections.singletonList("removed"));
+ Properties properties = new Properties();
+ properties.setProperty("foo", "bar");
+ result.getTables().put("t_order", new ShadowTableConfiguration("", Arrays.asList("shadowAlgorithmName_1", "shadowAlgorithmName_2")));
+ result.getShadowAlgorithms().put("shadowAlgorithmName", new ShardingSphereAlgorithmConfiguration("simple_note", properties));
+ return result;
+ }
+}
diff --git a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-parser/src/main/antlr4/imports/shadow/RDLStatement.g4 b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-parser/src/main/antlr4/imports/shadow/RDLStatement.g4
index dfde54e..50fa190 100644
--- a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-parser/src/main/antlr4/imports/shadow/RDLStatement.g4
+++ b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-parser/src/main/antlr4/imports/shadow/RDLStatement.g4
@@ -32,7 +32,12 @@ dropShadowRule
;
alterShadowAlgorithm
- : ALTER SHADOW ALGORITHM shadowAlgorithmDefinition (COMMA shadowAlgorithmDefinition)*;
+ : ALTER SHADOW ALGORITHM shadowAlgorithmDefinition (COMMA shadowAlgorithmDefinition)*
+ ;
+
+dropShadowAlgorithm
+ : DROP SHADOW ALGORITHM algorithmName (COMMA algorithmName)*
+ ;
shadowRuleDefinition
: ruleName LP SOURCE EQ source COMMA SHADOW EQ shadow COMMA shadowTableRule (COMMA shadowTableRule)* RP
diff --git a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-parser/src/main/antlr4/imports/shadow/RQLStatement.g4 b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-parser/src/main/antlr4/imports/shadow/RQLStatement.g4
index 84c029d..1ae1e2d 100644
--- a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-parser/src/main/antlr4/imports/shadow/RQLStatement.g4
+++ b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-parser/src/main/antlr4/imports/shadow/RQLStatement.g4
@@ -19,8 +19,20 @@ grammar RQLStatement;
import Keyword, Literals, Symbol;
+showShadowRules
+ : SHOW SHADOW (shadowRule | RULES) (FROM schemaName)?
+ ;
+
showShadowTableRules
- : SHOW SHADOW (ruleName | RULES) (FROM schemaName)?
+ : SHOW SHADOW TABLE RULES (FROM schemaName)?
+ ;
+
+showShadowAlgorithms
+ : SHOW SHADOW ALGORITHMS (FROM schemaName)?
+ ;
+
+shadowRule
+ : RULE ruleName
;
ruleName
diff --git a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-parser/src/main/antlr4/org/apache/shardingsphere/distsql/parser/autogen/ShadowDistSQLStatement.g4 b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-parser/src/main/antlr4/org/apache/shardingsphere/distsql/parser/autogen/ShadowDistSQLStatement.g4
index 5fafe22..9a8ceb0 100644
--- a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-parser/src/main/antlr4/org/apache/shardingsphere/distsql/parser/autogen/ShadowDistSQLStatement.g4
+++ b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-parser/src/main/antlr4/org/apache/shardingsphere/distsql/parser/autogen/ShadowDistSQLStatement.g4
@@ -23,6 +23,10 @@ execute
: (createShadowRule
| alterShadowRule
| dropShadowRule
+ | showShadowRules
+ | showShadowTableRules
+ | showShadowAlgorithms
+ | dropShadowAlgorithm
| alterShadowAlgorithm
) SEMI?
;
diff --git a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-parser/src/main/java/org/apache/shardingsphere/shadow/distsql/parser/core/ShadowDistSQLStatementVisitor.java b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-parser/src/main/java/org/apache/shardingsphere/shadow/distsql/parser/core/ShadowDistSQLStatementVisitor.java
index b5dd87e..14ff0f8 100644
--- a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-parser/src/main/java/org/apache/shardingsphere/shadow/distsql/parser/core/ShadowDistSQLStatementVisitor.java
+++ b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-parser/src/main/java/org/apache/shardingsphere/shadow/distsql/parser/core/ShadowDistSQLStatementVisitor.java
@@ -23,23 +23,34 @@ import org.apache.shardingsphere.distsql.parser.autogen.ShadowDistSQLStatementPa
import org.apache.shardingsphere.distsql.parser.autogen.ShadowDistSQLStatementParser.AlterShadowAlgorithmContext;
import org.apache.shardingsphere.distsql.parser.autogen.ShadowDistSQLStatementParser.AlterShadowRuleContext;
import org.apache.shardingsphere.distsql.parser.autogen.ShadowDistSQLStatementParser.CreateShadowRuleContext;
+import org.apache.shardingsphere.distsql.parser.autogen.ShadowDistSQLStatementParser.DropShadowAlgorithmContext;
import org.apache.shardingsphere.distsql.parser.autogen.ShadowDistSQLStatementParser.DropShadowRuleContext;
+import org.apache.shardingsphere.distsql.parser.autogen.ShadowDistSQLStatementParser.SchemaNameContext;
import org.apache.shardingsphere.distsql.parser.autogen.ShadowDistSQLStatementParser.ShadowAlgorithmDefinitionContext;
import org.apache.shardingsphere.distsql.parser.autogen.ShadowDistSQLStatementParser.ShadowRuleDefinitionContext;
import org.apache.shardingsphere.distsql.parser.autogen.ShadowDistSQLStatementParser.ShadowTableRuleContext;
+import org.apache.shardingsphere.distsql.parser.autogen.ShadowDistSQLStatementParser.ShowShadowAlgorithmsContext;
+import org.apache.shardingsphere.distsql.parser.autogen.ShadowDistSQLStatementParser.ShowShadowRulesContext;
+import org.apache.shardingsphere.distsql.parser.autogen.ShadowDistSQLStatementParser.ShowShadowTableRulesContext;
import org.apache.shardingsphere.distsql.parser.segment.AlgorithmSegment;
import org.apache.shardingsphere.shadow.distsql.parser.segment.ShadowAlgorithmSegment;
import org.apache.shardingsphere.shadow.distsql.parser.segment.ShadowRuleSegment;
import org.apache.shardingsphere.shadow.distsql.parser.statement.AlterShadowAlgorithmStatement;
import org.apache.shardingsphere.shadow.distsql.parser.statement.AlterShadowRuleStatement;
import org.apache.shardingsphere.shadow.distsql.parser.statement.CreateShadowRuleStatement;
+import org.apache.shardingsphere.shadow.distsql.parser.statement.DropShadowAlgorithmStatement;
import org.apache.shardingsphere.shadow.distsql.parser.statement.DropShadowRuleStatement;
+import org.apache.shardingsphere.shadow.distsql.parser.statement.ShowShadowAlgorithmsStatement;
+import org.apache.shardingsphere.shadow.distsql.parser.statement.ShowShadowRulesStatement;
+import org.apache.shardingsphere.shadow.distsql.parser.statement.ShowShadowTableRulesStatement;
import org.apache.shardingsphere.sql.parser.api.visitor.ASTNode;
import org.apache.shardingsphere.sql.parser.api.visitor.SQLVisitor;
+import org.apache.shardingsphere.sql.parser.sql.common.segment.generic.SchemaSegment;
import org.apache.shardingsphere.sql.parser.sql.common.value.identifier.IdentifierValue;
import org.apache.shardingsphere.sql.parser.sql.common.value.literal.impl.StringLiteralValue;
import java.util.Collection;
+import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Properties;
@@ -49,6 +60,7 @@ import java.util.stream.Collectors;
* SQL statement visitor for shadow dist SQL.
*/
public final class ShadowDistSQLStatementVisitor extends ShadowDistSQLStatementBaseVisitor<ASTNode> implements SQLVisitor {
+
@Override
public ASTNode visitCreateShadowRule(final CreateShadowRuleContext ctx) {
List<ShadowRuleSegment> shadowRuleSegments = ctx.shadowRuleDefinition().stream().map(this::visit).map(each -> (ShadowRuleSegment) each).collect(Collectors.toList());
@@ -63,6 +75,11 @@ public final class ShadowDistSQLStatementVisitor extends ShadowDistSQLStatementB
}
@Override
+ public ASTNode visitShowShadowAlgorithms(final ShowShadowAlgorithmsContext ctx) {
+ return new ShowShadowAlgorithmsStatement(null != ctx.schemaName() ? (SchemaSegment) visit(ctx.schemaName()) : null);
+ }
+
+ @Override
public ASTNode visitShadowAlgorithmDefinition(final ShadowAlgorithmDefinitionContext ctx) {
AlgorithmSegment algorithmSegment = new AlgorithmSegment(getText(ctx.shadowAlgorithmType()), getAlgorithmProperties(ctx.algorithmProperties()));
String algorithmName = null != ctx.algorithmName() ? getText(ctx.algorithmName()) : createAlgorithmName(getText(((ShadowTableRuleContext) ctx.getParent()).tableName()), algorithmSegment);
@@ -91,6 +108,24 @@ public final class ShadowDistSQLStatementVisitor extends ShadowDistSQLStatementB
return new AlterShadowAlgorithmStatement(visitShadowAlgorithms(ctx.shadowAlgorithmDefinition()));
}
+ @Override
+ public ASTNode visitDropShadowAlgorithm(final DropShadowAlgorithmContext ctx) {
+ return new DropShadowAlgorithmStatement(null == ctx.algorithmName() ? Collections.emptyList()
+ : ctx.algorithmName().stream().map(ShadowDistSQLStatementVisitor::getText).collect(Collectors.toSet()));
+ }
+
+ @Override
+ public ASTNode visitShowShadowRules(final ShowShadowRulesContext ctx) {
+ String ruleName = null == ctx.shadowRule() ? null : getText(ctx.shadowRule().ruleName());
+ SchemaSegment schemaSegment = null == ctx.schemaName() ? null : (SchemaSegment) visit(ctx.schemaName());
+ return new ShowShadowRulesStatement(ruleName, null == ctx.schemaName() ? null : schemaSegment);
+ }
+
+ @Override
+ public ASTNode visitShowShadowTableRules(final ShowShadowTableRulesContext ctx) {
+ return new ShowShadowTableRulesStatement(null != ctx.schemaName() ? (SchemaSegment) visit(ctx.schemaName()) : null);
+ }
+
private static String getText(final ParserRuleContext ctx) {
return new IdentifierValue(ctx.getText()).getValue();
}
@@ -102,4 +137,9 @@ public final class ShadowDistSQLStatementVisitor extends ShadowDistSQLStatementB
private String createAlgorithmName(final String tableName, final AlgorithmSegment algorithmSegment) {
return (tableName + "_" + algorithmSegment.getName()).toLowerCase();
}
+
+ @Override
+ public ASTNode visitSchemaName(final SchemaNameContext ctx) {
+ return new SchemaSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(), new IdentifierValue(ctx.getText()));
+ }
}
diff --git a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-parser/src/main/antlr4/imports/shadow/RQLStatement.g4 b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-statement/src/main/java/org/apache/shardingsphere/shadow/distsql/parser/statement/DropShadowAlgorithmStatement.java
similarity index 63%
copy from shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-parser/src/main/antlr4/imports/shadow/RQLStatement.g4
copy to shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-statement/src/main/java/org/apache/shardingsphere/shadow/distsql/parser/statement/DropShadowAlgorithmStatement.java
index 84c029d..a95d139 100644
--- a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-parser/src/main/antlr4/imports/shadow/RQLStatement.g4
+++ b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-statement/src/main/java/org/apache/shardingsphere/shadow/distsql/parser/statement/DropShadowAlgorithmStatement.java
@@ -15,18 +15,20 @@
* limitations under the License.
*/
-grammar RQLStatement;
+package org.apache.shardingsphere.shadow.distsql.parser.statement;
-import Keyword, Literals, Symbol;
+import lombok.Getter;
+import lombok.RequiredArgsConstructor;
+import org.apache.shardingsphere.distsql.parser.statement.rdl.drop.DropRuleStatement;
-showShadowTableRules
- : SHOW SHADOW (ruleName | RULES) (FROM schemaName)?
- ;
+import java.util.Collection;
-ruleName
- : IDENTIFIER
- ;
-
-schemaName
- : IDENTIFIER
- ;
+/**
+ * Drop shadow algorithm statement.
+ */
+@RequiredArgsConstructor
+@Getter
+public final class DropShadowAlgorithmStatement extends DropRuleStatement {
+
+ private final Collection<String> algorithmNames;
+}
diff --git a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-parser/src/main/antlr4/imports/shadow/RQLStatement.g4 b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-statement/src/main/java/org/apache/shardingsphere/shadow/distsql/parser/statement/ShowShadowAlgorithmsStatement.java
similarity index 61%
copy from shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-parser/src/main/antlr4/imports/shadow/RQLStatement.g4
copy to shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-statement/src/main/java/org/apache/shardingsphere/shadow/distsql/parser/statement/ShowShadowAlgorithmsStatement.java
index 84c029d..f74bcc9 100644
--- a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-parser/src/main/antlr4/imports/shadow/RQLStatement.g4
+++ b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-statement/src/main/java/org/apache/shardingsphere/shadow/distsql/parser/statement/ShowShadowAlgorithmsStatement.java
@@ -15,18 +15,19 @@
* limitations under the License.
*/
-grammar RQLStatement;
+package org.apache.shardingsphere.shadow.distsql.parser.statement;
-import Keyword, Literals, Symbol;
+import lombok.Getter;
+import org.apache.shardingsphere.distsql.parser.statement.rql.show.ShowRulesStatement;
+import org.apache.shardingsphere.sql.parser.sql.common.segment.generic.SchemaSegment;
-showShadowTableRules
- : SHOW SHADOW (ruleName | RULES) (FROM schemaName)?
- ;
-
-ruleName
- : IDENTIFIER
- ;
-
-schemaName
- : IDENTIFIER
- ;
+/**
+ * Show shadow algorithms statement.
+ */
+@Getter
+public final class ShowShadowAlgorithmsStatement extends ShowRulesStatement {
+
+ public ShowShadowAlgorithmsStatement(final SchemaSegment schema) {
+ super(schema);
+ }
+}
diff --git a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-parser/src/main/antlr4/imports/shadow/RQLStatement.g4 b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-statement/src/main/java/org/apache/shardingsphere/shadow/distsql/parser/statement/ShowShadowRulesStatement.java
similarity index 57%
copy from shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-parser/src/main/antlr4/imports/shadow/RQLStatement.g4
copy to shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-statement/src/main/java/org/apache/shardingsphere/shadow/distsql/parser/statement/ShowShadowRulesStatement.java
index 84c029d..da6adbb 100644
--- a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-parser/src/main/antlr4/imports/shadow/RQLStatement.g4
+++ b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-statement/src/main/java/org/apache/shardingsphere/shadow/distsql/parser/statement/ShowShadowRulesStatement.java
@@ -15,18 +15,22 @@
* limitations under the License.
*/
-grammar RQLStatement;
+package org.apache.shardingsphere.shadow.distsql.parser.statement;
-import Keyword, Literals, Symbol;
+import lombok.Getter;
+import org.apache.shardingsphere.distsql.parser.statement.rql.show.ShowRulesStatement;
+import org.apache.shardingsphere.sql.parser.sql.common.segment.generic.SchemaSegment;
-showShadowTableRules
- : SHOW SHADOW (ruleName | RULES) (FROM schemaName)?
- ;
-
-ruleName
- : IDENTIFIER
- ;
-
-schemaName
- : IDENTIFIER
- ;
+/**
+ * Show shadow rules statement.
+ */
+@Getter
+public final class ShowShadowRulesStatement extends ShowRulesStatement {
+
+ private final String ruleName;
+
+ public ShowShadowRulesStatement(final String tableName, final SchemaSegment schema) {
+ super(schema);
+ this.ruleName = tableName;
+ }
+}
diff --git a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-parser/src/main/antlr4/imports/shadow/RQLStatement.g4 b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-statement/src/main/java/org/apache/shardingsphere/shadow/distsql/parser/statement/ShowShadowTableRulesStatement.java
similarity index 61%
copy from shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-parser/src/main/antlr4/imports/shadow/RQLStatement.g4
copy to shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-statement/src/main/java/org/apache/shardingsphere/shadow/distsql/parser/statement/ShowShadowTableRulesStatement.java
index 84c029d..cb80422 100644
--- a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-parser/src/main/antlr4/imports/shadow/RQLStatement.g4
+++ b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-statement/src/main/java/org/apache/shardingsphere/shadow/distsql/parser/statement/ShowShadowTableRulesStatement.java
@@ -15,18 +15,19 @@
* limitations under the License.
*/
-grammar RQLStatement;
+package org.apache.shardingsphere.shadow.distsql.parser.statement;
-import Keyword, Literals, Symbol;
+import lombok.Getter;
+import org.apache.shardingsphere.distsql.parser.statement.rql.show.ShowRulesStatement;
+import org.apache.shardingsphere.sql.parser.sql.common.segment.generic.SchemaSegment;
-showShadowTableRules
- : SHOW SHADOW (ruleName | RULES) (FROM schemaName)?
- ;
-
-ruleName
- : IDENTIFIER
- ;
-
-schemaName
- : IDENTIFIER
- ;
+/**
+ * Show shadow table rules statement.
+ */
+@Getter
+public final class ShowShadowTableRulesStatement extends ShowRulesStatement {
+
+ public ShowShadowTableRulesStatement(final SchemaSegment schema) {
+ super(schema);
+ }
+}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/DistSQLBackendHandlerFactoryTest.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/DistSQLBackendHandlerFactoryTest.java
index e71a55b..6926cf7 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/DistSQLBackendHandlerFactoryTest.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/DistSQLBackendHandlerFactoryTest.java
@@ -47,7 +47,11 @@ import org.apache.shardingsphere.shadow.api.config.ShadowRuleConfiguration;
import org.apache.shardingsphere.shadow.distsql.parser.statement.AlterShadowAlgorithmStatement;
import org.apache.shardingsphere.shadow.distsql.parser.statement.AlterShadowRuleStatement;
import org.apache.shardingsphere.shadow.distsql.parser.statement.CreateShadowRuleStatement;
+import org.apache.shardingsphere.shadow.distsql.parser.statement.DropShadowAlgorithmStatement;
import org.apache.shardingsphere.shadow.distsql.parser.statement.DropShadowRuleStatement;
+import org.apache.shardingsphere.shadow.distsql.parser.statement.ShowShadowAlgorithmsStatement;
+import org.apache.shardingsphere.shadow.distsql.parser.statement.ShowShadowRulesStatement;
+import org.apache.shardingsphere.shadow.distsql.parser.statement.ShowShadowTableRulesStatement;
import org.apache.shardingsphere.sharding.distsql.parser.statement.CreateShardingTableRuleStatement;
import org.junit.After;
import org.junit.Before;
@@ -204,6 +208,51 @@ public final class DistSQLBackendHandlerFactoryTest {
}
@Test
+ public void assertExecuteShowShadowRulesContext() throws SQLException {
+ BackendConnection connection = mock(BackendConnection.class);
+ when(connection.getSchemaName()).thenReturn("schema");
+ setContextManager(true);
+ mockShardingSphereRuleMetaData();
+ ResponseHeader response = RQLBackendHandlerFactory.newInstance(mock(ShowShadowRulesStatement.class), connection).execute();
+ assertThat(response, instanceOf(QueryResponseHeader.class));
+ }
+
+ @Test
+ public void assertExecuteShowShadowTableRulesContext() throws SQLException {
+ BackendConnection connection = mock(BackendConnection.class);
+ when(connection.getSchemaName()).thenReturn("schema");
+ setContextManager(true);
+ mockShardingSphereRuleMetaData();
+ ResponseHeader response = RQLBackendHandlerFactory.newInstance(mock(ShowShadowTableRulesStatement.class), connection).execute();
+ assertThat(response, instanceOf(QueryResponseHeader.class));
+ }
+
+ @Test
+ public void assertExecuteShowShadowAlgorithmsContext() throws SQLException {
+ BackendConnection connection = mock(BackendConnection.class);
+ when(connection.getSchemaName()).thenReturn("schema");
+ setContextManager(true);
+ mockShardingSphereRuleMetaData();
+ ResponseHeader response = RQLBackendHandlerFactory.newInstance(mock(ShowShadowAlgorithmsStatement.class), connection).execute();
+ assertThat(response, instanceOf(QueryResponseHeader.class));
+ }
+
+ @Test
+ public void assertExecuteDropShadowAlgorithmContext() throws SQLException {
+ BackendConnection connection = mock(BackendConnection.class);
+ when(connection.getSchemaName()).thenReturn("schema");
+ try {
+ RDLBackendHandlerFactory.newInstance(new MySQLDatabaseType(), mock(DropShadowAlgorithmStatement.class), connection);
+ } catch (final SQLException ex) {
+ assertThat(ex.getMessage(), is("No Registry center to execute `DropShadowAlgorithmStatement` SQL"));
+ }
+ setContextManager(true);
+ mockShardingSphereRuleMetaData();
+ ResponseHeader response = RDLBackendHandlerFactory.newInstance(new MySQLDatabaseType(), mock(DropShadowAlgorithmStatement.class), connection).execute();
+ assertThat(response, instanceOf(UpdateResponseHeader.class));
+ }
+
+ @Test
public void assertExecuteDropResourceContext() throws SQLException {
BackendConnection connection = mock(BackendConnection.class);
when(connection.getSchemaName()).thenReturn("schema");
diff --git a/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/statement/distsql/rdl/drop/impl/DropShadowAlgorithmStatementAssert.java b/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/statement/distsql/rdl/drop/impl/DropShadowAlgorithmStatementAssert.java
new file mode 100644
index 0000000..7df906b
--- /dev/null
+++ b/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/statement/distsql/rdl/drop/impl/DropShadowAlgorithmStatementAssert.java
@@ -0,0 +1,52 @@
+/*
+ * 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.rdl.drop.impl;
+
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
+import org.apache.shardingsphere.shadow.distsql.parser.statement.DropShadowAlgorithmStatement;
+import org.apache.shardingsphere.test.sql.parser.parameterized.asserts.SQLCaseAssertContext;
+import org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.distsql.rdl.drop.DropShadowAlgorithmStatementTestCase;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertThat;
+
+/**
+ * Drop shadow algorithm statement assert.
+ */
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public final class DropShadowAlgorithmStatementAssert {
+
+ /**
+ * Assert drop shadow algorithm statement is correct with expected parser result.
+ *
+ * @param assertContext assert context
+ * @param actual actual drop shadow algorithm statement
+ * @param expected expected drop shadow algorithm statement test case
+ */
+ public static void assertIs(final SQLCaseAssertContext assertContext, final DropShadowAlgorithmStatement actual, final DropShadowAlgorithmStatementTestCase expected) {
+ if (null == expected) {
+ assertNull(assertContext.getText("Actual statement should not exist."), actual);
+ } else {
+ assertNotNull(assertContext.getText("Actual statement should exist."), actual);
+ assertThat(assertContext.getText("Shadow rule assertion error: "), actual.getAlgorithmNames(), is(expected.getRuleName()));
+ }
+ }
+}
diff --git a/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/statement/distsql/rql/impl/ShowRulesStatementAssert.java b/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/statement/distsql/rql/impl/ShowRulesStatementAssert.java
index 60b5263..d668ee9 100644
--- a/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/statement/distsql/rql/impl/ShowRulesStatementAssert.java
+++ b/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/statement/distsql/rql/impl/ShowRulesStatementAssert.java
@@ -23,6 +23,8 @@ import org.apache.shardingsphere.dbdiscovery.distsql.parser.statement.ShowDataba
import org.apache.shardingsphere.distsql.parser.statement.rql.show.ShowRulesStatement;
import org.apache.shardingsphere.encrypt.distsql.parser.statement.ShowEncryptRulesStatement;
import org.apache.shardingsphere.readwritesplitting.distsql.parser.statement.ShowReadwriteSplittingRulesStatement;
+import org.apache.shardingsphere.shadow.distsql.parser.statement.ShowShadowAlgorithmsStatement;
+import org.apache.shardingsphere.shadow.distsql.parser.statement.ShowShadowRulesStatement;
import org.apache.shardingsphere.sharding.distsql.parser.statement.ShowShardingAlgorithmsStatement;
import org.apache.shardingsphere.sharding.distsql.parser.statement.ShowShardingBindingTableRulesStatement;
import org.apache.shardingsphere.sharding.distsql.parser.statement.ShowShardingBroadcastTableRulesStatement;
@@ -31,6 +33,8 @@ import org.apache.shardingsphere.test.sql.parser.parameterized.asserts.SQLCaseAs
import org.apache.shardingsphere.test.sql.parser.parameterized.asserts.statement.distsql.rql.impl.rule.ShowDatabaseDiscoveryRulesStatementAssert;
import org.apache.shardingsphere.test.sql.parser.parameterized.asserts.statement.distsql.rql.impl.rule.ShowEncryptRulesStatementAssert;
import org.apache.shardingsphere.test.sql.parser.parameterized.asserts.statement.distsql.rql.impl.rule.ShowReadwriteSplittingRulesStatementAssert;
+import org.apache.shardingsphere.test.sql.parser.parameterized.asserts.statement.distsql.rql.impl.rule.ShowShadowAlgorithmsStatementAssert;
+import org.apache.shardingsphere.test.sql.parser.parameterized.asserts.statement.distsql.rql.impl.rule.ShowShadowRulesStatementAssert;
import org.apache.shardingsphere.test.sql.parser.parameterized.asserts.statement.distsql.rql.impl.rule.ShowShardingAlgorithmsStatementAssert;
import org.apache.shardingsphere.test.sql.parser.parameterized.asserts.statement.distsql.rql.impl.rule.ShowShardingBindingTableRulesStatementAssert;
import org.apache.shardingsphere.test.sql.parser.parameterized.asserts.statement.distsql.rql.impl.rule.ShowShardingBroadcastTableRulesStatementAssert;
@@ -39,6 +43,8 @@ import org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain
import org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.distsql.rql.ShowDataBaseDiscoveryRulesStatementTestCase;
import org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.distsql.rql.ShowEncryptRulesStatementTestCase;
import org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.distsql.rql.ShowReadWriteSplittingRulesStatementTestCase;
+import org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.distsql.rql.ShowShadowAlgorithmsStatementTestCase;
+import org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.distsql.rql.ShowShadowRulesStatementTestCase;
import org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.distsql.rql.ShowShardingAlgorithmsStatementTestCase;
import org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.distsql.rql.ShowShardingBindingTableRulesStatementTestCase;
import org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.distsql.rql.ShowShardingBroadcastTableRulesStatementTestCase;
@@ -72,6 +78,10 @@ public final class ShowRulesStatementAssert {
ShowShardingAlgorithmsStatementAssert.assertIs(assertContext, (ShowShardingAlgorithmsStatement) actual, (ShowShardingAlgorithmsStatementTestCase) expected);
} else if (actual instanceof ShowShardingTableRulesStatement) {
ShowShardingTableRulesStatementAssert.assertIs(assertContext, (ShowShardingTableRulesStatement) actual, (ShowShardingTableRulesStatementTestCase) expected);
+ } else if (actual instanceof ShowShadowRulesStatement) {
+ ShowShadowRulesStatementAssert.assertIs(assertContext, (ShowShadowRulesStatement) actual, (ShowShadowRulesStatementTestCase) expected);
+ } else if (actual instanceof ShowShadowAlgorithmsStatement) {
+ ShowShadowAlgorithmsStatementAssert.assertIs(assertContext, (ShowShadowAlgorithmsStatement) actual, (ShowShadowAlgorithmsStatementTestCase) expected);
}
}
}
diff --git a/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/statement/distsql/rql/impl/rule/ShowShadowAlgorithmsStatementAssert.java b/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/statement/distsql/rql/impl/rule/ShowShadowAlgorithmsStatementAssert.java
new file mode 100644
index 0000000..7c6c126
--- /dev/null
+++ b/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/statement/distsql/rql/impl/rule/ShowShadowAlgorithmsStatementAssert.java
@@ -0,0 +1,51 @@
+/*
+ * 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.rql.impl.rule;
+
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
+import org.apache.shardingsphere.shadow.distsql.parser.statement.ShowShadowAlgorithmsStatement;
+import org.apache.shardingsphere.test.sql.parser.parameterized.asserts.SQLCaseAssertContext;
+import org.apache.shardingsphere.test.sql.parser.parameterized.asserts.segment.schema.SchemaAssert;
+import org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.distsql.rql.ShowShadowAlgorithmsStatementTestCase;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+/**
+ * Show shadow algorithms statement assert.
+ */
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public final class ShowShadowAlgorithmsStatementAssert {
+
+ /**
+ * Assert show shadow algorithms statement is correct with expected parser result.
+ *
+ * @param assertContext assert context
+ * @param actual actual show shadow algorithms statement
+ * @param expected expected show shadow algorithms statement test case
+ */
+ public static void assertIs(final SQLCaseAssertContext assertContext, final ShowShadowAlgorithmsStatement actual, final ShowShadowAlgorithmsStatementTestCase expected) {
+ if (null != expected.getSchema()) {
+ assertTrue(assertContext.getText("Actual schema should exist."), actual.getSchema().isPresent());
+ SchemaAssert.assertIs(assertContext, actual.getSchema().get(), expected.getSchema());
+ } else {
+ assertFalse(assertContext.getText("Actual schema should not exist."), actual.getSchema().isPresent());
+ }
+ }
+}
diff --git a/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/statement/distsql/rql/impl/rule/ShowShadowRulesStatementAssert.java b/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/statement/distsql/rql/impl/rule/ShowShadowRulesStatementAssert.java
new file mode 100644
index 0000000..0228d9e
--- /dev/null
+++ b/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/statement/distsql/rql/impl/rule/ShowShadowRulesStatementAssert.java
@@ -0,0 +1,51 @@
+/*
+ * 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.rql.impl.rule;
+
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
+import org.apache.shardingsphere.shadow.distsql.parser.statement.ShowShadowRulesStatement;
+import org.apache.shardingsphere.test.sql.parser.parameterized.asserts.SQLCaseAssertContext;
+import org.apache.shardingsphere.test.sql.parser.parameterized.asserts.segment.schema.SchemaAssert;
+import org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.distsql.rql.ShowShadowRulesStatementTestCase;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+/**
+ * Show shadow rules statement assert.
+ */
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public final class ShowShadowRulesStatementAssert {
+
+ /**
+ * Assert show shadow rule statement is correct with expected parser result.
+ *
+ * @param assertContext assert context
+ * @param actual actual show shadow rules statement
+ * @param expected expected show shadow rules statement test case
+ */
+ public static void assertIs(final SQLCaseAssertContext assertContext, final ShowShadowRulesStatement actual, final ShowShadowRulesStatementTestCase expected) {
+ if (null != expected.getSchema()) {
+ assertTrue(assertContext.getText("Actual schema should exist."), actual.getSchema().isPresent());
+ SchemaAssert.assertIs(assertContext, actual.getSchema().get(), expected.getSchema());
+ } else {
+ assertFalse(assertContext.getText("Actual schema should not exist."), actual.getSchema().isPresent());
+ }
+ }
+}
diff --git a/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/statement/distsql/rql/impl/rule/ShowShadowTableRulesStatementAssert.java b/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/statement/distsql/rql/impl/rule/ShowShadowTableRulesStatementAssert.java
new file mode 100644
index 0000000..2606643
--- /dev/null
+++ b/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/statement/distsql/rql/impl/rule/ShowShadowTableRulesStatementAssert.java
@@ -0,0 +1,51 @@
+/*
+ * 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.rql.impl.rule;
+
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
+import org.apache.shardingsphere.shadow.distsql.parser.statement.ShowShadowTableRulesStatement;
+import org.apache.shardingsphere.test.sql.parser.parameterized.asserts.SQLCaseAssertContext;
+import org.apache.shardingsphere.test.sql.parser.parameterized.asserts.segment.schema.SchemaAssert;
+import org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.distsql.rql.ShowShadowTableRulesStatementTestCase;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+/**
+ * Show shadow table rules statement assert.
+ */
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public final class ShowShadowTableRulesStatementAssert {
+
+ /**
+ * Assert show shadow table rules statement is correct with expected parser result.
+ *
+ * @param assertContext assert context
+ * @param actual actual show shadow table rules statement
+ * @param expected expected show shadow table rules statement test case
+ */
+ public static void assertIs(final SQLCaseAssertContext assertContext, final ShowShadowTableRulesStatement actual, final ShowShadowTableRulesStatementTestCase expected) {
+ if (null != expected.getSchema()) {
+ assertTrue(assertContext.getText("Actual schema should exist."), actual.getSchema().isPresent());
+ SchemaAssert.assertIs(assertContext, actual.getSchema().get(), expected.getSchema());
+ } else {
+ assertFalse(assertContext.getText("Actual schema should not exist."), actual.getSchema().isPresent());
+ }
+ }
+}
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 a51d640..191b3bd 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
@@ -120,6 +120,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.rdl.drop.DropEncryptRuleStatementTestCase;
import org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.distsql.rdl.drop.DropReadWriteSplittingRuleStatementTestCase;
import org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.distsql.rdl.drop.DropResourceStatementTestCase;
+import org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.distsql.rdl.drop.DropShadowAlgorithmStatementTestCase;
import org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.distsql.rdl.drop.DropShadowRuleStatementTestCase;
import org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.distsql.rdl.drop.DropShardingBindingTableRulesStatementTestCase;
import org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.distsql.rdl.drop.DropShardingBroadcastTableRulesStatementTestCase;
@@ -127,6 +128,9 @@ import org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain
import org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.distsql.rql.ShowDataBaseDiscoveryRulesStatementTestCase;
import org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.distsql.rql.ShowEncryptRulesStatementTestCase;
import org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.distsql.rql.ShowReadWriteSplittingRulesStatementTestCase;
+import org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.distsql.rql.ShowShadowAlgorithmsStatementTestCase;
+import org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.distsql.rql.ShowShadowRulesStatementTestCase;
+import org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.distsql.rql.ShowShadowTableRulesStatementTestCase;
import org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.distsql.rql.ShowShardingAlgorithmsStatementTestCase;
import org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.distsql.rql.ShowShardingBindingTableRulesStatementTestCase;
import org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.distsql.rql.ShowShardingBroadcastTableRulesStatementTestCase;
@@ -540,6 +544,18 @@ public final class SQLParserTestCases {
@XmlElement(name = "alter-shadow-algorithm")
private final List<AlterShadowAlgorithmStatementTestCase> alterShadowAlgorithm = new LinkedList<>();
+ @XmlElement(name = "show-shadow-rules")
+ private final List<ShowShadowRulesStatementTestCase> showShadowRulesStatement = new LinkedList<>();
+
+ @XmlElement(name = "show-shadow-algorithms")
+ private final List<ShowShadowAlgorithmsStatementTestCase> showShadowAlgorithmsStatement = new LinkedList<>();
+
+ @XmlElement(name = "show-shadow-table-rules")
+ private final List<ShowShadowTableRulesStatementTestCase> showShadowTableRulesStatement = new LinkedList<>();
+
+ @XmlElement(name = "drop-shadow-algorithm")
+ private final List<DropShadowAlgorithmStatementTestCase> dropShadowAlgorithmStatement = new LinkedList<>();
+
/**
* Get all SQL parser test cases.
*
@@ -673,6 +689,10 @@ public final class SQLParserTestCases {
putAll(dropShadowRule, result);
putAll(alterShadowRule, result);
putAll(alterShadowAlgorithm, result);
+ putAll(showShadowRulesStatement, result);
+ putAll(showShadowTableRulesStatement, result);
+ putAll(showShadowAlgorithmsStatement, result);
+ putAll(dropShadowAlgorithmStatement, result);
return result;
}
diff --git a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-parser/src/main/antlr4/imports/shadow/RQLStatement.g4 b/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/jaxb/cases/domain/statement/distsql/rdl/drop/DropShadowAlgorithmStatementTestCase.java
similarity index 57%
copy from shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-parser/src/main/antlr4/imports/shadow/RQLStatement.g4
copy to shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/jaxb/cases/domain/statement/distsql/rdl/drop/DropShadowAlgorithmStatementTestCase.java
index 84c029d..f718536 100644
--- a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-parser/src/main/antlr4/imports/shadow/RQLStatement.g4
+++ b/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/jaxb/cases/domain/statement/distsql/rdl/drop/DropShadowAlgorithmStatementTestCase.java
@@ -15,18 +15,21 @@
* limitations under the License.
*/
-grammar RQLStatement;
+package org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.distsql.rdl.drop;
-import Keyword, Literals, Symbol;
+import lombok.Getter;
+import org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.SQLParserTestCase;
-showShadowTableRules
- : SHOW SHADOW (ruleName | RULES) (FROM schemaName)?
- ;
+import javax.xml.bind.annotation.XmlElement;
+import java.util.LinkedList;
+import java.util.List;
-ruleName
- : IDENTIFIER
- ;
-
-schemaName
- : IDENTIFIER
- ;
+/**
+ * Drop shadow algorithm statement test case.
+ */
+@Getter
+public final class DropShadowAlgorithmStatementTestCase extends SQLParserTestCase {
+
+ @XmlElement(name = "rule")
+ private final List<String> ruleName = new LinkedList<>();
+}
diff --git a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-parser/src/main/antlr4/imports/shadow/RQLStatement.g4 b/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/jaxb/cases/domain/statement/distsql/rql/ShowShadowAlgorithmsStatementTestCase.java
similarity index 55%
copy from shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-parser/src/main/antlr4/imports/shadow/RQLStatement.g4
copy to shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/jaxb/cases/domain/statement/distsql/rql/ShowShadowAlgorithmsStatementTestCase.java
index 84c029d..2b459e0 100644
--- a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-parser/src/main/antlr4/imports/shadow/RQLStatement.g4
+++ b/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/jaxb/cases/domain/statement/distsql/rql/ShowShadowAlgorithmsStatementTestCase.java
@@ -15,18 +15,22 @@
* limitations under the License.
*/
-grammar RQLStatement;
+package org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.distsql.rql;
-import Keyword, Literals, Symbol;
+import lombok.Getter;
+import lombok.Setter;
+import org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.segment.impl.schema.ExpectedSchema;
+import org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.SQLParserTestCase;
-showShadowTableRules
- : SHOW SHADOW (ruleName | RULES) (FROM schemaName)?
- ;
+import javax.xml.bind.annotation.XmlElement;
-ruleName
- : IDENTIFIER
- ;
-
-schemaName
- : IDENTIFIER
- ;
+/**
+ * Show shadow algorithms statement test case.
+ */
+@Getter
+@Setter
+public final class ShowShadowAlgorithmsStatementTestCase extends SQLParserTestCase {
+
+ @XmlElement
+ private ExpectedSchema schema;
+}
diff --git a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-parser/src/main/antlr4/imports/shadow/RQLStatement.g4 b/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/jaxb/cases/domain/statement/distsql/rql/ShowShadowRulesStatementTestCase.java
similarity index 52%
copy from shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-parser/src/main/antlr4/imports/shadow/RQLStatement.g4
copy to shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/jaxb/cases/domain/statement/distsql/rql/ShowShadowRulesStatementTestCase.java
index 84c029d..fe20c7c 100644
--- a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-parser/src/main/antlr4/imports/shadow/RQLStatement.g4
+++ b/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/jaxb/cases/domain/statement/distsql/rql/ShowShadowRulesStatementTestCase.java
@@ -15,18 +15,26 @@
* limitations under the License.
*/
-grammar RQLStatement;
+package org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.distsql.rql;
-import Keyword, Literals, Symbol;
+import lombok.Getter;
+import lombok.Setter;
+import org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.segment.impl.schema.ExpectedSchema;
+import org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.SQLParserTestCase;
-showShadowTableRules
- : SHOW SHADOW (ruleName | RULES) (FROM schemaName)?
- ;
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlElement;
-ruleName
- : IDENTIFIER
- ;
-
-schemaName
- : IDENTIFIER
- ;
+/**
+ * Show shadow rules statement test case.
+ */
+@Getter
+@Setter
+public final class ShowShadowRulesStatementTestCase extends SQLParserTestCase {
+
+ @XmlAttribute
+ private String ruleName;
+
+ @XmlElement
+ private ExpectedSchema schema;
+}
diff --git a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-parser/src/main/antlr4/imports/shadow/RQLStatement.g4 b/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/jaxb/cases/domain/statement/distsql/rql/ShowShadowTableRulesStatementTestCase.java
similarity index 55%
copy from shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-parser/src/main/antlr4/imports/shadow/RQLStatement.g4
copy to shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/jaxb/cases/domain/statement/distsql/rql/ShowShadowTableRulesStatementTestCase.java
index 84c029d..be34575 100644
--- a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-parser/src/main/antlr4/imports/shadow/RQLStatement.g4
+++ b/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/jaxb/cases/domain/statement/distsql/rql/ShowShadowTableRulesStatementTestCase.java
@@ -15,18 +15,22 @@
* limitations under the License.
*/
-grammar RQLStatement;
+package org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.distsql.rql;
-import Keyword, Literals, Symbol;
+import lombok.Getter;
+import lombok.Setter;
+import org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.segment.impl.schema.ExpectedSchema;
+import org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.SQLParserTestCase;
-showShadowTableRules
- : SHOW SHADOW (ruleName | RULES) (FROM schemaName)?
- ;
+import javax.xml.bind.annotation.XmlElement;
-ruleName
- : IDENTIFIER
- ;
-
-schemaName
- : IDENTIFIER
- ;
+/**
+ * Show shadow table rules statement test case.
+ */
+@Getter
+@Setter
+public final class ShowShadowTableRulesStatementTestCase extends SQLParserTestCase {
+
+ @XmlElement
+ private ExpectedSchema schema;
+}
diff --git a/shardingsphere-test/shardingsphere-parser-test/src/main/resources/case/rdl/drop.xml b/shardingsphere-test/shardingsphere-parser-test/src/main/resources/case/rdl/drop.xml
index 9dcb94b..ed0c03c 100644
--- a/shardingsphere-test/shardingsphere-parser-test/src/main/resources/case/rdl/drop.xml
+++ b/shardingsphere-test/shardingsphere-parser-test/src/main/resources/case/rdl/drop.xml
@@ -47,4 +47,9 @@
<rule>shadow_rule_1</rule>
<rule>shadow_rule_2</rule>
</drop-shadow-rule>
+
+ <drop-shadow-algorithm sql-case-id="drop-shadow-algorithm">
+ <rule>shadow_algorithm_1</rule>
+ <rule>shadow_algorithm_2</rule>
+ </drop-shadow-algorithm>
</sql-parser-test-cases>
diff --git a/shardingsphere-test/shardingsphere-parser-test/src/main/resources/case/rql/show.xml b/shardingsphere-test/shardingsphere-parser-test/src/main/resources/case/rql/show.xml
index c789677..3617759 100644
--- a/shardingsphere-test/shardingsphere-parser-test/src/main/resources/case/rql/show.xml
+++ b/shardingsphere-test/shardingsphere-parser-test/src/main/resources/case/rql/show.xml
@@ -57,4 +57,16 @@
<show-encrypt-rules sql-case-id="show-encrypt-table-rules">
<schema name="encrypt_db" start-index="39" stop-index="48"/>
</show-encrypt-rules>
+
+ <show-shadow-rules sql-case-id="show-shadow-rules">
+ <schema name="shadow_db" start-index="34" stop-index="42"/>
+ </show-shadow-rules>
+
+ <show-shadow-table-rules sql-case-id="show-shadow-table-rules">
+ <schema name="shadow_db" start-index="28" stop-index="36"/>
+ </show-shadow-table-rules>
+
+ <show-shadow-algorithms sql-case-id="show-shadow-algorithms">
+ <schema name="shadow_db" start-index="28" stop-index="36"/>
+ </show-shadow-algorithms>
</sql-parser-test-cases>
diff --git a/shardingsphere-test/shardingsphere-parser-test/src/main/resources/sql/supported/rdl/drop.xml b/shardingsphere-test/shardingsphere-parser-test/src/main/resources/sql/supported/rdl/drop.xml
index c95b87d..fcf730e 100644
--- a/shardingsphere-test/shardingsphere-parser-test/src/main/resources/sql/supported/rdl/drop.xml
+++ b/shardingsphere-test/shardingsphere-parser-test/src/main/resources/sql/supported/rdl/drop.xml
@@ -25,4 +25,5 @@
<distsql-case id="drop-database-discovery-rule" value="DROP DB_DISCOVERY RULE ha_group_0,ha_group_1" />
<distsql-case id="drop-encrypt-rule" value="DROP ENCRYPT RULE t_encrypt,t_encrypt_order" />
<distsql-case id="drop-shadow-rule" value="DROP SHADOW RULE shadow_rule_1,shadow_rule_2" />
+ <distsql-case id="drop-shadow-algorithm" value="DROP SHADOW algorithm shadow_algorithm_1,shadow_algorithm_2" />
</sql-cases>
diff --git a/shardingsphere-test/shardingsphere-parser-test/src/main/resources/sql/supported/rql/show.xml b/shardingsphere-test/shardingsphere-parser-test/src/main/resources/sql/supported/rql/show.xml
index 922648e..c37f8a8 100644
--- a/shardingsphere-test/shardingsphere-parser-test/src/main/resources/sql/supported/rql/show.xml
+++ b/shardingsphere-test/shardingsphere-parser-test/src/main/resources/sql/supported/rql/show.xml
@@ -27,4 +27,7 @@
<distsql-case id="show-db-discovery-rules" value="SHOW DB_DISCOVERY RULES FROM db_discovery_db" />
<distsql-case id="show-encrypt-rules" value="SHOW ENCRYPT RULES FROM encrypt_db" />
<distsql-case id="show-encrypt-table-rules" value="SHOW ENCRYPT TABLE RULE t_encrypt FROM encrypt_db" />
+ <distsql-case id="show-shadow-rules" value="SHOW SHADOW RULE shadow_rule FROM shadow_db" />
+ <distsql-case id="show-shadow-table-rules" value="SHOW SHADOW TABLE RULES FROM shadow_db" />
+ <distsql-case id="show-shadow-algorithms" value="SHOW SHADOW ALGORITHMS FROM shadow_db" />
</sql-cases>