This is an automated email from the ASF dual-hosted git repository.

jianglongtao pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git


The following commit(s) were added to refs/heads/master by this push:
     new 82b5942  [DistSQL] Add `show readwrite_splitting read resources` 
statement. (#13047)
82b5942 is described below

commit 82b594238dfb3a2fb47459ec222e722a7c519b9c
Author: lanchengx <[email protected]>
AuthorDate: Thu Oct 14 10:50:44 2021 -0500

    [DistSQL] Add `show readwrite_splitting read resources` statement. (#13047)
    
    * Add doc.
    
    * Add `show readwrite_splitting read resources` statement.
    
    * Add `show readwrite_splitting read resources` statement test case.
    
    * Adjust reformat.
    
    * About comparison.
    
    * Adjust doc.
    
    * Adjust doc.
---
 .../content/features/dist-sql/syntax/ral/ral.cn.md |   4 +-
 .../content/features/dist-sql/syntax/ral/ral.en.md |   4 +-
 .../antlr4/imports/readwrite-splitting/Keyword.g4  |   4 +
 .../imports/readwrite-splitting/RALStatement.g4    |   4 +
 .../autogen/ReadwriteSplittingDistSQLStatement.g4  |   1 +
 .../ReadwriteSplittingDistSQLStatementVisitor.java |   7 ++
 ...wReadwriteSplittingReadResourcesStatement.java} |  51 ++++-----
 .../common/show/ShowStatementExecutorFactory.java  |   5 +
 ...howReadwriteSplittingReadResourcesExecutor.java | 114 +++++++++++++++++++++
 .../ral/impl/CommonDistSQLStatementAssert.java     |   6 ++
 ...writeSplittingReadResourcesStatementAssert.java |  47 +++++++++
 .../jaxb/cases/domain/SQLParserTestCases.java      |   7 ++
 ...iteSplittingReadResourcesStatementTestCase.java |  21 ++--
 .../src/main/resources/case/ral/show.xml           |   1 +
 .../src/main/resources/sql/supported/ral/show.xml  |   1 +
 15 files changed, 229 insertions(+), 48 deletions(-)

diff --git a/docs/document/content/features/dist-sql/syntax/ral/ral.cn.md 
b/docs/document/content/features/dist-sql/syntax/ral/ral.cn.md
index 506cabb..4960669 100644
--- a/docs/document/content/features/dist-sql/syntax/ral/ral.cn.md
+++ b/docs/document/content/features/dist-sql/syntax/ral/ral.cn.md
@@ -43,6 +43,9 @@ RAL (Resource & Rule Administration Language) 为 Apache 
ShardingSphere 的管
 
|:------------------------------------------------------------------|:------------------------------------|:----------------------------------------------|
 |[enable / disable] readwrite_splitting read xxx [from schema]      | 启用 / 
禁用读库                       | enable readwrite_splitting read resource_0    |  
 |[enable / disable] instance IP=xxx, PORT=xxx                       | 启用 / 
禁用proxy实例                  | disable instance IP=127.0.0.1, PORT=3307      |  
+|show instance list                                                 | 查询 proxy 
实例信息                   | show instance list                            |  
+|show readwrite_splitting read resources [from schema]              | 
查询所有读库的状态                     | show readwrite_splitting read resources       | 
 
+
 
 ## 其他
 
@@ -53,7 +56,6 @@ RAL (Resource & Rule Administration Language) 为 Apache 
ShardingSphere 的管
 |show variable transaction_type                      | 查询当前连接的事务类型             
                    | show variable transaction_type                |  
 |show variable cached_connections                    | 查询当前连接中缓存的物理数据库连接个数     
              | show variable cached_connections              |  
 |show variable agent_plugins_enabled                 | 查询 agent 插件的启用状态        
                     | show variable agent_plugins_enabled           |  
-|show instance list                                  | 查询 proxy 实例信息           
                       | show instance list                            |  
 |preview SQL                                         | 预览实际 SQL                
                         | preview select * from t_order                 |  
 
 ## 注意事项
diff --git a/docs/document/content/features/dist-sql/syntax/ral/ral.en.md 
b/docs/document/content/features/dist-sql/syntax/ral/ral.en.md
index 4e47dce..81fe181 100644
--- a/docs/document/content/features/dist-sql/syntax/ral/ral.en.md
+++ b/docs/document/content/features/dist-sql/syntax/ral/ral.en.md
@@ -42,6 +42,9 @@ RAL (Resource & Rule Administration Language) responsible for 
the added-on featu
 
|:------------------------------------------------------------------|:------------------------------------|:----------------------------------------------|
 |[enable / disable] readwrite_splitting read xxx [from schema]      | Enable 
or disable read data source  | enable readwrite_splitting read resource_0    |  
 |[enable / disable] instance IP=xxx, PORT=xxx                       | Enable 
or disable proxy instance    | disable instance IP=127.0.0.1, PORT=3307      |  
+|show instance list                                                 | Query 
proxy instance information    | show instance list                            | 
 
+|show readwrite_splitting read resources [from schema]              | Query 
all read resources status     | show readwrite_splitting read resources       | 
 
+
 
 ## Other
 
@@ -52,7 +55,6 @@ RAL (Resource & Rule Administration Language) responsible for 
the added-on featu
 |show variable transaction_type                      | Query the transaction 
type of the current connection                                 | show variable 
transaction_type                |  
 |show variable cached_connections                    | Query the number of 
cached physical database connections in the current connection   | show 
variable cached_connections              |  
 |show variable agent_plugins_enabled                 | Query whether the agent 
plugin are enabled                                           | show variable 
agent_plugins_enabled           | 
-|show instance list                                  | Query proxy instance 
information                                                     | show instance 
list                            |  
 |preview SQL                                         | Preview the actual SQLs 
                                                             | preview select * 
from t_order                 |  
 
 ## Notice
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 144d41c..b482c87 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
@@ -87,6 +87,10 @@ SOURCE
     : S O U R C E
     ;
 
+RESOURCES
+    : R E S O U R C E S
+    ;
+
 STATUS
     : S T A T U S
     ;
diff --git 
a/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-distsql/shardingsphere-readwrite-splitting-distsql-parser/src/main/antlr4/imports/readwrite-splitting/RALStatement.g4
 
b/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-distsql/shardingsphere-readwrite-splitting-distsql-parser/src/main/antlr4/imports/readwrite-splitting/RALStatement.g4
index 60c4b7f..106c04f 100644
--- 
a/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-distsql/shardingsphere-readwrite-splitting-distsql-parser/src/main/antlr4/imports/readwrite-splitting/RALStatement.g4
+++ 
b/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-distsql/shardingsphere-readwrite-splitting-distsql-parser/src/main/antlr4/imports/readwrite-splitting/RALStatement.g4
@@ -39,6 +39,10 @@ disableReadDataSource
     : DISABLE READWRITE_SPLITTING READ resourceName (FROM schemaName)?
     ;
 
+showReadwriteSplittingReadResources
+    : SHOW READWRITE_SPLITTING READ RESOURCES (FROM schemaName)?
+    ;
+
 sourceValue
     : IDENTIFIER
     ;
diff --git 
a/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-distsql/shardingsphere-readwrite-splitting-distsql-parser/src/main/antlr4/org/apache/shardingsphere/distsql/parser/autogen/ReadwriteSplittingDistSQLStatement.g4
 
b/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-distsql/shardingsphere-readwrite-splitting-distsql-parser/src/main/antlr4/org/apache/shardingsphere/distsql/parser/autogen/Readwr
 [...]
index 44451bd..5e2a1c4 100644
--- 
a/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-distsql/shardingsphere-readwrite-splitting-distsql-parser/src/main/antlr4/org/apache/shardingsphere/distsql/parser/autogen/ReadwriteSplittingDistSQLStatement.g4
+++ 
b/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-distsql/shardingsphere-readwrite-splitting-distsql-parser/src/main/antlr4/org/apache/shardingsphere/distsql/parser/autogen/ReadwriteSplittingDistSQLStatement.g4
@@ -29,5 +29,6 @@ execute
     | clearReadwriteSplittingHint
     | enableReadDataSource
     | disableReadDataSource
+    | showReadwriteSplittingReadResources
     ) SEMI?
     ;
