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 f8524035b81 Extract public methods (#27575)
f8524035b81 is described below
commit f8524035b81fc6a67b95cb701b5feceb79761f21
Author: yx9o <[email protected]>
AuthorDate: Tue Aug 1 09:08:51 2023 +0800
Extract public methods (#27575)
* Extract public methods
* Update
---
.../handler/constant/EncryptDistSQLConstants.java | 6 ---
.../EncryptConvertRuleConfigurationProvider.java | 34 ---------------
.../handler/constant/MaskDistSQLConstants.java | 6 ---
.../MaskConvertRuleConfigurationProvider.java | 34 ---------------
.../ReadwriteSplittingDistSQLConstants.java | 6 ---
...eSplittingConvertRuleConfigurationProvider.java | 36 +---------------
.../handler/constant/ShadowDistSQLConstants.java | 6 ---
.../ShadowConvertRuleConfigurationProvider.java | 34 ---------------
.../handler/constant/ShardingDistSQLConstants.java | 6 ---
.../ShardingConvertRuleConfigurationProvider.java | 34 ---------------
.../ral/constant/DistSQLScriptConstants.java | 4 ++
.../query/ConvertRuleConfigurationProvider.java | 50 ++++++++++++++++++++++
12 files changed, 55 insertions(+), 201 deletions(-)
diff --git
a/features/encrypt/distsql/handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/constant/EncryptDistSQLConstants.java
b/features/encrypt/distsql/handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/constant/EncryptDistSQLConstants.java
index d914d27d1c4..0f638c7e2b4 100644
---
a/features/encrypt/distsql/handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/constant/EncryptDistSQLConstants.java
+++
b/features/encrypt/distsql/handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/constant/EncryptDistSQLConstants.java
@@ -30,8 +30,6 @@ public final class EncryptDistSQLConstants {
public static final String SEMI = ";";
- public static final String PROPERTY = "'%s'='%s'";
-
public static final String CREATE_ENCRYPT = "CREATE ENCRYPT RULE";
public static final String ENCRYPT = " %s ("
@@ -55,8 +53,4 @@ public final class EncryptDistSQLConstants {
public static final String ASSISTED_QUERY_ALGORITHM =
"ASSISTED_QUERY_ALGORITHM(%s)";
public static final String LIKE_QUERY_ALGORITHM =
"LIKE_QUERY_ALGORITHM(%s)";
-
- public static final String ALGORITHM_TYPE = "TYPE(NAME='%s',
PROPERTIES(%s))";
-
- public static final String ALGORITHM_TYPE_WITHOUT_PROPS =
"TYPE(NAME='%s')";
}
diff --git
a/features/encrypt/distsql/handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/provider/EncryptConvertRuleConfigurationProvider.java
b/features/encrypt/distsql/handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/provider/EncryptConvertRuleConfigurationProvider.java
index ca3a30194f2..56a5565aa66 100644
---
a/features/encrypt/distsql/handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/provider/EncryptConvertRuleConfigurationProvider.java
+++
b/features/encrypt/distsql/handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/provider/EncryptConvertRuleConfigurationProvider.java
@@ -30,8 +30,6 @@ import
org.apache.shardingsphere.infra.config.rule.RuleConfiguration;
import java.util.Collection;
import java.util.Iterator;
import java.util.Map;
-import java.util.Properties;
-import java.util.TreeMap;
/**
* Encrypt convert rule configuration provider.
@@ -106,38 +104,6 @@ public final class EncryptConvertRuleConfigurationProvider
implements ConvertRul
return result.toString();
}
- private String getAlgorithmType(final AlgorithmConfiguration
algorithmConfig) {
- StringBuilder result = new StringBuilder();
- if (null == algorithmConfig) {
- return result.toString();
- }
- String type = algorithmConfig.getType().toLowerCase();
- if (algorithmConfig.getProps().isEmpty()) {
-
result.append(String.format(EncryptDistSQLConstants.ALGORITHM_TYPE_WITHOUT_PROPS,
type));
- } else {
-
result.append(String.format(EncryptDistSQLConstants.ALGORITHM_TYPE, type,
getAlgorithmProperties(algorithmConfig.getProps())));
- }
- return result.toString();
- }
-
- @SuppressWarnings({"unchecked", "rawtypes"})
- private String getAlgorithmProperties(final Properties props) {
- StringBuilder result = new StringBuilder();
- Iterator<String> iterator = new TreeMap(props).keySet().iterator();
- while (iterator.hasNext()) {
- String key = iterator.next();
- Object value = props.get(key);
- if (null == value) {
- continue;
- }
- result.append(String.format(EncryptDistSQLConstants.PROPERTY, key,
value));
- if (iterator.hasNext()) {
- result.append(EncryptDistSQLConstants.COMMA).append(' ');
- }
- }
- return result.toString();
- }
-
@Override
public String getType() {
return EncryptRuleConfiguration.class.getName();
diff --git
a/features/mask/distsql/handler/src/main/java/org/apache/shardingsphere/mask/distsql/handler/constant/MaskDistSQLConstants.java
b/features/mask/distsql/handler/src/main/java/org/apache/shardingsphere/mask/distsql/handler/constant/MaskDistSQLConstants.java
index 76ed63164e0..d945ffb44f9 100644
---
a/features/mask/distsql/handler/src/main/java/org/apache/shardingsphere/mask/distsql/handler/constant/MaskDistSQLConstants.java
+++
b/features/mask/distsql/handler/src/main/java/org/apache/shardingsphere/mask/distsql/handler/constant/MaskDistSQLConstants.java
@@ -30,12 +30,6 @@ public final class MaskDistSQLConstants {
public static final String SEMI = ";";
- public static final String PROPERTY = "'%s'='%s'";
-
- public static final String ALGORITHM_TYPE = "TYPE(NAME='%s',
PROPERTIES(%s))";
-
- public static final String ALGORITHM_TYPE_WITHOUT_PROPS =
"TYPE(NAME='%s')";
-
public static final String CREATE_MASK = "CREATE MASK RULE";
public static final String MASK = " %s ("
diff --git
a/features/mask/distsql/handler/src/main/java/org/apache/shardingsphere/mask/distsql/handler/provider/MaskConvertRuleConfigurationProvider.java
b/features/mask/distsql/handler/src/main/java/org/apache/shardingsphere/mask/distsql/handler/provider/MaskConvertRuleConfigurationProvider.java
index 2263303d8a1..4e070b82528 100644
---
a/features/mask/distsql/handler/src/main/java/org/apache/shardingsphere/mask/distsql/handler/provider/MaskConvertRuleConfigurationProvider.java
+++
b/features/mask/distsql/handler/src/main/java/org/apache/shardingsphere/mask/distsql/handler/provider/MaskConvertRuleConfigurationProvider.java
@@ -28,8 +28,6 @@ import
org.apache.shardingsphere.mask.distsql.handler.constant.MaskDistSQLConsta
import java.util.Collection;
import java.util.Iterator;
import java.util.Map;
-import java.util.Properties;
-import java.util.TreeMap;
/**
* Mask convert rule configuration provider.
@@ -72,38 +70,6 @@ public final class MaskConvertRuleConfigurationProvider
implements ConvertRuleCo
return
getAlgorithmType(maskAlgorithms.get(columnRuleConfig.getMaskAlgorithm()));
}
- private String getAlgorithmType(final AlgorithmConfiguration
algorithmConfig) {
- StringBuilder result = new StringBuilder();
- if (null == algorithmConfig) {
- return result.toString();
- }
- String type = algorithmConfig.getType().toLowerCase();
- if (algorithmConfig.getProps().isEmpty()) {
-
result.append(String.format(MaskDistSQLConstants.ALGORITHM_TYPE_WITHOUT_PROPS,
type));
- } else {
- result.append(String.format(MaskDistSQLConstants.ALGORITHM_TYPE,
type, getAlgorithmProperties(algorithmConfig.getProps())));
- }
- return result.toString();
- }
-
- @SuppressWarnings({"unchecked", "rawtypes"})
- private String getAlgorithmProperties(final Properties props) {
- StringBuilder result = new StringBuilder();
- Iterator<String> iterator = new TreeMap(props).keySet().iterator();
- while (iterator.hasNext()) {
- String key = iterator.next();
- Object value = props.get(key);
- if (null == value) {
- continue;
- }
- result.append(String.format(MaskDistSQLConstants.PROPERTY, key,
value));
- if (iterator.hasNext()) {
- result.append(MaskDistSQLConstants.COMMA).append(' ');
- }
- }
- return result.toString();
- }
-
@Override
public String getType() {
return MaskRuleConfiguration.class.getName();
diff --git
a/features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/constant/ReadwriteSplittingDistSQLConstants.java
b/features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/constant/ReadwriteSplittingDistSQLConstants.java
index a1c73613b14..4a022b9e7cb 100644
---
a/features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/constant/ReadwriteSplittingDistSQLConstants.java
+++
b/features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/constant/ReadwriteSplittingDistSQLConstants.java
@@ -30,8 +30,6 @@ public final class ReadwriteSplittingDistSQLConstants {
public static final String SEMI = ";";
- public static final String PROPERTY = "'%s'='%s'";
-
public static final String CREATE_READWRITE_SPLITTING_RULE = "CREATE
READWRITE_SPLITTING RULE";
public static final String READWRITE_SPLITTING_FOR_STATIC = " %s ("
@@ -45,8 +43,4 @@ public final class ReadwriteSplittingDistSQLConstants {
+ ")";
public static final String READ_RESOURCE = "%s";
-
- public static final String ALGORITHM_TYPE = "TYPE(NAME='%s',
PROPERTIES(%s))";
-
- public static final String ALGORITHM_TYPE_WITHOUT_PROPS =
"TYPE(NAME='%s')";
}
diff --git
a/features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/provider/ReadwriteSplittingConvertRuleConfigurationProvider.java
b/features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/provider/ReadwriteSplittingConvertRuleConfigurationProvider.java
index d80e1631e5a..90192786423 100644
---
a/features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/provider/ReadwriteSplittingConvertRuleConfigurationProvider.java
+++
b/features/readwrite-splitting/distsql/handler/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/handler/provider/ReadwriteSplittingConvertRuleConfigurationProvider.java
@@ -22,14 +22,12 @@ import
org.apache.shardingsphere.distsql.handler.ral.query.ConvertRuleConfigurat
import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
import org.apache.shardingsphere.infra.config.rule.RuleConfiguration;
import
org.apache.shardingsphere.readwritesplitting.api.ReadwriteSplittingRuleConfiguration;
-import
org.apache.shardingsphere.readwritesplitting.distsql.handler.constant.ReadwriteSplittingDistSQLConstants;
import
org.apache.shardingsphere.readwritesplitting.api.rule.ReadwriteSplittingDataSourceRuleConfiguration;
+import
org.apache.shardingsphere.readwritesplitting.distsql.handler.constant.ReadwriteSplittingDistSQLConstants;
import java.util.Collection;
import java.util.Iterator;
import java.util.Map;
-import java.util.Properties;
-import java.util.TreeMap;
/**
* Readwrite-splitting convert rule configuration provider.
@@ -87,38 +85,6 @@ public final class
ReadwriteSplittingConvertRuleConfigurationProvider implements
return result.toString();
}
- private String getAlgorithmType(final AlgorithmConfiguration
algorithmConfig) {
- StringBuilder result = new StringBuilder();
- if (null == algorithmConfig) {
- return result.toString();
- }
- String type = algorithmConfig.getType().toLowerCase();
- if (algorithmConfig.getProps().isEmpty()) {
-
result.append(String.format(ReadwriteSplittingDistSQLConstants.ALGORITHM_TYPE_WITHOUT_PROPS,
type));
- } else {
-
result.append(String.format(ReadwriteSplittingDistSQLConstants.ALGORITHM_TYPE,
type, getAlgorithmProperties(algorithmConfig.getProps())));
- }
- return result.toString();
- }
-
- @SuppressWarnings({"unchecked", "rawtypes"})
- private String getAlgorithmProperties(final Properties props) {
- StringBuilder result = new StringBuilder();
- Iterator<String> iterator = new TreeMap(props).keySet().iterator();
- while (iterator.hasNext()) {
- String key = iterator.next();
- Object value = props.get(key);
- if (null == value) {
- continue;
- }
-
result.append(String.format(ReadwriteSplittingDistSQLConstants.PROPERTY, key,
value));
- if (iterator.hasNext()) {
-
result.append(ReadwriteSplittingDistSQLConstants.COMMA).append(' ');
- }
- }
- return result.toString();
- }
-
@Override
public String getType() {
return ReadwriteSplittingRuleConfiguration.class.getName();
diff --git
a/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/constant/ShadowDistSQLConstants.java
b/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/constant/ShadowDistSQLConstants.java
index 1dfcc993789..dec7d424cf1 100644
---
a/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/constant/ShadowDistSQLConstants.java
+++
b/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/constant/ShadowDistSQLConstants.java
@@ -30,12 +30,6 @@ public final class ShadowDistSQLConstants {
public static final String SEMI = ";";
- public static final String PROPERTY = "'%s'='%s'";
-
- public static final String ALGORITHM_TYPE = "TYPE(NAME='%s',
PROPERTIES(%s))";
-
- public static final String ALGORITHM_TYPE_WITHOUT_PROPS =
"TYPE(NAME='%s')";
-
public static final String CREATE_SHADOW = "CREATE SHADOW RULE";
public static final String SHADOW = " %s("
diff --git
a/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/provider/ShadowConvertRuleConfigurationProvider.java
b/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/provider/ShadowConvertRuleConfigurationProvider.java
index 207e34654e8..b557b26a3a8 100644
---
a/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/provider/ShadowConvertRuleConfigurationProvider.java
+++
b/features/shadow/distsql/handler/src/main/java/org/apache/shardingsphere/shadow/distsql/handler/provider/ShadowConvertRuleConfigurationProvider.java
@@ -28,8 +28,6 @@ import
org.apache.shardingsphere.shadow.distsql.handler.constant.ShadowDistSQLCo
import java.util.Collection;
import java.util.Iterator;
import java.util.Map;
-import java.util.Properties;
-import java.util.TreeMap;
/**
* Shadow convert rule configuration provider.
@@ -88,38 +86,6 @@ public final class ShadowConvertRuleConfigurationProvider
implements ConvertRule
return result.toString();
}
- private String getAlgorithmType(final AlgorithmConfiguration
algorithmConfig) {
- StringBuilder result = new StringBuilder();
- if (null == algorithmConfig) {
- return result.toString();
- }
- String type = algorithmConfig.getType().toLowerCase();
- if (algorithmConfig.getProps().isEmpty()) {
-
result.append(String.format(ShadowDistSQLConstants.ALGORITHM_TYPE_WITHOUT_PROPS,
type));
- } else {
- result.append(String.format(ShadowDistSQLConstants.ALGORITHM_TYPE,
type, getAlgorithmProperties(algorithmConfig.getProps())));
- }
- return result.toString();
- }
-
- @SuppressWarnings({"unchecked", "rawtypes"})
- private String getAlgorithmProperties(final Properties props) {
- StringBuilder result = new StringBuilder();
- Iterator<String> iterator = new TreeMap(props).keySet().iterator();
- while (iterator.hasNext()) {
- String key = iterator.next();
- Object value = props.get(key);
- if (null == value) {
- continue;
- }
- result.append(String.format(ShadowDistSQLConstants.PROPERTY, key,
value));
- if (iterator.hasNext()) {
- result.append(ShadowDistSQLConstants.COMMA).append(' ');
- }
- }
- return result.toString();
- }
-
@Override
public String getType() {
return ShadowRuleConfiguration.class.getName();
diff --git
a/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/constant/ShardingDistSQLConstants.java
b/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/constant/ShardingDistSQLConstants.java
index ed106445407..d0a3f03ecca 100644
---
a/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/constant/ShardingDistSQLConstants.java
+++
b/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/constant/ShardingDistSQLConstants.java
@@ -38,8 +38,6 @@ public final class ShardingDistSQLConstants {
public static final String SEMI = ";";
- public static final String PROPERTY = "'%s'='%s'";
-
public static final String CREATE_SHARDING_TABLE = "CREATE SHARDING TABLE
RULE";
public static final String SHARDING_TABLE = " %s ("
@@ -91,8 +89,4 @@ public final class ShardingDistSQLConstants {
public static final String DEFAULT_DATABASE_STRATEGY = "CREATE DEFAULT
SHARDING DATABASE STRATEGY";
public static final String DEFAULT_TABLE_STRATEGY = "CREATE DEFAULT
SHARDING TABLE STRATEGY";
-
- public static final String ALGORITHM_TYPE = "TYPE(NAME='%s',
PROPERTIES(%s))";
-
- public static final String ALGORITHM_TYPE_WITHOUT_PROPS =
"TYPE(NAME='%s')";
}
diff --git
a/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/provider/ShardingConvertRuleConfigurationProvider.java
b/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/provider/ShardingConvertRuleConfigurationProvider.java
index 84f3c2936ce..53b10d5fddd 100644
---
a/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/provider/ShardingConvertRuleConfigurationProvider.java
+++
b/features/sharding/distsql/handler/src/main/java/org/apache/shardingsphere/sharding/distsql/handler/provider/ShardingConvertRuleConfigurationProvider.java
@@ -36,8 +36,6 @@ import java.util.Collection;
import java.util.Iterator;
import java.util.Map;
import java.util.Objects;
-import java.util.Properties;
-import java.util.TreeMap;
/**
* Sharding convert rule configuration provider.
@@ -195,20 +193,6 @@ public final class
ShardingConvertRuleConfigurationProvider implements ConvertRu
}
}
- private String getAlgorithmType(final AlgorithmConfiguration
algorithmConfig) {
- StringBuilder result = new StringBuilder();
- if (null == algorithmConfig) {
- return result.toString();
- }
- String type = algorithmConfig.getType().toLowerCase();
- if (algorithmConfig.getProps().isEmpty()) {
-
result.append(String.format(ShardingDistSQLConstants.ALGORITHM_TYPE_WITHOUT_PROPS,
type));
- } else {
-
result.append(String.format(ShardingDistSQLConstants.ALGORITHM_TYPE, type,
getAlgorithmProperties(algorithmConfig.getProps())));
- }
- return result.toString();
- }
-
private String getAlgorithmTypes(final Map<String, AlgorithmConfiguration>
auditors, final Collection<String> auditorNames) {
StringBuilder result = new StringBuilder();
if (!auditorNames.isEmpty()) {
@@ -223,24 +207,6 @@ public final class
ShardingConvertRuleConfigurationProvider implements ConvertRu
return result.toString();
}
- @SuppressWarnings({"unchecked", "rawtypes"})
- private String getAlgorithmProperties(final Properties props) {
- StringBuilder result = new StringBuilder();
- Iterator<String> iterator = new TreeMap(props).keySet().iterator();
- while (iterator.hasNext()) {
- String key = iterator.next();
- Object value = props.get(key);
- if (null == value) {
- continue;
- }
- result.append(String.format(ShardingDistSQLConstants.PROPERTY,
key, value));
- if (iterator.hasNext()) {
- result.append(ShardingDistSQLConstants.COMMA).append(' ');
- }
- }
- return result.toString();
- }
-
@Override
public String getType() {
return ShardingRuleConfiguration.class.getName();
diff --git
a/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/ral/constant/DistSQLScriptConstants.java
b/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/ral/constant/DistSQLScriptConstants.java
index 711acccf4c4..b2bc0ad7e93 100644
---
a/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/ral/constant/DistSQLScriptConstants.java
+++
b/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/ral/constant/DistSQLScriptConstants.java
@@ -64,4 +64,8 @@ public final class DistSQLScriptConstants {
+ ")";
public static final String PROPERTY = "'%s'='%s'";
+
+ public static final String ALGORITHM_TYPE = "TYPE(NAME='%s',
PROPERTIES(%s))";
+
+ public static final String ALGORITHM_TYPE_WITHOUT_PROPS =
"TYPE(NAME='%s')";
}
diff --git
a/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/ral/query/ConvertRuleConfigurationProvider.java
b/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/ral/query/ConvertRuleConfigurationProvider.java
index ebc8b11c72e..2c0a3f1c519 100644
---
a/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/ral/query/ConvertRuleConfigurationProvider.java
+++
b/infra/distsql-handler/src/main/java/org/apache/shardingsphere/distsql/handler/ral/query/ConvertRuleConfigurationProvider.java
@@ -17,10 +17,16 @@
package org.apache.shardingsphere.distsql.handler.ral.query;
+import
org.apache.shardingsphere.distsql.handler.ral.constant.DistSQLScriptConstants;
+import org.apache.shardingsphere.infra.config.algorithm.AlgorithmConfiguration;
import org.apache.shardingsphere.infra.config.rule.RuleConfiguration;
import org.apache.shardingsphere.infra.spi.annotation.SingletonSPI;
import org.apache.shardingsphere.infra.spi.type.typed.TypedSPI;
+import java.util.Iterator;
+import java.util.Properties;
+import java.util.TreeMap;
+
/**
* Convert rule configuration provider.
*/
@@ -34,4 +40,48 @@ public interface ConvertRuleConfigurationProvider extends
TypedSPI {
* @return DistSQL script
*/
String convert(RuleConfiguration ruleConfig);
+
+ /**
+ * Get algorithm type.
+ *
+ * @param algorithmConfig algorithm configuration
+ * @return algorithm type
+ */
+ default String getAlgorithmType(final AlgorithmConfiguration
algorithmConfig) {
+ StringBuilder result = new StringBuilder();
+ if (null == algorithmConfig) {
+ return result.toString();
+ }
+ String type = algorithmConfig.getType().toLowerCase();
+ if (algorithmConfig.getProps().isEmpty()) {
+
result.append(String.format(DistSQLScriptConstants.ALGORITHM_TYPE_WITHOUT_PROPS,
type));
+ } else {
+ result.append(String.format(DistSQLScriptConstants.ALGORITHM_TYPE,
type, getAlgorithmProperties(algorithmConfig.getProps())));
+ }
+ return result.toString();
+ }
+
+ /**
+ * Get algorithm properties.
+ *
+ * @param props properties
+ * @return algorithm properties
+ */
+ @SuppressWarnings({"unchecked", "rawtypes"})
+ default String getAlgorithmProperties(final Properties props) {
+ StringBuilder result = new StringBuilder();
+ Iterator<String> iterator = new TreeMap(props).keySet().iterator();
+ while (iterator.hasNext()) {
+ String key = iterator.next();
+ Object value = props.get(key);
+ if (null == value) {
+ continue;
+ }
+ result.append(String.format(DistSQLScriptConstants.PROPERTY, key,
value));
+ if (iterator.hasNext()) {
+ result.append(DistSQLScriptConstants.COMMA).append(' ');
+ }
+ }
+ return result.toString();
+ }
}