You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by GitBox <gi...@apache.org> on 2022/05/07 03:34:19 UTC

[GitHub] [shardingsphere] soulasuna opened a new pull request, #17408: Optimize simple hint shadow algorithm

soulasuna opened a new pull request, #17408:
URL: https://github.com/apache/shardingsphere/pull/17408

   ## Optimize simple hint shadow algorithm
   
   Changes proposed in this pull request:
   - Optimize simple hint shadow algorithm
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [shardingsphere] terrymanu merged pull request #17408: Optimize simple hint shadow algorithm

Posted by GitBox <gi...@apache.org>.
terrymanu merged PR #17408:
URL: https://github.com/apache/shardingsphere/pull/17408


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [shardingsphere] terrymanu commented on a diff in pull request #17408: Optimize simple hint shadow algorithm

Posted by GitBox <gi...@apache.org>.
terrymanu commented on code in PR #17408:
URL: https://github.com/apache/shardingsphere/pull/17408#discussion_r867313053


##########
shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/algorithm/shadow/hint/SimpleHintShadowAlgorithm.java:
##########
@@ -53,8 +65,17 @@ public boolean isShadow(final Collection<String> shadowTableNames, final Precise
         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 (Map.Entry<String, String> entry : simpleHint.entrySet()) {

Review Comment:
   Please do not use `Map.Entry`, just put Map.Entry into import list



##########
shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/algorithm/shadow/hint/SimpleHintShadowAlgorithm.java:
##########
@@ -53,8 +65,17 @@ public boolean isShadow(final Collection<String> shadowTableNames, final Precise
         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 (Map.Entry<String, String> entry : simpleHint.entrySet()) {
+            if (entry.getValue().equals(preciseHint.get(entry.getKey()))) {
+                continue;

Review Comment:
   It is better to reverse the judge condition and just return here 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [shardingsphere] soulasuna commented on a diff in pull request #17408: Optimize simple hint shadow algorithm

Posted by GitBox <gi...@apache.org>.
soulasuna commented on code in PR #17408:
URL: https://github.com/apache/shardingsphere/pull/17408#discussion_r867313579


##########
shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/algorithm/shadow/hint/SimpleHintShadowAlgorithm.java:
##########
@@ -53,8 +65,17 @@ public boolean isShadow(final Collection<String> shadowTableNames, final Precise
         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 (Map.Entry<String, String> entry : simpleHint.entrySet()) {

Review Comment:
   I will fix it.



##########
shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-core/src/main/java/org/apache/shardingsphere/shadow/algorithm/shadow/hint/SimpleHintShadowAlgorithm.java:
##########
@@ -53,8 +65,17 @@ public boolean isShadow(final Collection<String> shadowTableNames, final Precise
         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 (Map.Entry<String, String> entry : simpleHint.entrySet()) {
+            if (entry.getValue().equals(preciseHint.get(entry.getKey()))) {
+                continue;

Review Comment:
   I will fix it.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org