diff --git 
a/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-distsql/shardingsphere-readwrite-splitting-distsql-parser/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/parser/core/ReadwriteSplittingDistSQLStatementVisitor.java
 
b/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-distsql/shardingsphere-readwrite-splitting-distsql-parser/src/main/java/org/apache/shardingsphere/readwrit
 [...]
index 1015010..642ae6d 100644
--- 
a/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-distsql/shardingsphere-readwrite-splitting-distsql-parser/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/parser/core/ReadwriteSplittingDistSQLStatementVisitor.java
+++ 
b/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-distsql/shardingsphere-readwrite-splitting-distsql-parser/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/parser/core/ReadwriteSplittingDistSQLStatementVisitor.java
@@ -31,9 +31,11 @@ import 
org.apache.shardingsphere.distsql.parser.autogen.ReadwriteSplittingDistSQ
 import 
org.apache.shardingsphere.distsql.parser.autogen.ReadwriteSplittingDistSQLStatementParser.SchemaNameContext;
 import 
org.apache.shardingsphere.distsql.parser.autogen.ReadwriteSplittingDistSQLStatementParser.SetReadwriteSplittingHintSourceContext;
 import 
org.apache.shardingsphere.distsql.parser.autogen.ReadwriteSplittingDistSQLStatementParser.ShowReadwriteSplittingHintStatusContext;
+import 
org.apache.shardingsphere.distsql.parser.autogen.ReadwriteSplittingDistSQLStatementParser.ShowReadwriteSplittingReadResourcesContext;
 import 
