You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by zh...@apache.org on 2022/05/07 07:01:47 UTC
[shardingsphere] branch master updated: Optimize simple hint shadow algorithm (#17408)
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 e0bf7a4afcf Optimize simple hint shadow algorithm (#17408)
e0bf7a4afcf is described below
commit e0bf7a4afcf6bb3c35e4b159f77f39e9a716574d
Author: gin <ja...@163.com>
AuthorDate: Sat May 7 15:01:39 2022 +0800
Optimize simple hint shadow algorithm (#17408)
* Optimize simple hint shadow algorithm
---
.../shadow/hint/SimpleHintShadowAlgorithm.java | 31 ++++++++++++++++++----
1 file changed, 26 insertions(+), 5 deletions(-)
diff --git a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/algorithm/shadow/hint/SimpleHintShadowAlgorithm.java b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/algorithm/shadow/hint/SimpleHintShadowAlgorithm.java
index a794229571f..58ccc00b812 100644
--- a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/algorithm/shadow/hint/SimpleHintShadowAlgorithm.java
+++ b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/algorithm/shadow/hint/SimpleHintShadowAlgorithm.java
@@ -25,23 +25,36 @@ import org.apache.shardingsphere.shadow.api.shadow.hint.HintShadowAlgorithm;
import org.apache.shardingsphere.shadow.api.shadow.hint.PreciseHintShadowValue;
import java.util.Collection;
-import java.util.Objects;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Map.Entry;
import java.util.Properties;
+import java.util.Set;
/**
* Simple hint shadow algorithm.
*/
public final class SimpleHintShadowAlgorithm implements HintShadowAlgorithm<String> {
- // TODO convert to static key, or use HashMap
@Getter
@Setter
private Properties props;
+ private Map<String, String> simpleHint;
+
@Override
public void init(final Properties props) {
checkPropsSize(props);
- this.props = props;
+ simpleHint = initSimpleHint(props);
+ }
+
+ private Map<String, String> initSimpleHint(final Properties props) {
+ Map<String, String> result = new HashMap<>(props.size(), 1.0f);
+ Set<String> strings = props.stringPropertyNames();
+ for (String each : strings) {
+ result.put(each, props.getProperty(each));
+ }
+ return result;
}
private void checkPropsSize(final Properties props) {
@@ -53,8 +66,16 @@ public final class SimpleHintShadowAlgorithm implements HintShadowAlgorithm<Stri
if (ShadowOperationType.HINT_MATCH != noteShadowValue.getShadowOperationType() && !shadowTableNames.contains(noteShadowValue.getLogicTableName())) {
return false;
}
- return ShadowHintExtractor.extractSimpleHint(noteShadowValue.getValue())
- .filter(optional -> props.entrySet().stream().allMatch(entry -> Objects.equals(entry.getValue(), optional.get(String.valueOf(entry.getKey()))))).isPresent();
+ return ShadowHintExtractor.extractSimpleHint(noteShadowValue.getValue()).filter(this::containsHint).isPresent();
+ }
+
+ private boolean containsHint(final Map<String, String> preciseHint) {
+ for (Entry<String, String> entry : simpleHint.entrySet()) {
+ if (!entry.getValue().equals(preciseHint.get(entry.getKey()))) {
+ return false;
+ }
+ }
+ return true;
}
@Override