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 c66ee2685a7 Replace `ShardingTableRulesUsedAuditorResultSet` with
`ShowShardingTableRulesUsedAuditorExecutor` (#23852)
c66ee2685a7 is described below
commit c66ee2685a7a2f683ec872b529746140fa8e7b8a
Author: Zichao <[email protected]>
AuthorDate: Tue Jan 31 16:27:55 2023 +1300
Replace `ShardingTableRulesUsedAuditorResultSet` with
`ShowShardingTableRulesUsedAuditorExecutor` (#23852)
---
...ShowShardingTableRulesUsedAuditorExecutor.java} | 37 ++++++--------------
...hardingsphere.distsql.handler.query.RQLExecutor | 1 +
...here.distsql.handler.resultset.DistSQLResultSet | 1 -
...ShardingTableRulesUsedAuditorExecutorTest.java} | 39 ++++++++++++++--------
...wDefaultSingleTableStorageUnitExecutorTest.java | 1 -
.../distsql/rql/ShowSingleTableExecutorTest.java | 1 -
.../distsql/rql/ShowStorageUnitExecutorTest.java | 1 -
7 files changed, 37 insertions(+), 44 deletions(-)
diff --git
a/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/query/ShardingTableRulesUsedAuditorResultSet.java
b/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/query/ShowShardingTableRulesUsedAuditorExecutor.java
similarity index 64%
rename from
features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/query/ShardingTableRulesUsedAuditorResultSet.java
rename to
features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/query/ShowShardingTableRulesUsedAuditorExecutor.java
index 4e2c2f4d349..4650f86f543 100644
---
a/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/query/ShardingTableRulesUsedAuditorResultSet.java
+++
b/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/query/ShowShardingTableRulesUsedAuditorExecutor.java
@@ -17,47 +17,42 @@
package org.apache.shardingsphere.sharding.distsql.handler.query;
-import
org.apache.shardingsphere.distsql.handler.resultset.DatabaseDistSQLResultSet;
+import org.apache.shardingsphere.distsql.handler.query.RQLExecutor;
+import
org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
import
org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase;
import org.apache.shardingsphere.sharding.api.config.ShardingRuleConfiguration;
import
org.apache.shardingsphere.sharding.distsql.parser.statement.ShowShardingTableRulesUsedAuditorStatement;
import org.apache.shardingsphere.sharding.rule.ShardingRule;
-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;
/**
- * Result set for show sharding table rules used auditor.
+ * Show sharding table rules used auditor executor.
*/
-public final class ShardingTableRulesUsedAuditorResultSet implements
DatabaseDistSQLResultSet {
-
- private Iterator<Collection<Object>> data = Collections.emptyIterator();
+public final class ShowShardingTableRulesUsedAuditorExecutor implements
RQLExecutor<ShowShardingTableRulesUsedAuditorStatement> {
@Override
- public void init(final ShardingSphereDatabase database, final SQLStatement
sqlStatement) {
- ShowShardingTableRulesUsedAuditorStatement statement =
(ShowShardingTableRulesUsedAuditorStatement) sqlStatement;
- Collection<Collection<Object>> result = new LinkedList<>();
-
database.getRuleMetaData().findSingleRule(ShardingRule.class).ifPresent(optional
-> requireResult(statement, result, optional));
- data = result.iterator();
+ public Collection<LocalDataQueryResultRow> getRows(final
ShardingSphereDatabase database, final
ShowShardingTableRulesUsedAuditorStatement sqlStatement) {
+ Collection<LocalDataQueryResultRow> result = new LinkedList<>();
+
database.getRuleMetaData().findSingleRule(ShardingRule.class).ifPresent(optional
-> requireResult(sqlStatement, result, optional));
+ return result;
}
- private void requireResult(final
ShowShardingTableRulesUsedAuditorStatement statement, final
Collection<Collection<Object>> result, final ShardingRule rule) {
+ private void requireResult(final
ShowShardingTableRulesUsedAuditorStatement statement, final
Collection<LocalDataQueryResultRow> result, final ShardingRule rule) {
if (!statement.getAuditorName().isPresent()) {
return;
}
ShardingRuleConfiguration config = (ShardingRuleConfiguration)
rule.getConfiguration();
config.getTables().forEach(each -> {
if (null != each.getAuditStrategy() &&
each.getAuditStrategy().getAuditorNames().contains(statement.getAuditorName().get()))
{
- result.add(Arrays.asList("table", each.getLogicTable()));
+ result.add(new LocalDataQueryResultRow("table",
each.getLogicTable()));
}
});
config.getAutoTables().forEach(each -> {
if (null != each.getAuditStrategy() &&
each.getAuditStrategy().getAuditorNames().contains(statement.getAuditorName().get()))
{
- result.add(Arrays.asList("auto_table", each.getLogicTable()));
+ result.add(new LocalDataQueryResultRow("auto_table",
each.getLogicTable()));
}
});
}
@@ -67,16 +62,6 @@ public final class ShardingTableRulesUsedAuditorResultSet
implements DatabaseDis
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 ShowShardingTableRulesUsedAuditorStatement.class.getName();
diff --git
a/features/sharding/distsql/handler/src/main/resources/META-INF/services/org.apache.shardingsphere.distsql.handler.query.RQLExecutor
b/features/sharding/distsql/handler/src/main/resources/META-INF/services/org.apache.shardingsphere.distsql.handler.query.RQLExecutor
index c8d78bb3ac8..0ffd2c93085 100644
---
a/features/sharding/distsql/handler/src/main/resources/META-INF/services/org.apache.shardingsphere.distsql.handler.query.RQLExecutor
+++
b/features/sharding/distsql/handler/src/main/resources/META-INF/services/org.apache.shardingsphere.distsql.handler.query.RQLExecutor
@@ -22,3 +22,4 @@
org.apache.shardingsphere.sharding.distsql.handler.query.ShowDefaultShardingStra
org.apache.shardingsphere.sharding.distsql.handler.query.ShowShardingAuditorsExecutor
org.apache.shardingsphere.sharding.distsql.handler.query.ShowShardingTableRulesUsedAlgorithmExecutor
org.apache.shardingsphere.sharding.distsql.handler.query.ShowShardingTableRulesUsedKeyGeneratorExecutor
+org.apache.shardingsphere.sharding.distsql.handler.query.ShowShardingTableRulesUsedAuditorExecutor
diff --git
a/features/sharding/distsql/handler/src/main/resources/META-INF/services/org.apache.shardingsphere.distsql.handler.resultset.DistSQLResultSet
b/features/sharding/distsql/handler/src/main/resources/META-INF/services/org.apache.shardingsphere.distsql.handler.resultset.DistSQLResultSet
index 3b8a347a3c0..b957cbe61ed 100644
---
a/features/sharding/distsql/handler/src/main/resources/META-INF/services/org.apache.shardingsphere.distsql.handler.resultset.DistSQLResultSet
+++
b/features/sharding/distsql/handler/src/main/resources/META-INF/services/org.apache.shardingsphere.distsql.handler.resultset.DistSQLResultSet
@@ -21,5 +21,4 @@
org.apache.shardingsphere.sharding.distsql.handler.query.ShardingTableNodesResul
org.apache.shardingsphere.sharding.distsql.handler.query.UnusedShardingAlgorithmsResultSet
org.apache.shardingsphere.sharding.distsql.handler.query.UnusedShardingKeyGeneratorResultSet
org.apache.shardingsphere.sharding.distsql.handler.query.UnusedShardingAuditorsResultSet
-org.apache.shardingsphere.sharding.distsql.handler.query.ShardingTableRulesUsedAuditorResultSet
org.apache.shardingsphere.sharding.distsql.handler.query.CountShardingRuleResultSet
diff --git
a/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/ShowShardingTableRulesUsedAuditorResultSetTest.java
b/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/ShowShardingTableRulesUsedAuditorExecutorTest.java
similarity index 80%
rename from
features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/ShowShardingTableRulesUsedAuditorResultSetTest.java
rename to
features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/ShowShardingTableRulesUsedAuditorExecutorTest.java
index 773d98a8919..d191fe12e75 100644
---
a/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/ShowShardingTableRulesUsedAuditorResultSetTest.java
+++
b/features/sharding/distsql/handler/src/test/java/org/apache/shardingsphere/sharding/distsql/query/ShowShardingTableRulesUsedAuditorExecutorTest.java
@@ -17,8 +17,9 @@
package org.apache.shardingsphere.sharding.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.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.sharding.api.config.ShardingRuleConfiguration;
@@ -27,16 +28,16 @@ import
org.apache.shardingsphere.sharding.api.config.rule.ShardingTableRuleConfi
import
org.apache.shardingsphere.sharding.api.config.strategy.audit.ShardingAuditStrategyConfiguration;
import
org.apache.shardingsphere.sharding.api.config.strategy.sharding.NoneShardingStrategyConfiguration;
import
org.apache.shardingsphere.sharding.api.config.strategy.sharding.StandardShardingStrategyConfiguration;
-import
org.apache.shardingsphere.sharding.distsql.handler.query.ShardingTableRulesUsedAuditorResultSet;
+import
org.apache.shardingsphere.sharding.distsql.handler.query.ShowShardingTableRulesUsedAuditorExecutor;
import
org.apache.shardingsphere.sharding.distsql.parser.statement.ShowShardingTableRulesUsedAuditorStatement;
import org.apache.shardingsphere.sharding.rule.ShardingRule;
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 java.util.Optional;
import java.util.Properties;
@@ -46,7 +47,7 @@ import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
-public final class ShowShardingTableRulesUsedAuditorResultSetTest {
+public final class ShowShardingTableRulesUsedAuditorExecutorTest {
@Test
public void assertGetRowData() {
@@ -54,18 +55,28 @@ public final class
ShowShardingTableRulesUsedAuditorResultSetTest {
ShardingRule rule = mock(ShardingRule.class);
when(rule.getConfiguration()).thenReturn(createRuleConfiguration());
when(database.getRuleMetaData()).thenReturn(new
ShardingSphereRuleMetaData(Collections.singleton(rule)));
- DatabaseDistSQLResultSet resultSet = new
ShardingTableRulesUsedAuditorResultSet();
+ RQLExecutor<ShowShardingTableRulesUsedAuditorStatement> executor = new
ShowShardingTableRulesUsedAuditorExecutor();
ShowShardingTableRulesUsedAuditorStatement statement =
mock(ShowShardingTableRulesUsedAuditorStatement.class);
when(statement.getAuditorName()).thenReturn(Optional.of("shardingKeyAudit"));
- resultSet.init(database, statement);
- List<Object> actual = new ArrayList<>(resultSet.getRowData());
+ Collection<LocalDataQueryResultRow> actual =
executor.getRows(database, statement);
assertThat(actual.size(), is(2));
- assertThat(actual.get(0), is("table"));
- assertThat(actual.get(1), is("t_order"));
- actual = new ArrayList<>(resultSet.getRowData());
- assertThat(actual.size(), is(2));
- assertThat(actual.get(0), is("auto_table"));
- assertThat(actual.get(1), is("t_order_auto"));
+ Iterator<LocalDataQueryResultRow> iterator = actual.iterator();
+ LocalDataQueryResultRow row = iterator.next();
+ assertThat(row.getCell(1), is("table"));
+ assertThat(row.getCell(2), is("t_order"));
+ row = iterator.next();
+ assertThat(row.getCell(1), is("auto_table"));
+ assertThat(row.getCell(2), is("t_order_auto"));
+ }
+
+ @Test
+ public void assertGetColumnNames() {
+ RQLExecutor<ShowShardingTableRulesUsedAuditorStatement> executor = new
ShowShardingTableRulesUsedAuditorExecutor();
+ Collection<String> columns = executor.getColumnNames();
+ assertThat(columns.size(), is(2));
+ Iterator<String> iterator = columns.iterator();
+ assertThat(iterator.next(), is("type"));
+ assertThat(iterator.next(), is("name"));
}
private ShardingRuleConfiguration createRuleConfiguration() {
diff --git
a/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rql/ShowDefaultSingleTableStorageUnitExecutorTest.java
b/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rql/ShowDefaultSingleTableStorageUnitExecutorTest.java
index 5c79183423b..78a1d7017ce 100644
---
a/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rql/ShowDefaultSingleTableStorageUnitExecutorTest.java
+++
b/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rql/ShowDefaultSingleTableStorageUnitExecutorTest.java
@@ -41,7 +41,6 @@ public final class
ShowDefaultSingleTableStorageUnitExecutorTest {
@Test
public void assertGetRowData() {
RQLExecutor<ShowDefaultSingleTableStorageUnitStatement> executor = new
ShowDefaultSingleTableStorageUnitExecutor();
- executor.getRows(mockDatabase(),
mock(ShowDefaultSingleTableStorageUnitStatement.class));
Collection<LocalDataQueryResultRow> actual =
executor.getRows(mockDatabase(),
mock(ShowDefaultSingleTableStorageUnitStatement.class));
assertThat(actual.size(), is(1));
Iterator<LocalDataQueryResultRow> rowData = actual.iterator();
diff --git
a/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rql/ShowSingleTableExecutorTest.java
b/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rql/ShowSingleTableExecutorTest.java
index 2112ee7c157..e32e8553bf6 100644
---
a/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rql/ShowSingleTableExecutorTest.java
+++
b/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rql/ShowSingleTableExecutorTest.java
@@ -65,7 +65,6 @@ public final class ShowSingleTableExecutorTest {
@Test
public void assertGetRowData() {
RQLExecutor<ShowSingleTableStatement> executor = new
ShowSingleTableExecutor();
- executor.getRows(database, mock(ShowSingleTableStatement.class));
Collection<LocalDataQueryResultRow> actual =
executor.getRows(database, mock(ShowSingleTableStatement.class));
assertThat(actual.size(), is(2));
Iterator<LocalDataQueryResultRow> rowData = actual.iterator();
diff --git
a/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rql/ShowStorageUnitExecutorTest.java
b/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rql/ShowStorageUnitExecutorTest.java
index f76420eea98..d88769f4866 100644
---
a/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rql/ShowStorageUnitExecutorTest.java
+++
b/proxy/backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/rql/ShowStorageUnitExecutorTest.java
@@ -136,7 +136,6 @@ public final class ShowStorageUnitExecutorTest {
public void assertUnusedStorageUnit() {
RQLExecutor<ShowStorageUnitsStatement> executor = new
ShowStorageUnitExecutor();
ShowStorageUnitsStatement showStorageUnitsStatement = new
ShowStorageUnitsStatement(mock(DatabaseSegment.class), 0);
- executor.getRows(database, showStorageUnitsStatement);
Collection<LocalDataQueryResultRow> actual =
executor.getRows(database, showStorageUnitsStatement);
assertThat(actual.size(), is(1));
Iterator<LocalDataQueryResultRow> rowData = actual.iterator();