org.apache.shardingsphere.distsql.parser.autogen.ReadwriteSplittingDistSQLStatementParser.ShowReadwriteSplittingRulesContext;
 import 
org.apache.shardingsphere.distsql.parser.autogen.ReadwriteSplittingDistSQLStatementParser.StaticReadwriteSplittingRuleDefinitionContext;
 import org.apache.shardingsphere.distsql.parser.segment.AlgorithmSegment;
+import 
org.apache.shardingsphere.readwritesplitting.distsql.parser.statement.ShowReadwriteSplittingReadResourcesStatement;
 import 
org.apache.shardingsphere.readwritesplitting.distsql.parser.statement.status.SetReadwriteSplittingStatusStatement;
 import 
org.apache.shardingsphere.readwritesplitting.distsql.parser.segment.ReadwriteSplittingRuleSegment;
 import 
org.apache.shardingsphere.readwritesplitting.distsql.parser.statement.AlterReadwriteSplittingRuleStatement;
@@ -117,6 +119,11 @@ public final class 
ReadwriteSplittingDistSQLStatementVisitor extends ReadwriteSp
     }
     
     @Override
+    public ASTNode visitShowReadwriteSplittingReadResources(final 
ShowReadwriteSplittingReadResourcesContext ctx) {
+        return new 
ShowReadwriteSplittingReadResourcesStatement(Objects.nonNull(ctx.schemaName()) 
? (SchemaSegment) visit(ctx.schemaName()) : null);
+    }
+    
+    @Override
     public ASTNode visitSetReadwriteSplittingHintSource(final 
SetReadwriteSplittingHintSourceContext ctx) {
         return new 
SetReadwriteSplittingHintStatement(getIdentifierValue(ctx.sourceValue()));
     }
diff --git 
a/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-distsql/shardingsphere-readwrite-splitting-distsql-parser/src/main/antlr4/imports/readwrite-splitting/RALStatement.g4
 
b/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-distsql/shardingsphere-readwrite-splitting-distsql-statement/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/parser/statement/ShowReadwriteSplittingReadR
 [...]
similarity index 50%
copy from 
shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-distsql/shardingsphere-readwrite-splitting-distsql-parser/src/main/antlr4/imports/readwrite-splitting/RALStatement.g4
copy to 
shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-distsql/shardingsphere-readwrite-splitting-distsql-statement/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/parser/statement/ShowReadwriteSplittingReadResourcesStatement.java
index 60c4b7f..b36ae5f 100644
--- 
a/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-distsql/shardingsphere-readwrite-splitting-distsql-parser/src/main/antlr4/imports/readwrite-splitting/RALStatement.g4
+++ 
b/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-distsql/shardingsphere-readwrite-splitting-distsql-statement/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/parser/statement/ShowReadwriteSplittingReadResourcesStatement.java
@@ -15,38 +15,25 @@
  * limitations under the License.
  */
 
