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 293e68f4239 Replace `AuthorityRuleResultSet` with
`AuthorityRuleExecutor` (#23918)
293e68f4239 is described below
commit 293e68f42390ec730f5f3f63571516106429e43f
Author: Zichao <[email protected]>
AuthorDate: Thu Feb 2 21:11:22 2023 +1300
Replace `AuthorityRuleResultSet` with `AuthorityRuleExecutor` (#23918)
---
...leResultSet.java => AuthorityRuleExecutor.java} | 42 ++++++----------------
...distsql.handler.ral.query.QueryableRALExecutor} | 2 +-
...SetTest.java => AuthorityRuleExecutorTest.java} | 41 ++++++++++++++-------
3 files changed, 39 insertions(+), 46 deletions(-)
diff --git
a/kernel/authority/distsql/handler/src/main/java/org/apache/shardingsphere/authority/distsql/handler/AuthorityRuleResultSet.java
b/kernel/authority/distsql/handler/src/main/java/org/apache/shardingsphere/authority/distsql/handler/AuthorityRuleExecutor.java
similarity index 53%
rename from
kernel/authority/distsql/handler/src/main/java/org/apache/shardingsphere/authority/distsql/handler/AuthorityRuleResultSet.java
rename to
kernel/authority/distsql/handler/src/main/java/org/apache/shardingsphere/authority/distsql/handler/AuthorityRuleExecutor.java
index 603bb46c7b3..baa52f152aa 100644
---
a/kernel/authority/distsql/handler/src/main/java/org/apache/shardingsphere/authority/distsql/handler/AuthorityRuleResultSet.java
+++
b/kernel/authority/distsql/handler/src/main/java/org/apache/shardingsphere/authority/distsql/handler/AuthorityRuleExecutor.java
@@ -20,53 +20,31 @@ package org.apache.shardingsphere.authority.distsql.handler;
import org.apache.shardingsphere.authority.config.AuthorityRuleConfiguration;
import
org.apache.shardingsphere.authority.distsql.parser.statement.ShowAuthorityRuleStatement;
import org.apache.shardingsphere.authority.rule.AuthorityRule;
-import
org.apache.shardingsphere.distsql.handler.resultset.GlobalRuleDistSQLResultSet;
-import
org.apache.shardingsphere.infra.metadata.database.rule.ShardingSphereRuleMetaData;
-import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement;
+import
org.apache.shardingsphere.distsql.handler.ral.query.MetaDataRequiredQueryableRALExecutor;
+import
org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
+import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
-import java.util.Iterator;
import java.util.stream.Collectors;
/**
- * Result set for authority rule.
+ * Show authority rule executor.
*/
-public final class AuthorityRuleResultSet implements
GlobalRuleDistSQLResultSet {
-
- private static final String USERS = "users";
-
- private static final String PROVIDER = "provider";
-
- private static final String PROPS = "props";
-
- private Iterator<Collection<Object>> data;
+public final class AuthorityRuleExecutor implements
MetaDataRequiredQueryableRALExecutor<ShowAuthorityRuleStatement> {
@Override
- public void init(final ShardingSphereRuleMetaData globalRuleMetaData,
final SQLStatement sqlStatement) {
- AuthorityRule rule =
globalRuleMetaData.getSingleRule(AuthorityRule.class);
- data = buildData(rule.getConfiguration()).iterator();
- }
-
- private Collection<Collection<Object>> buildData(final
AuthorityRuleConfiguration ruleConfig) {
- return
Collections.singleton(Arrays.asList(ruleConfig.getUsers().stream().map(each ->
each.getGrantee().toString()).collect(Collectors.joining("; ")),
+ public Collection<LocalDataQueryResultRow> getRows(final
ShardingSphereMetaData metaData, final ShowAuthorityRuleStatement sqlStatement)
{
+ AuthorityRule rule =
metaData.getGlobalRuleMetaData().getSingleRule(AuthorityRule.class);
+ AuthorityRuleConfiguration ruleConfig = rule.getConfiguration();
+ return Collections.singleton(new
LocalDataQueryResultRow(ruleConfig.getUsers().stream().map(each ->
each.getGrantee().toString()).collect(Collectors.joining("; ")),
ruleConfig.getProvider().getType(),
ruleConfig.getProvider().getProps().isEmpty() ? "" :
ruleConfig.getProvider().getProps()));
}
@Override
public Collection<String> getColumnNames() {
- return Arrays.asList(USERS, PROVIDER, PROPS);
- }
-
- @Override
- public boolean next() {
- return data.hasNext();
- }
-
- @Override
- public Collection<Object> getRowData() {
- return data.next();
+ return Arrays.asList("users", "provider", "props");
}
@Override
diff --git
a/kernel/authority/distsql/handler/src/main/resources/META-INF/services/org.apache.shardingsphere.distsql.handler.resultset.DistSQLResultSet
b/kernel/authority/distsql/handler/src/main/resources/META-INF/services/org.apache.shardingsphere.distsql.handler.ral.query.QueryableRALExecutor
similarity index 98%
rename from
kernel/authority/distsql/handler/src/main/resources/META-INF/services/org.apache.shardingsphere.distsql.handler.resultset.DistSQLResultSet
rename to
kernel/authority/distsql/handler/src/main/resources/META-INF/services/org.apache.shardingsphere.distsql.handler.ral.query.QueryableRALExecutor
index 037abffc087..6a5d6525750 100644
---
a/kernel/authority/distsql/handler/src/main/resources/META-INF/services/org.apache.shardingsphere.distsql.handler.resultset.DistSQLResultSet
+++
b/kernel/authority/distsql/handler/src/main/resources/META-INF/services/org.apache.shardingsphere.distsql.handler.ral.query.QueryableRALExecutor
@@ -15,4 +15,4 @@
# limitations under the License.
#
-org.apache.shardingsphere.authority.distsql.handler.AuthorityRuleResultSet
+org.apache.shardingsphere.authority.distsql.handler.AuthorityRuleExecutor
diff --git
a/kernel/authority/distsql/handler/src/test/java/org/apache/shardingsphere/authority/distsql/handler/AuthorityRuleResultSetTest.java
b/kernel/authority/distsql/handler/src/test/java/org/apache/shardingsphere/authority/distsql/handler/AuthorityRuleExecutorTest.java
similarity index 57%
rename from
kernel/authority/distsql/handler/src/test/java/org/apache/shardingsphere/authority/distsql/handler/AuthorityRuleResultSetTest.java
rename to
kernel/authority/distsql/handler/src/test/java/org/apache/shardingsphere/authority/distsql/handler/AuthorityRuleExecutorTest.java
index 1a8c7dd5929..eb53f79c37a 100644
---
a/kernel/authority/distsql/handler/src/test/java/org/apache/shardingsphere/authority/distsql/handler/AuthorityRuleResultSetTest.java
+++
b/kernel/authority/distsql/handler/src/test/java/org/apache/shardingsphere/authority/distsql/handler/AuthorityRuleExecutorTest.java
@@ -20,40 +20,55 @@ package org.apache.shardingsphere.authority.distsql.handler;
import org.apache.shardingsphere.authority.config.AuthorityRuleConfiguration;
import
org.apache.shardingsphere.authority.distsql.parser.statement.ShowAuthorityRuleStatement;
import org.apache.shardingsphere.authority.rule.AuthorityRule;
-import
org.apache.shardingsphere.distsql.handler.resultset.GlobalRuleDistSQLResultSet;
import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
+import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
+import
org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
+import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
import
org.apache.shardingsphere.infra.metadata.database.rule.ShardingSphereRuleMetaData;
import org.apache.shardingsphere.infra.metadata.user.ShardingSphereUser;
import org.junit.Test;
import java.util.Collection;
import java.util.Collections;
+import java.util.Iterator;
+import java.util.LinkedHashMap;
import java.util.Properties;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
-public final class AuthorityRuleResultSetTest {
+public final class AuthorityRuleExecutorTest {
@Test
public void assertExecute() {
- ShardingSphereRuleMetaData ruleMetaData = mockGlobalRuleMetaData();
- GlobalRuleDistSQLResultSet resultSet = new AuthorityRuleResultSet();
- resultSet.init(ruleMetaData, mock(ShowAuthorityRuleStatement.class));
- Collection<Object> actual = resultSet.getRowData();
- assertThat(actual.size(), is(3));
- assertTrue(actual.contains("root@localhost"));
- assertTrue(actual.contains("ALL_PERMITTED"));
- assertTrue(actual.contains(""));
+ ShardingSphereMetaData metaData = mockMetaData();
+ AuthorityRuleExecutor executor = new AuthorityRuleExecutor();
+ Collection<LocalDataQueryResultRow> actual =
executor.getRows(metaData, mock(ShowAuthorityRuleStatement.class));
+ assertThat(actual.size(), is(1));
+ Iterator<LocalDataQueryResultRow> iterator = actual.iterator();
+ LocalDataQueryResultRow row = iterator.next();
+ assertThat(row.getCell(1), is("root@localhost"));
+ assertThat(row.getCell(2), is("ALL_PERMITTED"));
+ assertThat(row.getCell(3), is(""));
}
- private ShardingSphereRuleMetaData mockGlobalRuleMetaData() {
+ @Test
+ public void assertGetColumnNames() {
+ AuthorityRuleExecutor executor = new AuthorityRuleExecutor();
+ Collection<String> columns = executor.getColumnNames();
+ assertThat(columns.size(), is(3));
+ Iterator<String> iterator = columns.iterator();
+ assertThat(iterator.next(), is("users"));
+ assertThat(iterator.next(), is("provider"));
+ assertThat(iterator.next(), is("props"));
+ }
+
+ private ShardingSphereMetaData mockMetaData() {
AuthorityRule authorityRule = mock(AuthorityRule.class);
when(authorityRule.getConfiguration()).thenReturn(createAuthorityRuleConfiguration());
- return new
ShardingSphereRuleMetaData(Collections.singleton(authorityRule));
+ return new ShardingSphereMetaData(new LinkedHashMap<>(), new
ShardingSphereRuleMetaData(Collections.singleton(authorityRule)), new
ConfigurationProperties(new Properties()));
}
private AuthorityRuleConfiguration createAuthorityRuleConfiguration() {