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 0f167519dd2 Replace `ShadowAlgorithmResultSet` with 
`ShowShadowAlgorithmExecutor` (#23819)
0f167519dd2 is described below

commit 0f167519dd2802c4bb9dd3f13c2a98b7064c6696
Author: Zichao <[email protected]>
AuthorDate: Mon Jan 30 18:31:56 2023 +1300

    Replace `ShadowAlgorithmResultSet` with `ShowShadowAlgorithmExecutor` 
(#23819)
---
 ...ltSet.java => ShowShadowAlgorithmExecutor.java} | 45 +++++++++-------------
 ...hardingsphere.distsql.handler.query.RQLExecutor |  1 +
 ...here.distsql.handler.resultset.DistSQLResultSet |  1 -
 ...t.java => ShowShadowAlgorithmExecutorTest.java} | 40 ++++++++++++-------
 4 files changed, 46 insertions(+), 41 deletions(-)

diff --git 
a/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/query/ShadowAlgorithmResultSet.java
 
b/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/query/ShowShadowAlgorithmExecutor.java
similarity index 62%
rename from 
features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/query/ShadowAlgorithmResultSet.java
rename to 
features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/query/ShowShadowAlgorithmExecutor.java
index 756d372bb81..f60f576ea7b 100644
--- 
a/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/query/ShadowAlgorithmResultSet.java
+++ 
b/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/query/ShowShadowAlgorithmExecutor.java
@@ -17,41 +17,46 @@
 
 package org.apache.shardingsphere.shadow.distsql.handler.query;
 
+import org.apache.shardingsphere.distsql.handler.query.RQLExecutor;
 import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
-import 
org.apache.shardingsphere.distsql.handler.resultset.DatabaseDistSQLResultSet;
+import 
org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
 import 
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
 import org.apache.shardingsphere.infra.util.props.PropertiesConverter;
 import org.apache.shardingsphere.shadow.api.config.ShadowRuleConfiguration;
 import 
org.apache.shardingsphere.shadow.distsql.parser.statement.ShowShadowAlgorithmsStatement;
 import org.apache.shardingsphere.shadow.rule.ShadowRule;
-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.LinkedList;
 import java.util.Map.Entry;
 import java.util.Objects;
 import java.util.Optional;
 import java.util.Properties;
 
 /**
- * Result set for show shadow algorithm.
+ * Show shadow algorithm executor.
  */
