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 84ed4801bb9 Refactor RQLExecutor's impl (#29741)
84ed4801bb9 is described below
commit 84ed4801bb99391f880b075d52d73d2d05bd1152
Author: Liang Zhang <[email protected]>
AuthorDate: Wed Jan 17 10:09:30 2024 +0800
Refactor RQLExecutor's impl (#29741)
* Refactor ShowDefaultShadowAlgorithmExecutor
* Refactor ShowDefaultShadowAlgorithmExecutor
* Refactor ShowShadowAlgorithmsExecutor
* Refactor ShowShardingTableRuleExecutor
* Refactor ShowUnusedShardingAlgorithmsExecutor
* Refactor ShowUnusedShardingAlgorithmsExecutor
* Refactor ShowUnusedShardingAlgorithmsExecutor
---
.../query/ShowDefaultShadowAlgorithmExecutor.java | 11 +++--------
.../handler/query/ShowShadowAlgorithmsExecutor.java | 16 +++++-----------
.../query/ShowShardingTableRuleExecutor.java | 21 ++++++++++-----------
.../query/ShowUnusedShardingAlgorithmsExecutor.java | 10 +++++-----
.../query/ShowUnusedShardingAuditorsExecutor.java | 13 +++----------
.../ShowUnusedShardingKeyGeneratorExecutor.java | 8 ++++----
.../test/e2e/cases/value/SQLValue.java | 2 +-
7 files changed, 31 insertions(+), 50 deletions(-)
diff --git
a/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/query/ShowDefaultShadowAlgorithmExecutor.java
b/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/query/ShowDefaultShadowAlgorithmExecutor.java
index 5f07f8db756..7fb4473134e 100644
---
a/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/query/ShowDefaultShadowAlgorithmExecutor.java
+++
b/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/query/ShowDefaultShadowAlgorithmExecutor.java
@@ -22,13 +22,11 @@ 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.props.PropertiesConverter;
-import org.apache.shardingsphere.shadow.api.config.ShadowRuleConfiguration;
import
org.apache.shardingsphere.shadow.distsql.statement.ShowDefaultShadowAlgorithmStatement;
import org.apache.shardingsphere.shadow.rule.ShadowRule;
import java.util.Arrays;
import java.util.Collection;
-import java.util.Iterator;
import java.util.LinkedList;
import java.util.Map.Entry;
import java.util.Properties;
@@ -50,13 +48,10 @@ public final class ShowDefaultShadowAlgorithmExecutor
extends RuleAwareRQLExecut
@Override
public Collection<LocalDataQueryResultRow> getRows(final
ShardingSphereDatabase database, final ShowDefaultShadowAlgorithmStatement
sqlStatement, final ShadowRule rule) {
- ShadowRuleConfiguration config = rule.getConfiguration();
- String defaultAlgorithm = config.getDefaultShadowAlgorithmName();
- Iterator<Entry<String, AlgorithmConfiguration>> data =
config.getShadowAlgorithms().entrySet().stream().filter(each ->
each.getKey().equals(defaultAlgorithm))
- .collect(Collectors.toMap(Entry::getKey,
Entry::getValue)).entrySet().iterator();
+ String defaultAlgorithm =
rule.getConfiguration().getDefaultShadowAlgorithmName();
Collection<LocalDataQueryResultRow> result = new LinkedList<>();
- while (data.hasNext()) {
- Entry<String, AlgorithmConfiguration> entry = data.next();
+ for (Entry<String, AlgorithmConfiguration> entry :
rule.getConfiguration().getShadowAlgorithms().entrySet().stream()
+ .filter(each ->
each.getKey().equals(defaultAlgorithm)).collect(Collectors.toMap(Entry::getKey,
Entry::getValue)).entrySet()) {
result.add(new LocalDataQueryResultRow(entry.getKey(),
entry.getValue().getType(), convertToString(entry.getValue().getProps())));
}
return result;
diff --git
a/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/query/ShowShadowAlgorithmsExecutor.java
b/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/query/ShowShadowAlgorithmsExecutor.java
index 252349afa04..69609153db8 100644
---
a/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/query/ShowShadowAlgorithmsExecutor.java
+++
b/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/query/ShowShadowAlgorithmsExecutor.java
@@ -18,7 +18,6 @@
package org.apache.shardingsphere.shadow.distsql.handler.query;
import
org.apache.shardingsphere.distsql.handler.type.rql.rule.RuleAwareRQLExecutor;
-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.props.PropertiesConverter;
@@ -27,10 +26,8 @@ import org.apache.shardingsphere.shadow.rule.ShadowRule;
import java.util.Arrays;
import java.util.Collection;
-import java.util.Iterator;
-import java.util.LinkedList;
-import java.util.Map.Entry;
import java.util.Properties;
+import java.util.stream.Collectors;
/**
* Show shadow algorithms executor.
@@ -48,14 +45,11 @@ public final class ShowShadowAlgorithmsExecutor extends
RuleAwareRQLExecutor<Sho
@Override
public Collection<LocalDataQueryResultRow> getRows(final
ShardingSphereDatabase database, final ShowShadowAlgorithmsStatement
sqlStatement, final ShadowRule rule) {
- Iterator<Entry<String, AlgorithmConfiguration>> data =
rule.getConfiguration().getShadowAlgorithms().entrySet().iterator();
String defaultAlgorithm =
rule.getConfiguration().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.toString(row.getKey().equals(defaultAlgorithm))));
- }
- return result;
+ return
rule.getConfiguration().getShadowAlgorithms().entrySet().stream()
+ .map(entry -> new LocalDataQueryResultRow(entry.getKey(),
entry.getValue().getType(),
+ convertToString(entry.getValue().getProps()),
Boolean.toString(entry.getKey().equals(defaultAlgorithm))))
+ .collect(Collectors.toList());
}
private String convertToString(final Properties props) {
diff --git
a/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/query/ShowShardingTableRuleExecutor.java
b/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/query/ShowShardingTableRuleExecutor.java
index c4d83754856..9b6fe94407a 100644
---
a/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/query/ShowShardingTableRuleExecutor.java
+++
b/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/query/ShowShardingTableRuleExecutor.java
@@ -36,7 +36,6 @@ import org.apache.shardingsphere.sharding.rule.ShardingRule;
import java.util.Arrays;
import java.util.Collection;
-import java.util.Iterator;
import java.util.LinkedList;
import java.util.Optional;
import java.util.stream.Collectors;
@@ -60,21 +59,21 @@ public final class ShowShardingTableRuleExecutor extends
RuleAwareRQLExecutor<Sh
@Override
public Collection<LocalDataQueryResultRow> getRows(final
ShardingSphereDatabase database, final ShowShardingTableRulesStatement
sqlStatement, final ShardingRule rule) {
String tableName = sqlStatement.getTableName();
- Iterator<ShardingTableRuleConfiguration> tables;
- Iterator<ShardingAutoTableRuleConfiguration> autoTables;
+ Collection<ShardingTableRuleConfiguration> tables;
+ Collection<ShardingAutoTableRuleConfiguration> autoTables;
if (null == tableName) {
- tables = rule.getConfiguration().getTables().iterator();
- autoTables = rule.getConfiguration().getAutoTables().iterator();
+ tables = rule.getConfiguration().getTables();
+ autoTables = rule.getConfiguration().getAutoTables();
} else {
- tables = rule.getConfiguration().getTables().stream().filter(each
->
tableName.equalsIgnoreCase(each.getLogicTable())).collect(Collectors.toList()).iterator();
- autoTables =
rule.getConfiguration().getAutoTables().stream().filter(each ->
tableName.equalsIgnoreCase(each.getLogicTable())).collect(Collectors.toList()).iterator();
+ tables = rule.getConfiguration().getTables().stream().filter(each
->
tableName.equalsIgnoreCase(each.getLogicTable())).collect(Collectors.toList());
+ autoTables =
rule.getConfiguration().getAutoTables().stream().filter(each ->
tableName.equalsIgnoreCase(each.getLogicTable())).collect(Collectors.toList());
}
Collection<LocalDataQueryResultRow> result = new LinkedList<>();
- while (tables.hasNext()) {
- result.add(buildTableRowData(rule.getConfiguration(),
tables.next()));
+ for (ShardingTableRuleConfiguration each : tables) {
+ result.add(buildTableRowData(rule.getConfiguration(), each));
}
- while (autoTables.hasNext()) {
- result.add(buildAutoTableRowData(rule.getConfiguration(),
autoTables.next()));
+ for (ShardingAutoTableRuleConfiguration each : autoTables) {
+ result.add(buildAutoTableRowData(rule.getConfiguration(), each));
}
return result;
}
diff --git
a/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/query/ShowUnusedShardingAlgorithmsExecutor.java
b/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/query/ShowUnusedShardingAlgorithmsExecutor.java
index 90a66a5f9c2..36478d44e7e 100644
---
a/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/query/ShowUnusedShardingAlgorithmsExecutor.java
+++
b/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/query/ShowUnusedShardingAlgorithmsExecutor.java
@@ -44,6 +44,11 @@ public final class ShowUnusedShardingAlgorithmsExecutor
extends RuleAwareRQLExec
super(ShardingRule.class);
}
+ @Override
+ public Collection<String> getColumnNames() {
+ return Arrays.asList("name", "type", "props");
+ }
+
@Override
public Collection<LocalDataQueryResultRow> getRows(final
ShardingSphereDatabase database, final ShowUnusedShardingAlgorithmsStatement
sqlStatement, final ShardingRule rule) {
ShardingRuleConfiguration shardingRuleConfig = rule.getConfiguration();
@@ -79,11 +84,6 @@ public final class ShowUnusedShardingAlgorithmsExecutor
extends RuleAwareRQLExec
return result;
}
- @Override
- public Collection<String> getColumnNames() {
- return Arrays.asList("name", "type", "props");
- }
-
private String buildProps(final Properties props) {
return null == props ? "" : PropertiesConverter.convert(props);
}
diff --git
a/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/query/ShowUnusedShardingAuditorsExecutor.java
b/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/query/ShowUnusedShardingAuditorsExecutor.java
index 7ab3e7fe0b7..cdf2bf6b9e9 100644
---
a/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/query/ShowUnusedShardingAuditorsExecutor.java
+++
b/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/query/ShowUnusedShardingAuditorsExecutor.java
@@ -18,7 +18,6 @@
package org.apache.shardingsphere.sharding.distsql.handler.query;
import
org.apache.shardingsphere.distsql.handler.type.rql.rule.RuleAwareRQLExecutor;
-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.props.PropertiesConverter;
@@ -30,8 +29,7 @@ import org.apache.shardingsphere.sharding.rule.ShardingRule;
import java.util.Arrays;
import java.util.Collection;
import java.util.LinkedHashSet;
-import java.util.LinkedList;
-import java.util.Map.Entry;
+import java.util.stream.Collectors;
/**
* Show unused sharding auditors executor.
@@ -51,13 +49,8 @@ public final class ShowUnusedShardingAuditorsExecutor
extends RuleAwareRQLExecut
public Collection<LocalDataQueryResultRow> getRows(final
ShardingSphereDatabase database, final ShowUnusedShardingAuditorsStatement
sqlStatement, final ShardingRule rule) {
ShardingRuleConfiguration shardingRuleConfig = rule.getConfiguration();
Collection<String> inUsedAuditors =
getUsedAuditors(shardingRuleConfig);
- Collection<LocalDataQueryResultRow> result = new LinkedList<>();
- for (Entry<String, AlgorithmConfiguration> entry :
shardingRuleConfig.getAuditors().entrySet()) {
- if (!inUsedAuditors.contains(entry.getKey())) {
- result.add(new LocalDataQueryResultRow(entry.getKey(),
entry.getValue().getType(),
PropertiesConverter.convert(entry.getValue().getProps())));
- }
- }
- return result;
+ return
shardingRuleConfig.getAuditors().entrySet().stream().filter(entry ->
!inUsedAuditors.contains(entry.getKey()))
+ .map(entry -> new LocalDataQueryResultRow(entry.getKey(),
entry.getValue().getType(),
PropertiesConverter.convert(entry.getValue().getProps()))).collect(Collectors.toList());
}
private Collection<String> getUsedAuditors(final ShardingRuleConfiguration
shardingRuleConfig) {
diff --git
a/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/query/ShowUnusedShardingKeyGeneratorExecutor.java
b/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/query/ShowUnusedShardingKeyGeneratorExecutor.java
index bf08310d8d5..203f4948181 100644
---
a/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/query/ShowUnusedShardingKeyGeneratorExecutor.java
+++
b/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/query/ShowUnusedShardingKeyGeneratorExecutor.java
@@ -54,11 +54,11 @@ public final class ShowUnusedShardingKeyGeneratorExecutor
extends RuleAwareRQLEx
.map(entry -> new LocalDataQueryResultRow(entry.getKey(),
entry.getValue().getType(),
buildProps(entry.getValue().getProps()))).collect(Collectors.toList());
}
- private Collection<String> getUsedKeyGenerators(final
ShardingRuleConfiguration shardingRuleConfig) {
+ private Collection<String> getUsedKeyGenerators(final
ShardingRuleConfiguration ruleConfig) {
Collection<String> result = new LinkedHashSet<>();
- shardingRuleConfig.getTables().stream().filter(each -> null !=
each.getKeyGenerateStrategy()).forEach(each ->
result.add(each.getKeyGenerateStrategy().getKeyGeneratorName()));
- shardingRuleConfig.getAutoTables().stream().filter(each -> null !=
each.getKeyGenerateStrategy()).forEach(each ->
result.add(each.getKeyGenerateStrategy().getKeyGeneratorName()));
- KeyGenerateStrategyConfiguration keyGenerateStrategy =
shardingRuleConfig.getDefaultKeyGenerateStrategy();
+ ruleConfig.getTables().stream().filter(each -> null !=
each.getKeyGenerateStrategy()).forEach(each ->
result.add(each.getKeyGenerateStrategy().getKeyGeneratorName()));
+ ruleConfig.getAutoTables().stream().filter(each -> null !=
each.getKeyGenerateStrategy()).forEach(each ->
result.add(each.getKeyGenerateStrategy().getKeyGeneratorName()));
+ KeyGenerateStrategyConfiguration keyGenerateStrategy =
ruleConfig.getDefaultKeyGenerateStrategy();
if (null != keyGenerateStrategy &&
!Strings.isNullOrEmpty(keyGenerateStrategy.getKeyGeneratorName())) {
result.add(keyGenerateStrategy.getKeyGeneratorName());
}
diff --git
a/test/e2e/sql/src/test/java/org/apache/shardingsphere/test/e2e/cases/value/SQLValue.java
b/test/e2e/sql/src/test/java/org/apache/shardingsphere/test/e2e/cases/value/SQLValue.java
index e7ac83c7d56..0a02fde26c1 100644
---
a/test/e2e/sql/src/test/java/org/apache/shardingsphere/test/e2e/cases/value/SQLValue.java
+++
b/test/e2e/sql/src/test/java/org/apache/shardingsphere/test/e2e/cases/value/SQLValue.java
@@ -114,7 +114,7 @@ public final class SQLValue {
return formatString(new String((byte[]) value,
StandardCharsets.UTF_8));
}
if (value instanceof UUID) {
- return formatString(((UUID) value).toString());
+ return formatString(value.toString());
}
return value.toString();
}