-grammar RALStatement;
+package org.apache.shardingsphere.readwritesplitting.distsql.parser.statement;
 
-import Keyword, Literals, Symbol;
+import lombok.RequiredArgsConstructor;
+import 
org.apache.shardingsphere.distsql.parser.statement.ral.common.ShowDistSQLStatement;
+import 
org.apache.shardingsphere.sql.parser.sql.common.segment.generic.SchemaSegment;
+import 
org.apache.shardingsphere.sql.parser.sql.common.statement.available.FromSchemaAvailable;
 
-setReadwriteSplittingHintSource
-    : SET READWRITE_SPLITTING HINT SOURCE EQ sourceValue
-    ;
+import java.util.Optional;
 
-showReadwriteSplittingHintStatus
-    : SHOW READWRITE_SPLITTING HINT STATUS
-    ;
-
-clearReadwriteSplittingHint
-    : CLEAR READWRITE_SPLITTING HINT
-    ;
-
-enableReadDataSource
-    : ENABLE READWRITE_SPLITTING READ resourceName (FROM schemaName)?
-    ;
-
-disableReadDataSource
-    : DISABLE READWRITE_SPLITTING READ resourceName (FROM schemaName)?
-    ;
-
-sourceValue
-    : IDENTIFIER
-    ;
-
-resourceName
-    : IDENTIFIER
-    ;
-
-schemaName
-    : IDENTIFIER
-    ;
+/**
+ * Show readwrite-splitting read resources statement.
+ */
+@RequiredArgsConstructor
+public final class ShowReadwriteSplittingReadResourcesStatement extends 
ShowDistSQLStatement implements FromSchemaAvailable {
+    
+    private final SchemaSegment schema;
+    
+    @Override
+    public Optional<SchemaSegment> getSchema() {
+        return Optional.ofNullable(schema);
+    }
+}
diff --git 
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/show/ShowStatementExecutorFactory.java
 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/show/ShowStatementExecutorFactory.java
index e1d778a..d247571 100644
--- 
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/show/ShowStatementExecutorFactory.java
+++ 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/show/ShowStatementExecutorFactory.java
@@ -23,7 +23,9 @@ import 
org.apache.shardingsphere.distsql.parser.statement.ral.common.show.ShowIn
 import 
org.apache.shardingsphere.distsql.parser.statement.ral.common.show.ShowVariableStatement;
 import 
org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.BackendConnection;
 import 
org.apache.shardingsphere.proxy.backend.text.distsql.ral.common.show.executor.ShowInstanceExecutor;
+import 
org.apache.shardingsphere.proxy.backend.text.distsql.ral.common.show.executor.ShowReadwriteSplittingReadResourcesExecutor;
 import 
org.apache.shardingsphere.proxy.backend.text.distsql.ral.common.show.executor.ShowVariableExecutor;
+import 
org.apache.shardingsphere.readwritesplitting.distsql.parser.statement.ShowReadwriteSplittingReadResourcesStatement;
 
 import java.sql.SQLException;
 
@@ -47,6 +49,9 @@ public final class ShowStatementExecutorFactory {
         if (sqlStatement instanceof ShowVariableStatement) {
             return new ShowVariableExecutor((ShowVariableStatement) 
sqlStatement, backendConnection);
         }
+        if (sqlStatement instanceof 
ShowReadwriteSplittingReadResourcesStatement) {
+            return new 
ShowReadwriteSplittingReadResourcesExecutor((ShowReadwriteSplittingReadResourcesStatement)
 sqlStatement, backendConnection);
+        }
         throw new 
UnsupportedTypeException(sqlStatement.getClass().getCanonicalName());
     }
 }
