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

panjuan 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 3620a24aa52 Revise #18179, fix exception occurred for encrypt DistSQL. 
(#19337)
3620a24aa52 is described below

commit 3620a24aa52afff115eae765020fb51be556a46e
Author: Raigor <[email protected]>
AuthorDate: Wed Jul 20 09:16:25 2022 +0800

    Revise #18179, fix exception occurred for encrypt DistSQL. (#19337)
---
 .../distsql/handler/converter/EncryptRuleStatementConverter.java | 9 ++++++---
 .../encrypt/distsql/handler/query/EncryptRuleQueryResultSet.java | 4 +---
 .../encrypt/distsql/parser/segment/EncryptColumnSegment.java     | 9 ---------
 3 files changed, 7 insertions(+), 15 deletions(-)

diff --git 
a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-distsql/shardingsphere-encrypt-distsql-handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/converter/EncryptRuleStatementConverter.java
 
b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-distsql/shardingsphere-encrypt-distsql-handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/converter/EncryptRuleStatementConverter.java
index 00ad5f7fd72..23aec718e8b 100644
--- 
a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-distsql/shardingsphere-encrypt-distsql-handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/converter/EncryptRuleStatementConverter.java
+++ 
b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-distsql/shardingsphere-encrypt-distsql-handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/converter/EncryptRuleStatementConverter.java
@@ -59,15 +59,18 @@ public final class EncryptRuleStatementConverter {
     }
     
     private static EncryptColumnRuleConfiguration 
createEncryptColumnRuleConfiguration(final String tableName, final 
EncryptColumnSegment columnSegment) {
+        String assistedQueryEncryptorName = null == 
columnSegment.getAssistedQueryEncryptor() ? null : 
getAssistedQueryEncryptorName(tableName, columnSegment.getName());
         return new EncryptColumnRuleConfiguration(columnSegment.getName(), 
columnSegment.getCipherColumn(), columnSegment.getAssistedQueryColumn(),
-                columnSegment.getPlainColumn(), getEncryptorName(tableName, 
columnSegment.getName()), getAssistedQueryEncryptorName(tableName, 
columnSegment.getName()), null);
+                columnSegment.getPlainColumn(), getEncryptorName(tableName, 
columnSegment.getName()), assistedQueryEncryptorName, null);
     }
     
     private static Map<String, ShardingSphereAlgorithmConfiguration> 
createEncryptorConfigurations(final EncryptRuleSegment ruleSegment) {
-        Map<String, ShardingSphereAlgorithmConfiguration> result = new 
HashMap<>();
+        Map<String, ShardingSphereAlgorithmConfiguration> result = new 
HashMap<>(ruleSegment.getColumns().size(), 1);
         for (EncryptColumnSegment each : ruleSegment.getColumns()) {
             result.put(getEncryptorName(ruleSegment.getTableName(), 
each.getName()), createEncryptorConfiguration(each));
-            
result.put(getAssistedQueryEncryptorName(ruleSegment.getTableName(), 
each.getName()), createAssistedQueryEncryptorConfiguration(each));
+            if (null != each.getAssistedQueryEncryptor()) {
+                
result.put(getAssistedQueryEncryptorName(ruleSegment.getTableName(), 
each.getName()), createAssistedQueryEncryptorConfiguration(each));
+            }
         }
         return result;
     }
diff --git 
a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-distsql/shardingsphere-encrypt-distsql-handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/query/EncryptRuleQueryResultSet.java
 
b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-distsql/shardingsphere-encrypt-distsql-handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/query/EncryptRuleQueryResultSet.java
index 2df9f5743c2..d5b5cac3d3f 100644
--- 
a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-distsql/shardingsphere-encrypt-distsql-handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/query/EncryptRuleQueryResultSet.java
+++ 
b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-distsql/shardingsphere-encrypt-distsql-handler/src/main/java/org/apache/shardingsphere/encrypt/distsql/handler/query/EncryptRuleQueryResultSet.java
@@ -17,7 +17,6 @@
 
 package org.apache.shardingsphere.encrypt.distsql.handler.query;
 
-import com.google.common.base.Preconditions;
 import org.apache.shardingsphere.encrypt.api.config.EncryptRuleConfiguration;
 import 
org.apache.shardingsphere.encrypt.api.config.rule.EncryptTableRuleConfiguration;
 import 
org.apache.shardingsphere.encrypt.distsql.parser.statement.ShowEncryptRulesStatement;
@@ -48,8 +47,7 @@ public final class EncryptRuleQueryResultSet implements 
DistSQLResultSet {
     @Override
     public void init(final ShardingSphereDatabase database, final SQLStatement 
sqlStatement) {
         Optional<EncryptRule> rule = 
database.getRuleMetaData().findSingleRule(EncryptRule.class);
-        Preconditions.checkState(rule.isPresent());
-        data = buildData((EncryptRuleConfiguration) 
rule.get().getConfiguration(), (ShowEncryptRulesStatement) 
sqlStatement).iterator();
+        rule.ifPresent(optional -> data = buildData((EncryptRuleConfiguration) 
optional.getConfiguration(), (ShowEncryptRulesStatement) 
sqlStatement).iterator());
     }
     
     private Collection<Collection<Object>> buildData(final 
EncryptRuleConfiguration ruleConfig, final ShowEncryptRulesStatement 
sqlStatement) {
diff --git 
a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-distsql/shardingsphere-encrypt-distsql-statement/src/main/java/org/apache/shardingsphere/encrypt/distsql/parser/segment/EncryptColumnSegment.java
 
b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-distsql/shardingsphere-encrypt-distsql-statement/src/main/java/org/apache/shardingsphere/encrypt/distsql/parser/segment/EncryptColumnSegment.java
index e1b8d380fdf..d4cdc140cf3 100644
--- 
a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-distsql/shardingsphere-encrypt-distsql-statement/src/main/java/org/apache/shardingsphere/encrypt/distsql/parser/segment/EncryptColumnSegment.java
+++ 
b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-distsql/shardingsphere-encrypt-distsql-statement/src/main/java/org/apache/shardingsphere/encrypt/distsql/parser/segment/EncryptColumnSegment.java
@@ -52,15 +52,6 @@ public final class EncryptColumnSegment implements ASTNode {
     
     private final AlgorithmSegment assistedQueryEncryptor;
     
-    public EncryptColumnSegment(final String name, final String cipherColumn, 
final String plainColumn, final String assistedQueryColumn, final 
AlgorithmSegment encryptor) {
-        this(name, cipherColumn, plainColumn, assistedQueryColumn, encryptor, 
null);
-    }
-    
-    public EncryptColumnSegment(final String name, final String cipherColumn, 
final String plainColumn, final String assistedQueryColumn, final String 
dataType, final String cipherDataType,
-                                final String plainDataType, final String 
assistedQueryDataType, final AlgorithmSegment encryptor) {
-        this(name, cipherColumn, plainColumn, assistedQueryColumn, dataType, 
cipherDataType, plainDataType, assistedQueryDataType, encryptor, null);
-    }
-    
     /**
      * Is the data type correct.
      *

Reply via email to