-public final class ShadowAlgorithmResultSet implements 
DatabaseDistSQLResultSet {
-    
-    private Iterator<Entry<String, AlgorithmConfiguration>> data = 
Collections.emptyIterator();
-    
-    private String defaultAlgorithm;
+public final class ShowShadowAlgorithmExecutor implements 
RQLExecutor<ShowShadowAlgorithmsStatement> {
     
     @Override
-    public void init(final ShardingSphereDatabase database, final SQLStatement 
sqlStatement) {
+    public Collection<LocalDataQueryResultRow> getRows(final 
ShardingSphereDatabase database, final ShowShadowAlgorithmsStatement 
sqlStatement) {
         Optional<ShadowRule> rule = 
database.getRuleMetaData().findSingleRule(ShadowRule.class);
-        if (rule.isPresent()) {
-            ShadowRuleConfiguration config = (ShadowRuleConfiguration) 
rule.get().getConfiguration();
-            data = config.getShadowAlgorithms().entrySet().iterator();
-            defaultAlgorithm = config.getDefaultShadowAlgorithmName();
+        if (!rule.isPresent()) {
+            return Collections.emptyList();
+        }
+        ShadowRuleConfiguration config = (ShadowRuleConfiguration) 
rule.get().getConfiguration();
+        Iterator<Entry<String, AlgorithmConfiguration>> data = 
config.getShadowAlgorithms().entrySet().iterator();
+        String defaultAlgorithm = config.getDefaultShadowAlgorithmName();
+        Collection<LocalDataQueryResultRow> result = new LinkedList<>();
+        while (data.hasNext()) {
+            Entry<String, AlgorithmConfiguration> row = data.next();
+            result.add(new LocalDataQueryResultRow(row.getKey(), 
row.getValue().getType(),
+                    convertToString(row.getValue().getProps()), 
Boolean.valueOf(row.getKey().equals(defaultAlgorithm)).toString()));
         }
+        return result;
     }
     
     @Override
@@ -59,20 +64,6 @@ public final class ShadowAlgorithmResultSet implements 
DatabaseDistSQLResultSet
         return Arrays.asList("shadow_algorithm_name", "type", "props", 
"is_default");
     }
     
-    @Override
-    public boolean next() {
-        return data.hasNext();
-    }
-    
-    @Override
-    public Collection<Object> getRowData() {
-        return buildTableRowData(data.next());
-    }
-    
-    private Collection<Object> buildTableRowData(final Entry<String, 
AlgorithmConfiguration> data) {
-        return Arrays.asList(data.getKey(), data.getValue().getType(), 
convertToString(data.getValue().getProps()), 
Boolean.valueOf(data.getKey().equals(defaultAlgorithm)).toString());
-    }
-    
     private String convertToString(final Properties props) {
         return Objects.nonNull(props) ? PropertiesConverter.convert(props) : 
"";
     }
diff --git 
a/features/shadow/distsql/handler/src/main/resources/META-INF/services/org.apache.shardingsphere.distsql.handler.query.RQLExecutor
 
b/features/shadow/distsql/handler/src/main/resources/META-INF/services/org.apache.shardingsphere.distsql.handler.query.RQLExecutor
index 7361ed20031..cc62e23e483 100644
--- 
a/features/shadow/distsql/handler/src/main/resources/META-INF/services/org.apache.shardingsphere.distsql.handler.query.RQLExecutor
+++ 
b/features/shadow/distsql/handler/src/main/resources/META-INF/services/org.apache.shardingsphere.distsql.handler.query.RQLExecutor
@@ -17,3 +17,4 @@
 
 org.apache.shardingsphere.shadow.distsql.handler.query.ShowShadowRuleExecutor
 
org.apache.shardingsphere.shadow.distsql.handler.query.ShowShadowTableRuleExecutor
+org.apache.shardingsphere.shadow.distsql.handler.query.ShowShadowAlgorithmExecutor
diff --git 
a/features/shadow/distsql/handler/src/main/resources/META-INF/services/org.apache.shardingsphere.distsql.handler.resultset.DistSQLResultSet
 
b/features/shadow/distsql/handler/src/main/resources/META-INF/services/org.apache.shardingsphere.distsql.handler.resultset.DistSQLResultSet
index b377baa5cdd..8d5dce23696 100644
--- 
a/features/shadow/distsql/handler/src/main/resources/META-INF/services/org.apache.shardingsphere.distsql.handler.resultset.DistSQLResultSet
+++ 
b/features/shadow/distsql/handler/src/main/resources/META-INF/services/org.apache.shardingsphere.distsql.handler.resultset.DistSQLResultSet
@@ -15,6 +15,5 @@
 # limitations under the License.
 #
 
-org.apache.shardingsphere.shadow.distsql.handler.query.ShadowAlgorithmResultSet
 
org.apache.shardingsphere.shadow.distsql.handler.query.DefaultShadowAlgorithmResultSet
 org.apache.shardingsphere.shadow.distsql.handler.query.CountShadowRuleResultSet
diff --git 
a/features/shadow/distsql/handler/src/test/java/org/apache/shardingsphere/shadow/distsql/query/ShadowAlgorithmResultSetTest.java
 
b/features/shadow/distsql/handler/src/test/java/org/apache/shardingsphere/shadow/distsql/query/ShowShadowAlgorithmExecutorTest.java
similarity index 66%
rename from 
features/shadow/distsql/handler/src/test/java/org/apache/shardingsphere/shadow/distsql/query/ShadowAlgorithmResultSetTest.java
rename to 
features/shadow/distsql/handler/src/test/java/org/apache/shardingsphere/shadow/distsql/query/ShowShadowAlgorithmExecutorTest.java
index 7a15fd2e68e..473b99d169f 100644
--- 
a/features/shadow/distsql/handler/src/test/java/org/apache/shardingsphere/shadow/distsql/query/ShadowAlgorithmResultSetTest.java
+++ 
b/features/shadow/distsql/handler/src/test/java/org/apache/shardingsphere/shadow/distsql/query/ShowShadowAlgorithmExecutorTest.java
@@ -17,23 +17,24 @@
 
 package org.apache.shardingsphere.shadow.distsql.query;
 
-import 
org.apache.shardingsphere.distsql.handler.resultset.DatabaseDistSQLResultSet;
+import org.apache.shardingsphere.distsql.handler.query.RQLExecutor;
 import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
 import org.apache.shardingsphere.infra.config.rule.RuleConfiguration;
+import 
org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
 import 
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
 import 
org.apache.shardingsphere.infra.metadata.database.rule.ShardingSphereRuleMetaData;
 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.ShadowAlgorithmResultSet;
+import 
org.apache.shardingsphere.shadow.distsql.handler.query.ShowShadowAlgorithmExecutor;
 import 
org.apache.shardingsphere.shadow.distsql.parser.statement.ShowShadowAlgorithmsStatement;
 import org.apache.shardingsphere.shadow.rule.ShadowRule;
 import org.apache.shardingsphere.test.util.PropertiesBuilder;
 import org.apache.shardingsphere.test.util.PropertiesBuilder.Property;
 import org.junit.Test;
 
-import java.util.ArrayList;
+import java.util.Collection;
 import java.util.Collections;
-import java.util.List;
+import java.util.Iterator;
 
 import static org.hamcrest.CoreMatchers.is;
 import static org.hamcrest.MatcherAssert.assertThat;
@@ -41,18 +42,31 @@ import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 
-public final class ShadowAlgorithmResultSetTest {
+public final class ShowShadowAlgorithmExecutorTest {
     
     @Test
     public void assertGetRowData() {
-        DatabaseDistSQLResultSet resultSet = new ShadowAlgorithmResultSet();
-        resultSet.init(mockDatabase(), 
mock(ShowShadowAlgorithmsStatement.class));
-        List<Object> actual = new ArrayList<>(resultSet.getRowData());
-        assertThat(actual.size(), is(4));
-        assertThat(actual.get(0), is("shadowAlgorithmName"));
-        assertThat(actual.get(1), is("simple_hint"));
-        assertThat(actual.get(2), is("foo=bar"));
-        assertThat(actual.get(3), is("false"));
+        RQLExecutor<ShowShadowAlgorithmsStatement> executor = new 
ShowShadowAlgorithmExecutor();
+        Collection<LocalDataQueryResultRow> actual = 
executor.getRows(mockDatabase(), mock(ShowShadowAlgorithmsStatement.class));
+        assertThat(actual.size(), is(1));
+        Iterator<LocalDataQueryResultRow> iterator = actual.iterator();
+        LocalDataQueryResultRow row = iterator.next();
+        assertThat(row.getCell(1), is("shadowAlgorithmName"));
+        assertThat(row.getCell(2), is("simple_hint"));
+        assertThat(row.getCell(3), is("foo=bar"));
+        assertThat(row.getCell(4), is("false"));
+    }
+    
+    @Test
+    public void assertGetColumnNames() {
+        RQLExecutor<ShowShadowAlgorithmsStatement> executor = new 
ShowShadowAlgorithmExecutor();
+        Collection<String> columns = executor.getColumnNames();
+        assertThat(columns.size(), is(4));
+        Iterator<String> iterator = columns.iterator();
+        assertThat(iterator.next(), is("shadow_algorithm_name"));
+        assertThat(iterator.next(), is("type"));
+        assertThat(iterator.next(), is("props"));
+        assertThat(iterator.next(), is("is_default"));
     }
     
     private ShardingSphereDatabase mockDatabase() {

Reply via email to