diff --git 
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/show/executor/ShowReadwriteSplittingReadResourcesExecutor.java
 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/show/executor/ShowReadwriteSplittingReadResourcesExecutor.java
new file mode 100644
index 0000000..6f7155d
--- /dev/null
+++ 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/distsql/ral/common/show/executor/ShowReadwriteSplittingReadResourcesExecutor.java
@@ -0,0 +1,114 @@
+/*
+ * 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.ral.common.show.executor;
+
+import lombok.RequiredArgsConstructor;
+import org.apache.shardingsphere.infra.exception.SchemaNotExistedException;
+import org.apache.shardingsphere.infra.merge.result.MergedResult;
+import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
+import 
org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.status.storage.StorageNodeStatus;
+import 
org.apache.shardingsphere.mode.manager.cluster.coordinator.registry.status.storage.node.StorageStatusNode;
+import org.apache.shardingsphere.mode.metadata.persist.MetaDataPersistService;
+import 
org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.BackendConnection;
+import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
+import 
org.apache.shardingsphere.proxy.backend.exception.NoDatabaseSelectedException;
+import 
org.apache.shardingsphere.proxy.backend.response.header.query.impl.QueryHeader;
+import 
org.apache.shardingsphere.readwritesplitting.distsql.parser.statement.ShowReadwriteSplittingReadResourcesStatement;
+import 
org.apache.shardingsphere.sharding.merge.dal.common.MultipleLocalDataMergedResult;
+
+import java.sql.Types;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Objects;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+/**
+ * Show readwrite-splitting read resources executor.
+ */
+@RequiredArgsConstructor
+public final class ShowReadwriteSplittingReadResourcesExecutor extends 
AbstractShowExecutor {
+    
+    private static final String DELIMITER = "\\.";
+    
+    private static final String RESOURCE = "resource";
+    
+    private static final String STATUS = "status";
+    
+    private static final String DISABLE = "disable";
+    
+    private static final String ENABLE = "enable";
+    
+    private final ShowReadwriteSplittingReadResourcesStatement sqlStatement;
+    
+    private final BackendConnection backendConnection;
+    
+    @Override
+    protected List<QueryHeader> createQueryHeaders() {
+        return Arrays.asList(
+                new QueryHeader("", "", RESOURCE, RESOURCE, Types.VARCHAR, 
"VARCHAR", 64, 0, false, false, false, false),
+                new QueryHeader("", "", STATUS, STATUS, Types.VARCHAR, 
"VARCHAR", 64, 0, false, false, false, false));
+    }
+    
+    @Override
+    protected MergedResult createMergedResult() {
+        String schemaName = sqlStatement.getSchema().isPresent() ? 
sqlStatement.getSchema().get().getIdentifier().getValue() : 
backendConnection.getSchemaName();
+        if (null == schemaName) {
+            throw new NoDatabaseSelectedException();
+        }
+        if 
(!ProxyContext.getInstance().getAllSchemaNames().contains(schemaName)) {
+            throw new SchemaNotExistedException(schemaName);
+        }
+        ShardingSphereMetaData metaData = 
ProxyContext.getInstance().getContextManager().getMetaDataContexts().getMetaData(schemaName);
+        Collection<List<Object>> rows = buildInstanceRows(metaData, ENABLE);
+        MetaDataPersistService persistService = 
ProxyContext.getInstance().getContextManager().getMetaDataContexts().getMetaDataPersistService().orElse(null);
+        if (null == persistService || null == persistService.getRepository()) {
+            return new MultipleLocalDataMergedResult(rows);
+        }
+        Collection<List<Object>> disableInstanceRows = 
buildInstanceRows(persistService, DISABLE);
+        return new MultipleLocalDataMergedResult(mergeRows(rows, 
disableInstanceRows));
+    }
+    
+    private Collection<List<Object>> buildInstanceRows(final 
ShardingSphereMetaData metaData, final String status) {
+        Set<String> allResources = 
metaData.getResource().getDataSources().keySet();
+        return allResources.stream().map(each -> buildRow(each, 
status)).collect(Collectors.toCollection(LinkedList::new));
+    }
+    
+    private Collection<List<Object>> buildInstanceRows(final 
MetaDataPersistService persistService, final String status) {
+        List<String> instanceIds = 
persistService.getRepository().getChildrenKeys(StorageStatusNode.getStatusPath(status.equals(DISABLE)
 ? StorageNodeStatus.DISABLE : StorageNodeStatus.PRIMARY));
+        if (!instanceIds.isEmpty()) {
+            return instanceIds.stream().filter(Objects::nonNull).map(each -> 
each.split(DELIMITER)[1]).map(each -> buildRow(each, 
status)).collect(Collectors.toCollection(LinkedList::new));
+        }
+        return Collections.emptyList();
+    }
+    
+    private Collection<List<Object>> mergeRows(final Collection<List<Object>> 
rows, final Collection<List<Object>> disableInstanceRow) {
+        Collection<List<Object>> result;
+        Set<Object> disableResource = 
disableInstanceRow.stream().flatMap(Collection::stream).filter(each -> 
!each.equals(DISABLE)).collect(Collectors.toSet());
+        result = rows.stream().filter(each -> 
!disableResource.contains(each)).collect(Collectors.toCollection(LinkedList::new));
+        result.addAll(disableInstanceRow);
+        return result;
+    }
+    
+    private List<Object> buildRow(final String resource, final String status) {
+        return Arrays.asList(resource, status);
+    }
+}
diff --git 
a/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/statement/distsql/ral/impl/CommonDistSQLStatementAssert.java
 
