This is an automated email from the ASF dual-hosted git repository.

duanzhengqiang 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 e5cb762  matched the PredicateColumnToken and PredicateRightValueToken 
(#15952)
e5cb762 is described below

commit e5cb7628ebcda4b5c78cadcf97be61c8ccc3c407
Author: cheese8 <[email protected]>
AuthorDate: Thu Mar 10 10:08:12 2022 +0800

    matched the PredicateColumnToken and PredicateRightValueToken (#15952)
---
 .../generator/EncryptPredicateRightValueTokenGenerator.java      | 9 ++++++++-
 .../case/query-with-plain/dml/select/select_projection.xml       | 5 +++++
 2 files changed, 13 insertions(+), 1 deletion(-)

diff --git 
a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/EncryptPredicateRightValueTokenGenerator.java
 
b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/EncryptPredicateRightValueTokenGenerator.java
index a7849a6..69c68c6 100644
--- 
a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/EncryptPredicateRightValueTokenGenerator.java
+++ 
b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/src/main/java/org/apache/shardingsphere/encrypt/rewrite/token/generator/EncryptPredicateRightValueTokenGenerator.java
@@ -33,6 +33,7 @@ import 
org.apache.shardingsphere.infra.rewrite.sql.token.generator.aware.Paramet
 import org.apache.shardingsphere.infra.rewrite.sql.token.pojo.SQLToken;
 
 import java.util.Collection;
+import java.util.HashMap;
 import java.util.LinkedHashMap;
 import java.util.LinkedHashSet;
 import java.util.List;
@@ -93,7 +94,13 @@ public final class EncryptPredicateRightValueTokenGenerator 
implements Collectio
     
     private SQLToken generateSQLTokenForQueryWithoutCipherColumn(final 
EncryptCondition encryptCondition, final List<Object> originalValues, final int 
startIndex) {
         int stopIndex = encryptCondition.getStopIndex();
-        Map<Integer, Object> indexValues = 
getPositionValues(encryptCondition.getPositionValueMap().keySet(), 
originalValues);
+        Map<Integer, Object> indexValues = new HashMap<>();
+        Optional<String> plainColumn = 
encryptRule.findPlainColumn(encryptCondition.getTableName(), 
encryptCondition.getColumnName());
+        if (plainColumn.isPresent()) {
+            
indexValues.putAll(getPositionValues(encryptCondition.getPositionValueMap().keySet(),
 originalValues));
+        } else {
+            
indexValues.putAll(getPositionValues(encryptCondition.getPositionValueMap().keySet(),
 getEncryptedValues(schemaName, encryptCondition, originalValues)));
+        }
         Collection<Integer> parameterMarkerIndexes = 
encryptCondition.getPositionIndexMap().keySet();
         return encryptCondition instanceof EncryptInCondition
                 ? new EncryptPredicateInRightValueToken(startIndex, stopIndex, 
indexValues, parameterMarkerIndexes)
diff --git 
a/shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/encrypt/case/query-with-plain/dml/select/select_projection.xml
 
b/shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/encrypt/case/query-with-plain/dml/select/select_projection.xml
index 6a94e8a..e8ca98c 100644
--- 
a/shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/encrypt/case/query-with-plain/dml/select/select_projection.xml
+++ 
b/shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/encrypt/case/query-with-plain/dml/select/select_projection.xml
@@ -51,4 +51,9 @@
         <input sql="SELECT * FROM t_order WHERE content = ?" parameters="TEST" 
/>
         <output sql="SELECT `t_order`.`order_id`, `t_order`.`user_id`, 
`t_order`.`plain_content` AS `content` FROM t_order WHERE plain_content = ?" 
parameters="TEST" />
     </rewrite-assertion>
+
+    <rewrite-assertion 
id="select_for_predicate_and_right_value_should_be_matched" db-types="MySQL">
+        <input sql="SELECT account_id, password, amount AS a, status AS s FROM 
t_account WHERE account_id = 1 AND password = 'aaa' AND amount = 1000 AND 
status = 'OK'" />
+        <output sql="SELECT account_id, cipher_password AS password, 
cipher_amount AS a, status AS s FROM t_account WHERE account_id = 1 AND 
assisted_query_password = 'assisted_query_aaa' AND cipher_amount = 
'encrypt_1000' AND status = 'OK'" />
+    </rewrite-assertion>
 </rewrite-assertions>

Reply via email to