You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by la...@apache.org on 2022/02/08 02:13:15 UTC
[shardingsphere] branch master updated: Add `SHOW RULES USED RESOURCE` syntax to DistSQL. (#15251)
This is an automated email from the ASF dual-hosted git repository.
lanchengxiang 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 638e72a Add `SHOW RULES USED RESOURCE` syntax to DistSQL. (#15251)
638e72a is described below
commit 638e72a2ec5bcdf70c0bd5bf3a8cc546bb4c6c63
Author: yx9o <ya...@163.com>
AuthorDate: Tue Feb 8 10:12:13 2022 +0800
Add `SHOW RULES USED RESOURCE` syntax to DistSQL. (#15251)
* Add syntax SHOW RULES USED RESOURCE.
* Update.
* Update.
---
.../src/main/antlr4/imports/Keyword.g4 | 4 +
.../src/main/antlr4/imports/RQLStatement.g4 | 10 +-
.../parser/autogen/CommonDistSQLStatement.g4 | 1 +
.../core/common/CommonDistSQLStatementVisitor.java | 9 +
.../rql/show/ShowRulesUsedResourceStatement.java | 31 ++--
.../antlr4/imports/db-discovery/RDLStatement.g4 | 10 +-
.../antlr4/imports/db-discovery/RQLStatement.g4 | 6 +-
.../antlr4/imports/readwrite-splitting/Keyword.g4 | 4 +-
.../src/main/antlr4/imports/shadow/RDLStatement.g4 | 2 +-
.../rql/rule/RulesUsedResourceQueryResultSet.java | 187 +++++++++++++++++++++
...dingsphere.infra.distsql.query.DistSQLResultSet | 1 +
.../rql/RulesUsedResourceQueryResultSetTest.java | 183 ++++++++++++++++++++
.../distsql/rql/impl/ShowRulesStatementAssert.java | 5 +
.../rule/ShowRulesUsedResourceStatementAssert.java | 57 +++++++
.../jaxb/cases/domain/SQLParserTestCases.java | 9 +-
.../ShowRulesUsedResourceStatementTestCase.java | 34 ++--
.../src/main/resources/case/rql/show.xml | 4 +
.../src/main/resources/sql/supported/rql/show.xml | 1 +
18 files changed, 514 insertions(+), 44 deletions(-)
diff --git a/shardingsphere-distsql/shardingsphere-distsql-parser/src/main/antlr4/imports/Keyword.g4 b/shardingsphere-distsql/shardingsphere-distsql-parser/src/main/antlr4/imports/Keyword.g4
index 3b57845..c11100c 100644
--- a/shardingsphere-distsql/shardingsphere-distsql-parser/src/main/antlr4/imports/Keyword.g4
+++ b/shardingsphere-distsql/shardingsphere-distsql-parser/src/main/antlr4/imports/Keyword.g4
@@ -266,3 +266,7 @@ CONFIG
FILE
: F I L E
;
+
+USED
+ : U S E D
+ ;
diff --git a/shardingsphere-distsql/shardingsphere-distsql-parser/src/main/antlr4/imports/RQLStatement.g4 b/shardingsphere-distsql/shardingsphere-distsql-parser/src/main/antlr4/imports/RQLStatement.g4
index bbd16e6..964e0db 100644
--- a/shardingsphere-distsql/shardingsphere-distsql-parser/src/main/antlr4/imports/RQLStatement.g4
+++ b/shardingsphere-distsql/shardingsphere-distsql-parser/src/main/antlr4/imports/RQLStatement.g4
@@ -28,13 +28,21 @@ showSingleTableRules
;
showSingleTable
- : SHOW SINGLE (table | TABLES) (FROM schemaName)?
+ : SHOW SINGLE (table | TABLES) (FROM schemaName)?
;
countSchemaRules
: COUNT SCHEMA RULES (FROM schemaName)?
;
+showRulesUsedResource
+ : SHOW RULES USED RESOURCE resourceName (FROM schemaName)?
+ ;
+
+resourceName
+ : IDENTIFIER | STRING
+ ;
+
schemaName
: IDENTIFIER
;
diff --git a/shardingsphere-distsql/shardingsphere-distsql-parser/src/main/antlr4/org/apache/shardingsphere/distsql/parser/autogen/CommonDistSQLStatement.g4 b/shardingsphere-distsql/shardingsphere-distsql-parser/src/main/antlr4/org/apache/shardingsphere/distsql/parser/autogen/CommonDistSQLStatement.g4
index 6100550..e059ef7 100644
--- a/shardingsphere-distsql/shardingsphere-distsql-parser/src/main/antlr4/org/apache/shardingsphere/distsql/parser/autogen/CommonDistSQLStatement.g4
+++ b/shardingsphere-distsql/shardingsphere-distsql-parser/src/main/antlr4/org/apache/shardingsphere/distsql/parser/autogen/CommonDistSQLStatement.g4
@@ -50,5 +50,6 @@ execute
| createTrafficRule
| alterTrafficRule
| exportSchemaConfiguration
+ | showRulesUsedResource
) SEMI?
;
diff --git a/shardingsphere-distsql/shardingsphere-distsql-parser/src/main/java/org/apache/shardingsphere/distsql/parser/core/common/CommonDistSQLStatementVisitor.java b/shardingsphere-distsql/shardingsphere-distsql-parser/src/main/java/org/apache/shardingsphere/distsql/parser/core/common/CommonDistSQLStatementVisitor.java
index 7ee4d87..99b4e5d 100644
--- a/shardingsphere-distsql/shardingsphere-distsql-parser/src/main/java/org/apache/shardingsphere/distsql/parser/core/common/CommonDistSQLStatementVisitor.java
+++ b/shardingsphere-distsql/shardingsphere-distsql-parser/src/main/java/org/apache/shardingsphere/distsql/parser/core/common/CommonDistSQLStatementVisitor.java
@@ -55,6 +55,7 @@ import org.apache.shardingsphere.distsql.parser.autogen.CommonDistSQLStatementPa
import org.apache.shardingsphere.distsql.parser.autogen.CommonDistSQLStatementParser.ShowInstanceContext;
import org.apache.shardingsphere.distsql.parser.autogen.CommonDistSQLStatementParser.ShowInstanceModeContext;
import org.apache.shardingsphere.distsql.parser.autogen.CommonDistSQLStatementParser.ShowResourcesContext;
+import org.apache.shardingsphere.distsql.parser.autogen.CommonDistSQLStatementParser.ShowRulesUsedResourceContext;
import org.apache.shardingsphere.distsql.parser.autogen.CommonDistSQLStatementParser.ShowSQLParserRuleContext;
import org.apache.shardingsphere.distsql.parser.autogen.CommonDistSQLStatementParser.ShowSingleTableContext;
import org.apache.shardingsphere.distsql.parser.autogen.CommonDistSQLStatementParser.ShowSingleTableRulesContext;
@@ -97,6 +98,7 @@ import org.apache.shardingsphere.distsql.parser.statement.rdl.drop.DropDefaultSi
import org.apache.shardingsphere.distsql.parser.statement.rdl.drop.DropResourceStatement;
import org.apache.shardingsphere.distsql.parser.statement.rql.show.CountSchemaRulesStatement;
import org.apache.shardingsphere.distsql.parser.statement.rql.show.ShowResourcesStatement;
+import org.apache.shardingsphere.distsql.parser.statement.rql.show.ShowRulesUsedResourceStatement;
import org.apache.shardingsphere.distsql.parser.statement.rql.show.ShowSingleTableRulesStatement;
import org.apache.shardingsphere.distsql.parser.statement.rql.show.ShowSingleTableStatement;
import org.apache.shardingsphere.sql.parser.api.visitor.ASTNode;
@@ -399,4 +401,11 @@ public final class CommonDistSQLStatementVisitor extends CommonDistSQLStatementB
public ASTNode visitExportSchemaConfiguration(final ExportSchemaConfigurationContext ctx) {
return new ExportSchemaConfigurationStatement(Objects.nonNull(ctx.schemaName()) ? (SchemaSegment) visit(ctx.schemaName()) : null, Optional.ofNullable(getIdentifierValue(ctx.filePath())));
}
+
+ @Override
+ public ASTNode visitShowRulesUsedResource(final ShowRulesUsedResourceContext ctx) {
+ return new ShowRulesUsedResourceStatement(
+ null == ctx.resourceName() ? Optional.empty() : Optional.of(getIdentifierValue(ctx.resourceName())),
+ null == ctx.schemaName() ? null : (SchemaSegment) visit(ctx.schemaName()));
+ }
}
diff --git a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-parser/src/main/antlr4/imports/db-discovery/RQLStatement.g4 b/shardingsphere-distsql/shardingsphere-distsql-statement/src/main/java/org/apache/shardingsphere/distsql/parser/statement/rql/show/ShowRulesUsedResourceStatement.java
similarity index 58%
copy from shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-parser/src/main/antlr4/imports/db-discovery/RQLStatement.g4
copy to shardingsphere-distsql/shardingsphere-distsql-statement/src/main/java/org/apache/shardingsphere/distsql/parser/statement/rql/show/ShowRulesUsedResourceStatement.java
index 1cc717c..f614b46 100644
--- a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-parser/src/main/antlr4/imports/db-discovery/RQLStatement.g4
+++ b/shardingsphere-distsql/shardingsphere-distsql-statement/src/main/java/org/apache/shardingsphere/distsql/parser/statement/rql/show/ShowRulesUsedResourceStatement.java
@@ -15,22 +15,23 @@
* limitations under the License.
*/
-grammar RQLStatement;
+package org.apache.shardingsphere.distsql.parser.statement.rql.show;
-import Keyword, Literals, Symbol;
+import lombok.Getter;
+import org.apache.shardingsphere.sql.parser.sql.common.segment.generic.SchemaSegment;
-showDatabaseDiscoveryRules
- : SHOW DB_DISCOVERY RULES (FROM schemaName)?
- ;
-
-showDatabaseDiscoveryTypes
- : SHOW DB_DISCOVERY TYPES (FROM schemaName)?
- ;
+import java.util.Optional;
+
+/**
+ * Show rules used resource statement.
+ */
+@Getter
+public final class ShowRulesUsedResourceStatement extends ShowRulesStatement {
-showDatabaseDiscoveryHeartbeats
- : SHOW DB_DISCOVERY HEARTBEATS (FROM schemaName)?
- ;
+ private final Optional<String> resourceName;
-schemaName
- : IDENTIFIER
- ;
+ public ShowRulesUsedResourceStatement(final Optional<String> resourceName, final SchemaSegment schema) {
+ super(schema);
+ this.resourceName = resourceName;
+ }
+}
diff --git a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-parser/src/main/antlr4/imports/db-discovery/RDLStatement.g4 b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-parser/src/main/antlr4/imports/db-discovery/RDLStatement.g4
index 48c8ec4..60636c6 100644
--- a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-parser/src/main/antlr4/imports/db-discovery/RDLStatement.g4
+++ b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-parser/src/main/antlr4/imports/db-discovery/RDLStatement.g4
@@ -20,11 +20,11 @@ grammar RDLStatement;
import Keyword, Literals, Symbol;
createDatabaseDiscoveryRule
- : CREATE DB_DISCOVERY RULE databaseDiscoveryRule (COMMA databaseDiscoveryRule)*
+ : CREATE DB_DISCOVERY RULE databaseDiscoveryRule (COMMA databaseDiscoveryRule)*
;
alterDatabaseDiscoveryRule
- : ALTER DB_DISCOVERY RULE databaseDiscoveryRule (COMMA databaseDiscoveryRule)*
+ : ALTER DB_DISCOVERY RULE databaseDiscoveryRule (COMMA databaseDiscoveryRule)*
;
dropDatabaseDiscoveryRule
@@ -38,7 +38,7 @@ createDatabaseDiscoveryType
createDatabaseDiscoveryHeartbeat
: CREATE DB_DISCOVERY HEARTBEAT heartbeatDefinition (COMMA heartbeatDefinition)*
;
-
+
alterDatabaseDiscoveryHeartbeat
: ALTER DB_DISCOVERY HEARTBEAT heartbeatDefinition (COMMA heartbeatDefinition)*
;
@@ -50,7 +50,7 @@ dropDatabaseDiscoveryType
dropDatabaseDiscoveryHeartbeat
: DROP DB_DISCOVERY HEARTBEAT discoveryHeartbeatName (COMMA discoveryHeartbeatName)*
;
-
+
alterDatabaseDiscoveryType
: ALTER DB_DISCOVERY TYPE databaseDiscoveryTypeDefinition (COMMA databaseDiscoveryTypeDefinition)*
;
@@ -106,7 +106,7 @@ property
discoveryTypeName
: IDENTIFIER
;
-
+
discoveryHeartbeatName
: IDENTIFIER
;
diff --git a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-parser/src/main/antlr4/imports/db-discovery/RQLStatement.g4 b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-parser/src/main/antlr4/imports/db-discovery/RQLStatement.g4
index 1cc717c..d9eff06 100644
--- a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-parser/src/main/antlr4/imports/db-discovery/RQLStatement.g4
+++ b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-parser/src/main/antlr4/imports/db-discovery/RQLStatement.g4
@@ -22,15 +22,15 @@ import Keyword, Literals, Symbol;
showDatabaseDiscoveryRules
: SHOW DB_DISCOVERY RULES (FROM schemaName)?
;
-
+
showDatabaseDiscoveryTypes
: SHOW DB_DISCOVERY TYPES (FROM schemaName)?
;
-
+
showDatabaseDiscoveryHeartbeats
: SHOW DB_DISCOVERY HEARTBEATS (FROM schemaName)?
;
-
+
schemaName
: IDENTIFIER
;
diff --git a/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-distsql/shardingsphere-readwrite-splitting-distsql-parser/src/main/antlr4/imports/readwrite-splitting/Keyword.g4 b/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-distsql/shardingsphere-readwrite-splitting-distsql-parser/src/main/antlr4/imports/readwrite-splitting/Keyword.g4
index b482c87..8a0ef00 100644
--- a/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-distsql/shardingsphere-readwrite-splitting-distsql-parser/src/main/antlr4/imports/readwrite-splitting/Keyword.g4
+++ b/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-distsql/shardingsphere-readwrite-splitting-distsql-parser/src/main/antlr4/imports/readwrite-splitting/Keyword.g4
@@ -106,11 +106,11 @@ CLEAR
ENABLE
: E N A B L E
;
-
+
DISABLE
: D I S A B L E
;
-
+
READ
: R E A D
;
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 19c4dd9..ed7e0ae 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
@@ -20,7 +20,7 @@ grammar RDLStatement;
import Keyword, Literals, Symbol;
createShadowRule
- : CREATE SHADOW RULE shadowRuleDefinition (COMMA shadowRuleDefinition)*
+ : CREATE SHADOW RULE shadowRuleDefinition (COMMA shadowRuleDefinition)*
;
alterShadowRule
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rql/rule/RulesUsedResourceQueryResultSet.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rql/rule/RulesUsedResourceQueryResultSet.java
new file mode 100644
index 0000000..aef0f66
--- /dev/null
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/rql/rule/RulesUsedResourceQueryResultSet.java
@@ -0,0 +1,187 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.proxy.backend.text.distsql.rql.rule;
+
+import org.apache.shardingsphere.dbdiscovery.api.config.DatabaseDiscoveryRuleConfiguration;
+import org.apache.shardingsphere.distsql.parser.statement.rql.show.ShowRulesUsedResourceStatement;
+import org.apache.shardingsphere.encrypt.api.config.EncryptRuleConfiguration;
+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.readwritesplitting.api.ReadwriteSplittingRuleConfiguration;
+import org.apache.shardingsphere.shadow.api.config.ShadowRuleConfiguration;
+import org.apache.shardingsphere.shadow.api.config.datasource.ShadowDataSourceConfiguration;
+import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration;
+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.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Result set for show rules used resource.
+ */
+public final class RulesUsedResourceQueryResultSet implements DistSQLResultSet {
+
+ private static final String TYPE = ShowRulesUsedResourceStatement.class.getName();
+
+ private static final String SHARDING = "sharding";
+
+ private static final String READWRITE_SPLITTING = "readwrite_splitting";
+
+ private static final String DB_DISCOVERY = "db_discovery";
+
+ private static final String ENCRYPT = "encrypt";
+
+ private static final String SHADOW = "shadow";
+
+ private static final Map<String, Class<? extends RuleConfiguration>> FEATURE_MAP = new HashMap<>(5, 1);
+
+ private Iterator<Collection<Object>> data;
+
+ static {
+ FEATURE_MAP.put(SHARDING, ShardingRuleConfiguration.class);
+ FEATURE_MAP.put(READWRITE_SPLITTING, ReadwriteSplittingRuleConfiguration.class);
+ FEATURE_MAP.put(DB_DISCOVERY, DatabaseDiscoveryRuleConfiguration.class);
+ FEATURE_MAP.put(ENCRYPT, EncryptRuleConfiguration.class);
+ FEATURE_MAP.put(SHADOW, ShadowRuleConfiguration.class);
+ }
+
+ @Override
+ public void init(final ShardingSphereMetaData metaData, final SQLStatement sqlStatement) {
+ List<Collection<Object>> result = new ArrayList<>();
+ ShowRulesUsedResourceStatement statement = (ShowRulesUsedResourceStatement) sqlStatement;
+ String resourceName = statement.getResourceName().get();
+ if (hasRulesConfig(metaData) && metaData.getResource().getDataSources().keySet().contains(resourceName)) {
+ getRulesConfig(metaData.getRuleMetaData().getConfigurations(), resourceName, result);
+ }
+ data = result.iterator();
+ }
+
+ private void getRulesConfig(final Collection<RuleConfiguration> ruleConfigurations, final String resourceName, final List<Collection<Object>> result) {
+ ruleConfigurations.stream().forEach(each -> {
+ getRulesConfigForSharding(each, result);
+ getRulesConfigForReadwriteSplitting(each, resourceName, result);
+ getRulesConfigForDBDiscovery(each, resourceName, result);
+ getRulesConfigForEncrypt(each, result);
+ getRulesConfigForShadow(each, resourceName, result);
+ });
+ }
+
+ private void getRulesConfigForSharding(final RuleConfiguration ruleConfig, final List<Collection<Object>> result) {
+ if (!matchFeature(ruleConfig, SHARDING)) {
+ return;
+ }
+ ShardingRuleConfiguration config = (ShardingRuleConfiguration) ruleConfig;
+ config.getAutoTables().forEach(each -> {
+ result.add(buildRow(SHARDING, each.getLogicTable()));
+ });
+ config.getTables().forEach(each -> {
+ result.add(buildRow(SHARDING, each.getLogicTable()));
+ });
+ }
+
+ private void getRulesConfigForReadwriteSplitting(final RuleConfiguration ruleConfig, final String resourceName, final List<Collection<Object>> result) {
+ if (!matchFeature(ruleConfig, READWRITE_SPLITTING)) {
+ return;
+ }
+ ReadwriteSplittingRuleConfiguration config = (ReadwriteSplittingRuleConfiguration) ruleConfig;
+ config.getDataSources().forEach(each -> {
+ if (each.getWriteDataSourceName().isPresent() && each.getWriteDataSourceName().get().equalsIgnoreCase(resourceName)) {
+ result.add(buildRow(READWRITE_SPLITTING, each.getName()));
+ }
+ if (each.getReadDataSourceNames().isPresent() && Arrays.asList(each.getReadDataSourceNames().get().split(",")).contains(resourceName)) {
+ result.add(buildRow(READWRITE_SPLITTING, each.getName()));
+ }
+ });
+ }
+
+ private void getRulesConfigForDBDiscovery(final RuleConfiguration ruleConfig, final String resourceName, final List<Collection<Object>> result) {
+ if (!matchFeature(ruleConfig, DB_DISCOVERY)) {
+ return;
+ }
+ DatabaseDiscoveryRuleConfiguration config = (DatabaseDiscoveryRuleConfiguration) ruleConfig;
+ config.getDataSources().forEach(each -> {
+ if (each.getDataSourceNames().contains(resourceName)) {
+ result.add(buildRow(DB_DISCOVERY, each.getGroupName()));
+ }
+ });
+ }
+
+ private void getRulesConfigForEncrypt(final RuleConfiguration ruleConfig, final List<Collection<Object>> result) {
+ if (!matchFeature(ruleConfig, ENCRYPT)) {
+ return;
+ }
+ EncryptRuleConfiguration config = (EncryptRuleConfiguration) ruleConfig;
+ config.getTables().forEach(each -> {
+ result.add(buildRow(ENCRYPT, each.getName()));
+ });
+ }
+
+ private void getRulesConfigForShadow(final RuleConfiguration ruleConfig, final String resourceName, final List<Collection<Object>> result) {
+ if (!matchFeature(ruleConfig, SHADOW)) {
+ return;
+ }
+ ShadowRuleConfiguration config = (ShadowRuleConfiguration) ruleConfig;
+ for (Map.Entry<String, ShadowDataSourceConfiguration> each : config.getDataSources().entrySet()) {
+ if (each.getValue().getShadowDataSourceName().equalsIgnoreCase(resourceName) || each.getValue().getSourceDataSourceName().equalsIgnoreCase(resourceName)) {
+ result.add(buildRow(SHADOW, each.getKey()));
+ }
+ }
+ }
+
+ private boolean matchFeature(final RuleConfiguration ruleConfig, final String feature) {
+ if (null != ruleConfig && ruleConfig.getClass().getName().equals(FEATURE_MAP.get(feature).getName())) {
+ return true;
+ }
+ return false;
+ }
+
+ private Collection<Object> buildRow(final String type, final String name) {
+ return Arrays.asList(type, name);
+ }
+
+ private boolean hasRulesConfig(final ShardingSphereMetaData metaData) {
+ Collection<RuleConfiguration> configurations = metaData.getRuleMetaData().getConfigurations();
+ return null != configurations && !configurations.isEmpty();
+ }
+
+ @Override
+ public Collection<String> getColumnNames() {
+ return Arrays.asList("type", "name");
+ }
+
+ @Override
+ public boolean next() {
+ return data.hasNext();
+ }
+
+ @Override
+ public Collection<Object> getRowData() {
+ return data.next();
+ }
+
+ @Override
+ public String getType() {
+ return TYPE;
+ }
+}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.distsql.query.DistSQLResultSet b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.distsql.query.DistSQLResultSet
index 0d6e2b2..b4f8c88 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.distsql.query.DistSQLResultSet
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.distsql.query.DistSQLResultSet
@@ -19,3 +19,4 @@ org.apache.shardingsphere.proxy.backend.text.distsql.rql.resource.DataSourceQuer
org.apache.shardingsphere.proxy.backend.text.distsql.rql.rule.SingleTableQueryResultSet
org.apache.shardingsphere.proxy.backend.text.distsql.rql.rule.SingleTableRulesQueryResultSet
org.apache.shardingsphere.proxy.backend.text.distsql.rql.rule.SchemaRulesQueryResultSet
+org.apache.shardingsphere.proxy.backend.text.distsql.rql.rule.RulesUsedResourceQueryResultSet
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rql/RulesUsedResourceQueryResultSetTest.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rql/RulesUsedResourceQueryResultSetTest.java
new file mode 100644
index 0000000..40c0945
--- /dev/null
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/distsql/rql/RulesUsedResourceQueryResultSetTest.java
@@ -0,0 +1,183 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.proxy.backend.text.distsql.rql;
+
+import com.zaxxer.hikari.HikariDataSource;
+import org.apache.shardingsphere.dbdiscovery.api.config.DatabaseDiscoveryRuleConfiguration;
+import org.apache.shardingsphere.dbdiscovery.api.config.rule.DatabaseDiscoveryDataSourceRuleConfiguration;
+import org.apache.shardingsphere.distsql.parser.statement.rql.show.ShowRulesUsedResourceStatement;
+import org.apache.shardingsphere.encrypt.api.config.EncryptRuleConfiguration;
+import org.apache.shardingsphere.encrypt.api.config.rule.EncryptTableRuleConfiguration;
+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.infra.metadata.resource.ShardingSphereResource;
+import org.apache.shardingsphere.infra.metadata.rule.ShardingSphereRuleMetaData;
+import org.apache.shardingsphere.proxy.backend.text.distsql.rql.rule.RulesUsedResourceQueryResultSet;
+import org.apache.shardingsphere.readwritesplitting.api.ReadwriteSplittingRuleConfiguration;
+import org.apache.shardingsphere.readwritesplitting.api.rule.ReadwriteSplittingDataSourceRuleConfiguration;
+import org.apache.shardingsphere.shadow.api.config.ShadowRuleConfiguration;
+import org.apache.shardingsphere.shadow.api.config.datasource.ShadowDataSourceConfiguration;
+import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration;
+import org.apache.shardingsphere.sharding.api.config.rule.ShardingAutoTableRuleConfiguration;
+import org.apache.shardingsphere.sharding.api.config.rule.ShardingTableRuleConfiguration;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.junit.MockitoJUnitRunner;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.Optional;
+import java.util.Properties;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+@RunWith(MockitoJUnitRunner.class)
+public final class RulesUsedResourceQueryResultSetTest {
+
+ @Mock
+ private ShardingSphereMetaData shardingSphereMetaData;
+
+ @Test
+ public void assertGetRowDataForSharding() {
+ init(mockShardingTableRule());
+ DistSQLResultSet resultSet = new RulesUsedResourceQueryResultSet();
+ ShowRulesUsedResourceStatement sqlStatement = mock(ShowRulesUsedResourceStatement.class);
+ when(sqlStatement.getResourceName()).thenReturn(Optional.of("ds_0"));
+ resultSet.init(shardingSphereMetaData, sqlStatement);
+ Collection<Object> actual = resultSet.getRowData();
+ assertThat(actual.size(), is(2));
+ Iterator<Object> rowData = actual.iterator();
+ assertThat(rowData.next(), is("sharding"));
+ assertThat(rowData.next(), is("sharding_auto_table"));
+ resultSet.next();
+ actual = resultSet.getRowData();
+ assertThat(actual.size(), is(2));
+ rowData = actual.iterator();
+ assertThat(rowData.next(), is("sharding"));
+ assertThat(rowData.next(), is("sharding_table"));
+ }
+
+ @Test
+ public void assertGetRowDataForReadwriteSplitting() {
+ init(mockReadwriteSplittingRule());
+ DistSQLResultSet resultSet = new RulesUsedResourceQueryResultSet();
+ ShowRulesUsedResourceStatement sqlStatement = mock(ShowRulesUsedResourceStatement.class);
+ when(sqlStatement.getResourceName()).thenReturn(Optional.of("ds_0"));
+ resultSet.init(shardingSphereMetaData, sqlStatement);
+ Collection<Object> actual = resultSet.getRowData();
+ assertThat(actual.size(), is(2));
+ Iterator<Object> rowData = actual.iterator();
+ assertThat(rowData.next(), is("readwrite_splitting"));
+ assertThat(rowData.next(), is("readwrite_splitting_source"));
+ }
+
+ @Test
+ public void assertGetRowDataForDBDiscovery() {
+ init(mockDBDiscoveryRule());
+ DistSQLResultSet resultSet = new RulesUsedResourceQueryResultSet();
+ ShowRulesUsedResourceStatement sqlStatement = mock(ShowRulesUsedResourceStatement.class);
+ when(sqlStatement.getResourceName()).thenReturn(Optional.of("ds_0"));
+ resultSet.init(shardingSphereMetaData, sqlStatement);
+ Collection<Object> actual = resultSet.getRowData();
+ assertThat(actual.size(), is(2));
+ Iterator<Object> rowData = actual.iterator();
+ rowData = actual.iterator();
+ assertThat(rowData.next(), is("db_discovery"));
+ assertThat(rowData.next(), is("db_discovery_group_name"));
+ }
+
+ @Test
+ public void assertGetRowDataForEncryptRule() {
+ init(mockEncryptRule());
+ DistSQLResultSet resultSet = new RulesUsedResourceQueryResultSet();
+ ShowRulesUsedResourceStatement sqlStatement = mock(ShowRulesUsedResourceStatement.class);
+ when(sqlStatement.getResourceName()).thenReturn(Optional.of("ds_0"));
+ resultSet.init(shardingSphereMetaData, sqlStatement);
+ Collection<Object> actual = resultSet.getRowData();
+ assertThat(actual.size(), is(2));
+ Iterator<Object> rowData = actual.iterator();
+ assertThat(rowData.next(), is("encrypt"));
+ assertThat(rowData.next(), is("encrypt_table"));
+ }
+
+ @Test
+ public void assertGetRowDataForShadowRule() {
+ init(mockShadowRule());
+ DistSQLResultSet resultSet = new RulesUsedResourceQueryResultSet();
+ ShowRulesUsedResourceStatement sqlStatement = mock(ShowRulesUsedResourceStatement.class);
+ when(sqlStatement.getResourceName()).thenReturn(Optional.of("ds_0"));
+ resultSet.init(shardingSphereMetaData, sqlStatement);
+ Collection<Object> actual = resultSet.getRowData();
+ assertThat(actual.size(), is(2));
+ Iterator<Object> rowData = actual.iterator();
+ assertThat(rowData.next(), is("shadow"));
+ assertThat(rowData.next(), is("shadow_source"));
+ }
+
+ private void init(final RuleConfiguration ruleConfiguration) {
+ ShardingSphereRuleMetaData ruleMetaData = mock(ShardingSphereRuleMetaData.class);
+ when(ruleMetaData.getConfigurations()).thenReturn(Collections.singletonList(ruleConfiguration));
+ when(shardingSphereMetaData.getRuleMetaData()).thenReturn(ruleMetaData);
+ when(shardingSphereMetaData.getResource()).thenReturn(createResource());
+ }
+
+ private ShardingSphereResource createResource() {
+ return new ShardingSphereResource(Collections.singletonMap("ds_0", new HikariDataSource()), null, null, null);
+ }
+
+ private RuleConfiguration mockShardingTableRule() {
+ ShardingRuleConfiguration result = mock(ShardingRuleConfiguration.class);
+ when(result.getTables()).thenReturn(Collections.singletonList(new ShardingTableRuleConfiguration("sharding_table")));
+ when(result.getAutoTables()).thenReturn(Collections.singletonList(new ShardingAutoTableRuleConfiguration("sharding_auto_table")));
+ return result;
+ }
+
+ private RuleConfiguration mockReadwriteSplittingRule() {
+ ReadwriteSplittingRuleConfiguration result = mock(ReadwriteSplittingRuleConfiguration.class);
+ Properties props = new Properties();
+ props.setProperty("write-data-source-name", "ds_0");
+ props.setProperty("read-data-source-names", "read_0,read_1");
+ when(result.getDataSources()).thenReturn(Collections.singletonList(new ReadwriteSplittingDataSourceRuleConfiguration("readwrite_splitting_source", "", props, "")));
+ return result;
+ }
+
+ private RuleConfiguration mockDBDiscoveryRule() {
+ DatabaseDiscoveryRuleConfiguration result = mock(DatabaseDiscoveryRuleConfiguration.class);
+ when(result.getDataSources()).thenReturn(Collections.singletonList(new DatabaseDiscoveryDataSourceRuleConfiguration("db_discovery_group_name", Arrays.asList("ds_0", "ds_1"), "", "")));
+ return result;
+ }
+
+ private RuleConfiguration mockEncryptRule() {
+ EncryptRuleConfiguration result = mock(EncryptRuleConfiguration.class);
+ when(result.getTables()).thenReturn(Collections.singletonList(new EncryptTableRuleConfiguration("encrypt_table", Collections.emptyList(), false)));
+ return result;
+ }
+
+ private RuleConfiguration mockShadowRule() {
+ ShadowRuleConfiguration result = mock(ShadowRuleConfiguration.class);
+ when(result.getDataSources()).thenReturn(Collections.singletonMap("shadow_source", new ShadowDataSourceConfiguration("ds_0", "shadow_ds")));
+ return result;
+ }
+}
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 e26d40f..83e3cae 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
@@ -24,6 +24,7 @@ import org.apache.shardingsphere.dbdiscovery.distsql.parser.statement.ShowDataba
import org.apache.shardingsphere.dbdiscovery.distsql.parser.statement.ShowDatabaseDiscoveryTypesStatement;
import org.apache.shardingsphere.distsql.parser.statement.rql.show.CountSchemaRulesStatement;
import org.apache.shardingsphere.distsql.parser.statement.rql.show.ShowRulesStatement;
+import org.apache.shardingsphere.distsql.parser.statement.rql.show.ShowRulesUsedResourceStatement;
import org.apache.shardingsphere.distsql.parser.statement.rql.show.ShowSingleTableRulesStatement;
import org.apache.shardingsphere.distsql.parser.statement.rql.show.ShowSingleTableStatement;
import org.apache.shardingsphere.encrypt.distsql.parser.statement.ShowEncryptRulesStatement;
@@ -46,6 +47,7 @@ import org.apache.shardingsphere.test.sql.parser.parameterized.asserts.statement
import org.apache.shardingsphere.test.sql.parser.parameterized.asserts.statement.distsql.rql.impl.rule.ShowDefaultShardingStrategyStatementAssert;
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.ShowRulesUsedResourceStatementAssert;
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;
@@ -65,6 +67,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.rql.ShowDefaultShardingStrategyStatementTestCase;
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.ShowRulesUsedResourceStatementTestCase;
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;
@@ -129,6 +132,8 @@ public final class ShowRulesStatementAssert {
ShowUnusedShardingKeyGeneratorsStatementAssert.assertIs(assertContext, (ShowUnusedShardingKeyGeneratorsStatement) actual, (ShowUnusedShardingKeyGeneratorsStatementTestCase) expected);
} else if (actual instanceof CountSchemaRulesStatement) {
CountSchemaRulesStatementAssert.assertIs(assertContext, (CountSchemaRulesStatement) actual, (CountSchemaRulesStatementTestCase) expected);
+ } else if (actual instanceof ShowRulesUsedResourceStatement) {
+ ShowRulesUsedResourceStatementAssert.assertIs(assertContext, (ShowRulesUsedResourceStatement) actual, (ShowRulesUsedResourceStatementTestCase) 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/ShowRulesUsedResourceStatementAssert.java b/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/statement/distsql/rql/impl/rule/ShowRulesUsedResourceStatementAssert.java
new file mode 100644
index 0000000..d71d81f
--- /dev/null
+++ b/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/statement/distsql/rql/impl/rule/ShowRulesUsedResourceStatementAssert.java
@@ -0,0 +1,57 @@
+/*
+ * 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 com.google.common.base.Strings;
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
+import org.apache.shardingsphere.distsql.parser.statement.rql.show.ShowRulesUsedResourceStatement;
+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.ShowRulesUsedResourceStatementTestCase;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+/**
+ * Show rules used resource statement assert.
+ */
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public final class ShowRulesUsedResourceStatementAssert {
+
+ /**
+ * Assert show rules used resource statement is correct with expected parser result.
+ *
+ * @param assertContext assert context
+ * @param actual actual show rules used resource statement
+ * @param expected expected show rules used resource statement test case
+ */
+ public static void assertIs(final SQLCaseAssertContext assertContext, final ShowRulesUsedResourceStatement actual, final ShowRulesUsedResourceStatementTestCase 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());
+ }
+ if (!Strings.isNullOrEmpty(expected.getResourceName())) {
+ assertTrue(assertContext.getText("Actual resource should exist."), actual.getResourceName().isPresent());
+ } else {
+ assertFalse(assertContext.getText("Actual resource should not exist."), actual.getResourceName().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 3a85953..5d612cc 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
@@ -250,6 +250,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.rql.ShowDefaultShardingStrategyStatementTestCase;
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.ShowRulesUsedResourceStatementTestCase;
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;
@@ -1082,7 +1083,10 @@ public final class SQLParserTestCases {
private final List<UnlockStatementTestCase> unlockStatementTestCases = new LinkedList<>();
@XmlElement(name = "export-schema-config")
- private final List<ExportSchemaConfigurationStatementTestCase> exportSchemaStatementTestCases = new LinkedList<>();
+ private final List<ExportSchemaConfigurationStatementTestCase> exportSchemaConfigurationStatementTestCases = new LinkedList<>();
+
+ @XmlElement(name = "show-rules-used-resource")
+ private final List<ShowRulesUsedResourceStatementTestCase> showRulesUsedResourceStatementTestCases = new LinkedList<>();
/**
* Get all SQL parser test cases.
@@ -1353,7 +1357,8 @@ public final class SQLParserTestCases {
putAll(dropExtensionStatementTestCase, result);
putAll(lockStatementTestCases, result);
putAll(unlockStatementTestCases, result);
- putAll(exportSchemaStatementTestCases, result);
+ putAll(exportSchemaConfigurationStatementTestCases, result);
+ putAll(showRulesUsedResourceStatementTestCases, result);
return result;
}
// CHECKSTYLE:ON
diff --git a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-parser/src/main/antlr4/imports/db-discovery/RQLStatement.g4 b/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/jaxb/cases/domain/statement/distsql/rql/ShowRulesUsedResourceStatementTestCase.java
similarity index 51%
copy from shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-parser/src/main/antlr4/imports/db-discovery/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/ShowRulesUsedResourceStatementTestCase.java
index 1cc717c..8a6a0a1 100644
--- a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-parser/src/main/antlr4/imports/db-discovery/RQLStatement.g4
+++ b/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/jaxb/cases/domain/statement/distsql/rql/ShowRulesUsedResourceStatementTestCase.java
@@ -15,22 +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;
-showDatabaseDiscoveryRules
- : SHOW DB_DISCOVERY RULES (FROM schemaName)?
- ;
-
-showDatabaseDiscoveryTypes
- : SHOW DB_DISCOVERY TYPES (FROM schemaName)?
- ;
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlElement;
+
+/**
+ * Show rules used resource statement test case.
+ */
+@Getter
+@Setter
+public final class ShowRulesUsedResourceStatementTestCase extends SQLParserTestCase {
-showDatabaseDiscoveryHeartbeats
- : SHOW DB_DISCOVERY HEARTBEATS (FROM schemaName)?
- ;
+ @XmlAttribute(name = "resource-name")
+ private String resourceName;
-schemaName
- : IDENTIFIER
- ;
+ @XmlElement
+ private ExpectedSchema schema;
+}
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 97c26ef..16a54f8 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
@@ -114,4 +114,8 @@
<count-schema-rules sql-case-id="count-schema-rules">
<schema name="schemaName" start-index="24" stop-index="33"/>
</count-schema-rules>
+
+ <show-rules-used-resource sql-case-id="show-rules-used-resource" resource-name="ds_0">
+ <schema name="schemaName" start-index="35" stop-index="44"/>
+ </show-rules-used-resource>
</sql-parser-test-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 db2ca45..fefad50 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
@@ -41,4 +41,5 @@
<distsql-case id="show-unused-sharding-algorithms" value="SHOW UNUSED SHARDING ALGORITHMS FROM schemaName" />
<distsql-case id="show-unused-sharding-key-generators" value="SHOW UNUSED SHARDING KEY GENERATORS FROM schemaName" />
<distsql-case id="count-schema-rules" value="COUNT SCHEMA RULES FROM schemaName" />
+ <distsql-case id="show-rules-used-resource" value="SHOW RULES USED RESOURCE ds_0 FROM schemaName" />
</sql-cases>