b/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/statement/distsql/ral/impl/CommonDistSQLStatementAssert.java
index 0f4d704..23cc401 100644
--- 
a/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/statement/distsql/ral/impl/CommonDistSQLStatementAssert.java
+++ 
b/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/statement/distsql/ral/impl/CommonDistSQLStatementAssert.java
@@ -24,13 +24,16 @@ import 
org.apache.shardingsphere.distsql.parser.statement.ral.common.SetDistSQLS
 import 
org.apache.shardingsphere.distsql.parser.statement.ral.common.set.SetVariableStatement;
 import 
org.apache.shardingsphere.distsql.parser.statement.ral.common.show.ShowInstanceStatement;
 import 
org.apache.shardingsphere.distsql.parser.statement.ral.common.show.ShowVariableStatement;
+import 
org.apache.shardingsphere.readwritesplitting.distsql.parser.statement.ShowReadwriteSplittingReadResourcesStatement;
 import 
org.apache.shardingsphere.test.sql.parser.parameterized.asserts.SQLCaseAssertContext;
 import 
org.apache.shardingsphere.test.sql.parser.parameterized.asserts.statement.distsql.ral.impl.common.SetVariableStatementAssert;
 import 
org.apache.shardingsphere.test.sql.parser.parameterized.asserts.statement.distsql.ral.impl.common.ShowVariableStatementAssert;
 import 
