This is an automated email from the ASF dual-hosted git repository.
zhangliang 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 687c1c9d990 Refactor DistSQL getRows (#29779)
687c1c9d990 is described below
commit 687c1c9d990ea3e86062fd0f1e2c4de0f70d6795
Author: Raigor <[email protected]>
AuthorDate: Fri Jan 19 23:37:53 2024 +0800
Refactor DistSQL getRows (#29779)
---
.../query/ShowEncryptAlgorithmImplementationsExecutor.java | 8 ++------
.../handler/query/ShowMaskAlgorithmImplementationsExecutor.java | 8 ++------
.../ShowReadQueryLoadBalanceAlgorithmImplementationsExecutor.java | 8 ++------
.../handler/query/ShowShadowAlgorithmImplementationsExecutor.java | 8 ++------
.../handler/distsql/ral/queryable/ShowComputeNodesExecutor.java | 2 +-
.../ShowKeyGenerateAlgorithmImplementationsExecutor.java | 8 ++------
6 files changed, 11 insertions(+), 31 deletions(-)
diff --git
a/features/encrypt/distsql/handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/query/ShowEncryptAlgorithmImplementationsExecutor.java
b/features/encrypt/distsql/handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/query/ShowEncryptAlgorithmImplementationsExecutor.java
index db436f05394..ed0fb743196 100644
---
a/features/encrypt/distsql/handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/query/ShowEncryptAlgorithmImplementationsExecutor.java
+++
b/features/encrypt/distsql/handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/query/ShowEncryptAlgorithmImplementationsExecutor.java
@@ -26,7 +26,7 @@ import
org.apache.shardingsphere.infra.spi.ShardingSphereServiceLoader;
import java.util.Arrays;
import java.util.Collection;
-import java.util.LinkedList;
+import java.util.stream.Collectors;
/**
* Show encrypt algorithm implementations executor.
@@ -40,12 +40,8 @@ public final class
ShowEncryptAlgorithmImplementationsExecutor implements Querya
@Override
public Collection<LocalDataQueryResultRow> getRows(final
ShowEncryptAlgorithmImplementationsStatement sqlStatement, final
ShardingSphereMetaData metaData) {
- Collection<LocalDataQueryResultRow> result = new LinkedList<>();
Collection<EncryptAlgorithm> encryptAlgorithms =
ShardingSphereServiceLoader.getServiceInstances(EncryptAlgorithm.class);
- for (EncryptAlgorithm each : encryptAlgorithms) {
- result.add(new
LocalDataQueryResultRow(each.getClass().getSimpleName(), each.getType(),
each.getClass().getName()));
- }
- return result;
+ return encryptAlgorithms.stream().map(each -> new
LocalDataQueryResultRow(each.getClass().getSimpleName(), each.getType(),
each.getClass().getName())).collect(Collectors.toList());
}
@Override
diff --git
a/features/mask/distsql/handler/src/main/java/org/apache/shardingsphere/mask/distsql/handler/query/ShowMaskAlgorithmImplementationsExecutor.java
b/features/mask/distsql/handler/src/main/java/org/apache/shardingsphere/mask/distsql/handler/query/ShowMaskAlgorithmImplementationsExecutor.java
index 05aeed24150..cb375ebbfe1 100644
---
a/features/mask/distsql/handler/src/main/java/org/apache/shardingsphere/mask/distsql/handler/query/ShowMaskAlgorithmImplementationsExecutor.java
+++
b/features/mask/distsql/handler/src/main/java/org/apache/shardingsphere/mask/distsql/handler/query/ShowMaskAlgorithmImplementationsExecutor.java
@@ -26,7 +26,7 @@ import org.apache.shardingsphere.mask.spi.MaskAlgorithm;
import java.util.Arrays;
import java.util.Collection;
-import java.util.LinkedList;
+import java.util.stream.Collectors;
/**
* Show mask algorithm implementations executor.
@@ -41,12 +41,8 @@ public final class ShowMaskAlgorithmImplementationsExecutor
implements Queryable
@SuppressWarnings("rawtypes")
@Override
public Collection<LocalDataQueryResultRow> getRows(final
ShowMaskAlgorithmImplementationsStatement sqlStatement, final
ShardingSphereMetaData metaData) {
- Collection<LocalDataQueryResultRow> result = new LinkedList<>();
Collection<MaskAlgorithm> maskAlgorithms =
ShardingSphereServiceLoader.getServiceInstances(MaskAlgorithm.class);
- for (MaskAlgorithm each : maskAlgorithms) {
- result.add(new
LocalDataQueryResultRow(each.getClass().getSimpleName(), each.getType(),
each.getClass().getName()));
- }
- return result;
+ return maskAlgorithms.stream().map(each -> new
LocalDataQueryResultRow(each.getClass().getSimpleName(), each.getType(),
each.getClass().getName())).collect(Collectors.toList());
}
@Override
diff --git
a/features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/query/ShowReadQueryLoadBalanceAlgorithmImplementationsExecutor.java
b/features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/query/ShowReadQueryLoadBalanceAlgorithmImplementationsExecutor.java
index ec5e8b06829..51fcdf24fd1 100644
---
a/features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/query/ShowReadQueryLoadBalanceAlgorithmImplementationsExecutor.java
+++
b/features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/query/ShowReadQueryLoadBalanceAlgorithmImplementationsExecutor.java
@@ -26,7 +26,7 @@ import
org.apache.shardingsphere.readwritesplitting.spi.ReadQueryLoadBalanceAlgo
import java.util.Arrays;
import java.util.Collection;
-import java.util.LinkedList;
+import java.util.stream.Collectors;
/**
* Show read query load balance algorithm implementations executor.
@@ -40,12 +40,8 @@ public final class
ShowReadQueryLoadBalanceAlgorithmImplementationsExecutor impl
@Override
public Collection<LocalDataQueryResultRow> getRows(final
ShowReadQueryLoadBalanceAlgorithmImplementationsStatement sqlStatement, final
ShardingSphereMetaData metaData) {
- Collection<LocalDataQueryResultRow> result = new LinkedList<>();
Collection<ReadQueryLoadBalanceAlgorithm> loadBalanceAlgorithms =
ShardingSphereServiceLoader.getServiceInstances(ReadQueryLoadBalanceAlgorithm.class);
- for (ReadQueryLoadBalanceAlgorithm each : loadBalanceAlgorithms) {
- result.add(new
LocalDataQueryResultRow(each.getClass().getSimpleName(), each.getType(),
each.getClass().getName()));
- }
- return result;
+ return loadBalanceAlgorithms.stream().map(each -> new
LocalDataQueryResultRow(each.getClass().getSimpleName(), each.getType(),
each.getClass().getName())).collect(Collectors.toList());
}
@Override
diff --git
a/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/query/ShowShadowAlgorithmImplementationsExecutor.java
b/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/query/ShowShadowAlgorithmImplementationsExecutor.java
index 29d9c6cd36f..824919a5970 100644
---
a/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/query/ShowShadowAlgorithmImplementationsExecutor.java
+++
b/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/query/ShowShadowAlgorithmImplementationsExecutor.java
@@ -26,7 +26,7 @@ import org.apache.shardingsphere.shadow.spi.ShadowAlgorithm;
import java.util.Arrays;
import java.util.Collection;
-import java.util.LinkedList;
+import java.util.stream.Collectors;
/**
* Show shadow algorithm implementations executor.
@@ -40,12 +40,8 @@ public final class
ShowShadowAlgorithmImplementationsExecutor implements Queryab
@Override
public Collection<LocalDataQueryResultRow> getRows(final
ShowShadowAlgorithmImplementationsStatement sqlStatement, final
ShardingSphereMetaData metaData) {
- Collection<LocalDataQueryResultRow> result = new LinkedList<>();
Collection<ShadowAlgorithm> shadowAlgorithms =
ShardingSphereServiceLoader.getServiceInstances(ShadowAlgorithm.class);
- for (ShadowAlgorithm each : shadowAlgorithms) {
- result.add(new
LocalDataQueryResultRow(each.getClass().getSimpleName(), each.getType(),
each.getClass().getName()));
- }
- return result;
+ return shadowAlgorithms.stream().map(each -> new
LocalDataQueryResultRow(each.getClass().getSimpleName(), each.getType(),
each.getClass().getName())).collect(Collectors.toList());
}
@Override
diff --git
a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowComputeNodesExecutor.java
b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowComputeNodesExecutor.java
index 36be19981bb..1fbd7b979d9 100644
---
a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowComputeNodesExecutor.java
+++
b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowComputeNodesExecutor.java
@@ -52,7 +52,7 @@ public final class ShowComputeNodesExecutor implements
InstanceContextAwareQuery
return
Collections.singleton(buildRow(instanceContext.getInstance(), modeType));
}
Collection<ComputeNodeInstance> instances =
instanceContext.getAllClusterInstances();
- return instances.isEmpty() ? Collections.emptyList() :
instances.stream().map(each -> buildRow(each,
modeType)).collect(Collectors.toList());
+ return instances.stream().map(each -> buildRow(each,
modeType)).collect(Collectors.toList());
}
private LocalDataQueryResultRow buildRow(final ComputeNodeInstance
instance, final String modeType) {
diff --git
a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowKeyGenerateAlgorithmImplementationsExecutor.java
b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowKeyGenerateAlgorithmImplementationsExecutor.java
index a5b192ed6e8..78c95d4b789 100644
---
a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowKeyGenerateAlgorithmImplementationsExecutor.java
+++
b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowKeyGenerateAlgorithmImplementationsExecutor.java
@@ -26,7 +26,7 @@ import
org.apache.shardingsphere.keygen.core.algorithm.KeyGenerateAlgorithm;
import java.util.Arrays;
import java.util.Collection;
-import java.util.LinkedList;
+import java.util.stream.Collectors;
/**
* Show key generate algorithm implementations executor.
@@ -40,12 +40,8 @@ public final class
ShowKeyGenerateAlgorithmImplementationsExecutor implements Qu
@Override
public Collection<LocalDataQueryResultRow> getRows(final
ShowKeyGenerateAlgorithmImplementationsStatement sqlStatement, final
ShardingSphereMetaData metaData) {
- Collection<LocalDataQueryResultRow> result = new LinkedList<>();
Collection<KeyGenerateAlgorithm> keyGenerateAlgorithms =
ShardingSphereServiceLoader.getServiceInstances(KeyGenerateAlgorithm.class);
- for (KeyGenerateAlgorithm each : keyGenerateAlgorithms) {
- result.add(new
LocalDataQueryResultRow(each.getClass().getSimpleName(), each.getType(),
each.getClass().getName()));
- }
- return result;
+ return keyGenerateAlgorithms.stream().map(each -> new
LocalDataQueryResultRow(each.getClass().getSimpleName(), each.getType(),
each.getClass().getName())).collect(Collectors.toList());
}
@Override