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 2021/04/10 09:22:53 UTC

[GitHub] [shardingsphere] huanghao495430759 opened a new pull request #10024: Issue#9510.support rewrite SQL correctly when using sharding and encrypt together.

huanghao495430759 opened a new pull request #10024:
URL: https://github.com/apache/shardingsphere/pull/10024


   Fixes #9510 .
   
   Changes proposed in this pull request:
   - add CombinationalSQLToken.
   - refactor EncryptProjectionTokenGenerator.
   - refactor AbstractSQLBuilder to support CombinationalSQLToken.
   


-- 
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.

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



[GitHub] [shardingsphere] huanghao495430759 closed pull request #10024: Issue#9510.support rewrite SQL correctly when using sharding and encrypt together.

Posted by GitBox <gi...@apache.org>.
huanghao495430759 closed pull request #10024:
URL: https://github.com/apache/shardingsphere/pull/10024


   


-- 
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.

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



[GitHub] [shardingsphere] huanghao495430759 commented on a change in pull request #10024: Issue#9510.support rewrite SQL correctly when using sharding and encrypt together.

Posted by GitBox <gi...@apache.org>.
huanghao495430759 commented on a change in pull request #10024:
URL: https://github.com/apache/shardingsphere/pull/10024#discussion_r611165462



##########
File path: shardingsphere-infra/shardingsphere-infra-rewrite/shardingsphere-infra-rewrite-engine/src/main/java/org/apache/shardingsphere/infra/rewrite/sql/impl/AbstractSQLBuilder.java
##########
@@ -41,15 +43,30 @@ public final String toSQL() {
         Collections.sort(context.getSqlTokens());
         StringBuilder result = new StringBuilder();
         result.append(context.getSql(), 0, context.getSqlTokens().get(0).getStartIndex());
-        for (SQLToken each : context.getSqlTokens()) {
-            result.append(getSQLTokenText(each));
+        int size = context.getSqlTokens().size();
+        for (int index = 0; index < size; index++) {
+            if (index < size - 1 && isSubstitutableNeedIgnore(context.getSqlTokens().get(index), context.getSqlTokens().get(index + 1))) {
+                continue;
+            }
+            SQLToken each = context.getSqlTokens().get(index);
+            result.append(each instanceof Combinational ? getCombinationalText((Combinational) each) : getSQLTokenText(each));
             result.append(getConjunctionText(each));
         }
         return result.toString();
     }
-    
+
     protected abstract String getSQLTokenText(SQLToken sqlToken);
-    
+
+    private String getCombinationalText(final Combinational combinationalSQLToken) {
+        StringBuilder result = new StringBuilder();
+        Collection<SQLToken> subSQLTokens = combinationalSQLToken.getMaterials();
+        for (SQLToken subSQLToken : subSQLTokens) {
+            result.append(getSQLTokenText(subSQLToken));
+            result.append(getConjunctionText(subSQLToken));
+        }
+        return result.toString();

Review comment:
       > It is the kernel of rewrite module, could you provide a design doc to explain why and how to change here?
   
   Hi,this is my new ideas , [https://github.com/apache/shardingsphere/issues/9510#issuecomment-817283554](url)




-- 
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.

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



[GitHub] [shardingsphere] terrymanu commented on a change in pull request #10024: Issue#9510.support rewrite SQL correctly when using sharding and encrypt together.

Posted by GitBox <gi...@apache.org>.
terrymanu commented on a change in pull request #10024:
URL: https://github.com/apache/shardingsphere/pull/10024#discussion_r611043031



##########
File path: shardingsphere-infra/shardingsphere-infra-rewrite/shardingsphere-infra-rewrite-engine/src/main/java/org/apache/shardingsphere/infra/rewrite/sql/impl/AbstractSQLBuilder.java
##########
@@ -41,15 +43,30 @@ public final String toSQL() {
         Collections.sort(context.getSqlTokens());
         StringBuilder result = new StringBuilder();
         result.append(context.getSql(), 0, context.getSqlTokens().get(0).getStartIndex());
-        for (SQLToken each : context.getSqlTokens()) {
-            result.append(getSQLTokenText(each));
+        int size = context.getSqlTokens().size();
+        for (int index = 0; index < size; index++) {
+            if (index < size - 1 && isSubstitutableNeedIgnore(context.getSqlTokens().get(index), context.getSqlTokens().get(index + 1))) {
+                continue;
+            }
+            SQLToken each = context.getSqlTokens().get(index);
+            result.append(each instanceof Combinational ? getCombinationalText((Combinational) each) : getSQLTokenText(each));
             result.append(getConjunctionText(each));
         }
         return result.toString();
     }
-    
+
     protected abstract String getSQLTokenText(SQLToken sqlToken);
-    
+
+    private String getCombinationalText(final Combinational combinationalSQLToken) {
+        StringBuilder result = new StringBuilder();
+        Collection<SQLToken> subSQLTokens = combinationalSQLToken.getMaterials();
+        for (SQLToken subSQLToken : subSQLTokens) {
+            result.append(getSQLTokenText(subSQLToken));
+            result.append(getConjunctionText(subSQLToken));
+        }
+        return result.toString();

Review comment:
       It is the kernel of rewrite module, could you provide a design doc to explain why and how to change 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.

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



[GitHub] [shardingsphere] terrymanu commented on a change in pull request #10024: Issue#9510.support rewrite SQL correctly when using sharding and encrypt together.

Posted by GitBox <gi...@apache.org>.
terrymanu commented on a change in pull request #10024:
URL: https://github.com/apache/shardingsphere/pull/10024#discussion_r611202944



##########
File path: shardingsphere-infra/shardingsphere-infra-rewrite/shardingsphere-infra-rewrite-engine/src/main/java/org/apache/shardingsphere/infra/rewrite/sql/impl/AbstractSQLBuilder.java
##########
@@ -41,15 +43,30 @@ public final String toSQL() {
         Collections.sort(context.getSqlTokens());
         StringBuilder result = new StringBuilder();
         result.append(context.getSql(), 0, context.getSqlTokens().get(0).getStartIndex());
-        for (SQLToken each : context.getSqlTokens()) {
-            result.append(getSQLTokenText(each));
+        int size = context.getSqlTokens().size();
+        for (int index = 0; index < size; index++) {
+            if (index < size - 1 && isSubstitutableNeedIgnore(context.getSqlTokens().get(index), context.getSqlTokens().get(index + 1))) {
+                continue;
+            }
+            SQLToken each = context.getSqlTokens().get(index);
+            result.append(each instanceof Combinational ? getCombinationalText((Combinational) each) : getSQLTokenText(each));
             result.append(getConjunctionText(each));
         }
         return result.toString();
     }
-    
+
     protected abstract String getSQLTokenText(SQLToken sqlToken);
-    
+
+    private String getCombinationalText(final Combinational combinationalSQLToken) {
+        StringBuilder result = new StringBuilder();
+        Collection<SQLToken> subSQLTokens = combinationalSQLToken.getMaterials();
+        for (SQLToken subSQLToken : subSQLTokens) {
+            result.append(getSQLTokenText(subSQLToken));
+            result.append(getConjunctionText(subSQLToken));
+        }
+        return result.toString();

Review comment:
       Thank you for the excellent design. I just reply the issue and give some advices for me. 




-- 
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.

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



[GitHub] [shardingsphere] huanghao495430759 commented on a change in pull request #10024: Issue#9510.support rewrite SQL correctly when using sharding and encrypt together.

Posted by GitBox <gi...@apache.org>.
huanghao495430759 commented on a change in pull request #10024:
URL: https://github.com/apache/shardingsphere/pull/10024#discussion_r611165462



##########
File path: shardingsphere-infra/shardingsphere-infra-rewrite/shardingsphere-infra-rewrite-engine/src/main/java/org/apache/shardingsphere/infra/rewrite/sql/impl/AbstractSQLBuilder.java
##########
@@ -41,15 +43,30 @@ public final String toSQL() {
         Collections.sort(context.getSqlTokens());
         StringBuilder result = new StringBuilder();
         result.append(context.getSql(), 0, context.getSqlTokens().get(0).getStartIndex());
-        for (SQLToken each : context.getSqlTokens()) {
-            result.append(getSQLTokenText(each));
+        int size = context.getSqlTokens().size();
+        for (int index = 0; index < size; index++) {
+            if (index < size - 1 && isSubstitutableNeedIgnore(context.getSqlTokens().get(index), context.getSqlTokens().get(index + 1))) {
+                continue;
+            }
+            SQLToken each = context.getSqlTokens().get(index);
+            result.append(each instanceof Combinational ? getCombinationalText((Combinational) each) : getSQLTokenText(each));
             result.append(getConjunctionText(each));
         }
         return result.toString();
     }
-    
+
     protected abstract String getSQLTokenText(SQLToken sqlToken);
-    
+
+    private String getCombinationalText(final Combinational combinationalSQLToken) {
+        StringBuilder result = new StringBuilder();
+        Collection<SQLToken> subSQLTokens = combinationalSQLToken.getMaterials();
+        for (SQLToken subSQLToken : subSQLTokens) {
+            result.append(getSQLTokenText(subSQLToken));
+            result.append(getConjunctionText(subSQLToken));
+        }
+        return result.toString();

Review comment:
       > It is the kernel of rewrite module, could you provide a design doc to explain why and how to change here?
   
   Hi,this is my new ideas , https://github.com/apache/shardingsphere/issues/9510#issuecomment-817283554




-- 
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.

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