org.apache.shardingsphere.test.sql.parser.parameterized.asserts.statement.distsql.ral.impl.query.ShowInstanceStatementAssert;
+import 
org.apache.shardingsphere.test.sql.parser.parameterized.asserts.statement.distsql.ral.impl.query.ShowReadwriteSplittingReadResourcesStatementAssert;
 import 
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.SQLParserTestCase;
 import 
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.distsql.ral.SetVariableStatementTestCase;
 import 
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.distsql.ral.ShowInstanceStatementTestCase;
+import 
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.distsql.ral.ShowReadwriteSplittingReadResourcesStatementTestCase;
 import 
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.distsql.ral.ShowVariableStatementTestCase;
 
 /**
@@ -53,6 +56,9 @@ public final class CommonDistSQLStatementAssert {
             ShowVariableStatementAssert.assertIs(assertContext, 
(ShowVariableStatement) actual, (ShowVariableStatementTestCase) expected);
         } else if (actual instanceof ShowInstanceStatement) {
             ShowInstanceStatementAssert.assertIs(assertContext, 
(ShowInstanceStatement) actual, (ShowInstanceStatementTestCase) expected);
+        } else if (actual instanceof 
ShowReadwriteSplittingReadResourcesStatement) {
+            
ShowReadwriteSplittingReadResourcesStatementAssert.assertIs(assertContext, 
(ShowReadwriteSplittingReadResourcesStatement) actual,
+                    (ShowReadwriteSplittingReadResourcesStatementTestCase) 
expected);
         }
     }
 }
diff --git 
a/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/statement/distsql/ral/impl/query/ShowReadwriteSplittingReadResourcesStatementAssert.java
 
b/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/statement/distsql/ral/impl/query/ShowReadwriteSplittingReadResourcesStatementAssert.java
new file mode 100644
index 0000000..4e7ea4c
--- /dev/null
+++ 
b/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/statement/distsql/ral/impl/query/ShowReadwriteSplittingReadResourcesStatementAssert.java
@@ -0,0 +1,47 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package 
org.apache.shardingsphere.test.sql.parser.parameterized.asserts.statement.distsql.ral.impl.query;
+
+import 
org.apache.shardingsphere.readwritesplitting.distsql.parser.statement.ShowReadwriteSplittingReadResourcesStatement;
+import 
org.apache.shardingsphere.test.sql.parser.parameterized.asserts.SQLCaseAssertContext;
+import 
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.distsql.ral.ShowReadwriteSplittingReadResourcesStatementTestCase;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+
+/**
+ * Show readwrite-splitting read resources statement assert.
+ */
+public final class ShowReadwriteSplittingReadResourcesStatementAssert {
+    
+    /**
+     * Assert show readwrite-splitting read resources statement is correct 
with expected parser result.
+     *
+     * @param assertContext assert context
+     * @param actual actual show readwrite-splitting read resources statement
+     * @param expected expected show readwrite-splitting read resources 
statement test case
+     */
+    public static void assertIs(final SQLCaseAssertContext assertContext, 
final ShowReadwriteSplittingReadResourcesStatement actual, 
+                                final 
ShowReadwriteSplittingReadResourcesStatementTestCase expected) {
+        if (null == expected) {
+            assertNull(assertContext.getText("Actual statement should not 
exist."), actual);
+        } else {
+            assertNotNull(assertContext.getText("Actual statement should 
exist."), actual);
+        }
+    }
+}
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 97e916a..ade5893 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
@@ -108,6 +108,7 @@ import 
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain
 import 
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.distsql.ral.SetVariableStatementTestCase;
 import 
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.distsql.ral.ShowInstanceStatementTestCase;
 import 
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.distsql.ral.ShowReadwriteSplittingHintStatusStatementTestCase;
+import 
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.distsql.ral.ShowReadwriteSplittingReadResourcesStatementTestCase;
 import 
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.distsql.ral.ShowScalingListStatementTestCase;
 import 
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.distsql.ral.ShowShardingHintStatusStatementTestCase;
 import 
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.distsql.ral.ShowVariableStatementTestCase;
@@ -620,11 +621,15 @@ public final class SQLParserTestCases {
     @XmlElement(name = "show-instance")
     private final List<ShowInstanceStatementTestCase> 
showInstanceStatementTestCases = new LinkedList<>();
     
+    @XmlElement(name = "show-readwrite-splitting-read-resources")
+    private final List<ShowReadwriteSplittingReadResourcesStatementTestCase> 
showReadwriteSplittingReadResourcesStatementTestCases = new LinkedList<>();
+    
     /**
      * Get all SQL parser test cases.
      *
      * @return all SQL parser test cases
      */
+    // CHECKSTYLE:OFF
     public Map<String, SQLParserTestCase> getAllSQLParserTestCases() {
         Map<String, SQLParserTestCase> result = new HashMap<>();
         putAll(selectTestCases, result);
@@ -773,8 +778,10 @@ public final class SQLParserTestCases {
         putAll(flushStatementTestCase, result);
         putAll(installPluginStatementTestCase, result);
         putAll(showInstanceStatementTestCases, result);
+        putAll(showReadwriteSplittingReadResourcesStatementTestCases, result);
         return result;
     }
+    // CHECKSTYLE:ON
     
     private void putAll(final List<? extends SQLParserTestCase> 
sqlParserTestCases, final Map<String, SQLParserTestCase> target) {
         Map<String, SQLParserTestCase> sqlParserTestCaseMap = 
getSQLParserTestCases(sqlParserTestCases);
diff --git 
a/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-distsql/shardingsphere-readwrite-splitting-distsql-parser/src/main/antlr4/org/apache/shardingsphere/distsql/parser/autogen/ReadwriteSplittingDistSQLStatement.g4
 
b/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/jaxb/cases/domain/statement/distsql/ral/ShowReadwriteSplittingReadResourcesStatementTestCase.java
similarity index 65%
copy from 
shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-distsql/shardingsphere-readwrite-splitting-distsql-parser/src/main/antlr4/org/apache/shardingsphere/distsql/parser/autogen/ReadwriteSplittingDistSQLStatement.g4
copy to 
shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/jaxb/cases/domain/statement/distsql/ral/ShowReadwriteSplittingReadResourcesStatementTestCase.java
index 44451bd..3b84cc9 100644
--- 
a/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-distsql/shardingsphere-readwrite-splitting-distsql-parser/src/main/antlr4/org/apache/shardingsphere/distsql/parser/autogen/ReadwriteSplittingDistSQLStatement.g4
+++ 
b/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/jaxb/cases/domain/statement/distsql/ral/ShowReadwriteSplittingReadResourcesStatementTestCase.java
@@ -15,19 +15,12 @@
  * limitations under the License.
  */
 
-grammar ReadwriteSplittingDistSQLStatement;
+package 
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.distsql.ral;
 
-import Symbol, RALStatement, RDLStatement, RQLStatement;
+import 
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.SQLParserTestCase;
 
-execute
-    : (createReadwriteSplittingRule
-    | alterReadwriteSplittingRule
-    | dropReadwriteSplittingRule
-    | showReadwriteSplittingRules
-    | setReadwriteSplittingHintSource
-    | showReadwriteSplittingHintStatus
-    | clearReadwriteSplittingHint
-    | enableReadDataSource
-    | disableReadDataSource
-    ) SEMI?
-    ;
+/**
+ * Show readwrite-splitting read resources statement test case.
+ */
+public final class ShowReadwriteSplittingReadResourcesStatementTestCase 
extends SQLParserTestCase {
+}
diff --git 
a/shardingsphere-test/shardingsphere-parser-test/src/main/resources/case/ral/show.xml
 
b/shardingsphere-test/shardingsphere-parser-test/src/main/resources/case/ral/show.xml
index 112dcb1..3f5c997 100644
--- 
a/shardingsphere-test/shardingsphere-parser-test/src/main/resources/case/ral/show.xml
+++ 
b/shardingsphere-test/shardingsphere-parser-test/src/main/resources/case/ral/show.xml
@@ -21,4 +21,5 @@
     <show-readwrite-splitting-hint-source 
sql-case-id="show-readwrite-splitting-hint-source" />
     <show-sharding-hint-status sql-case-id="show-sharding-hint-status" />
     <show-instance sql-case-id="show-instance" />
+    <show-readwrite-splitting-read-resources 
sql-case-id="show-readwrite-splitting-read-resources" />
 </sql-parser-test-cases>
diff --git 
a/shardingsphere-test/shardingsphere-parser-test/src/main/resources/sql/supported/ral/show.xml
 
b/shardingsphere-test/shardingsphere-parser-test/src/main/resources/sql/supported/ral/show.xml
index f461417..f5d6f21 100644
--- 
a/shardingsphere-test/shardingsphere-parser-test/src/main/resources/sql/supported/ral/show.xml
+++ 
b/shardingsphere-test/shardingsphere-parser-test/src/main/resources/sql/supported/ral/show.xml
@@ -21,4 +21,5 @@
     <distsql-case id="show-readwrite-splitting-hint-source" value="SHOW 
READWRITE_SPLITTING HINT STATUS" />
     <distsql-case id="show-sharding-hint-status" value="SHOW SHARDING HINT 
STATUS" />
     <distsql-case id="show-instance" value="SHOW INSTANCE LIST" />
+    <distsql-case id="show-readwrite-splitting-read-resources" value="show 
readwrite_splitting read resources" />
 </sql-cases>

Reply via email to