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/06/09 06:20:51 UTC

[shardingsphere] branch master updated: parse assistedQueryEncryptor for encrypt distsql (#18256)

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 2179bfbac2d parse assistedQueryEncryptor for encrypt distsql (#18256)
2179bfbac2d is described below

commit 2179bfbac2d83d81ffd8b1c6c407f46b578573e5
Author: cheese8 <yi...@163.com>
AuthorDate: Thu Jun 9 14:20:44 2022 +0800

    parse assistedQueryEncryptor for encrypt distsql (#18256)
    
    * parse assistedQueryEncryptor for encrypt distsql
    
    * Update EncryptColumnSegment.java
---
 .../src/main/antlr4/imports/encrypt/RDLStatement.g4           |  2 +-
 .../distsql/parser/core/EncryptDistSQLStatementVisitor.java   |  8 +++++++-
 .../encrypt/distsql/parser/segment/EncryptColumnSegment.java  | 11 +++++++++++
 3 files changed, 19 insertions(+), 2 deletions(-)

diff --git a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-distsql/shardingsphere-encrypt-distsql-parser/src/main/antlr4/imports/encrypt/RDLStatement.g4 b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-distsql/shardingsphere-encrypt-distsql-parser/src/main/antlr4/imports/encrypt/RDLStatement.g4
index bf8b82de2db..0713e64fffd 100644
--- a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-distsql/shardingsphere-encrypt-distsql-parser/src/main/antlr4/imports/encrypt/RDLStatement.g4
+++ b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-distsql/shardingsphere-encrypt-distsql-parser/src/main/antlr4/imports/encrypt/RDLStatement.g4
@@ -44,7 +44,7 @@ resourceName
     ;
 
 encryptColumnDefinition
-    : LP columnDefinition (COMMA plainColumnDefinition)? COMMA cipherColumnDefinition (COMMA assistedQueryColumnDefinition)? COMMA algorithmDefinition RP
+    : LP columnDefinition (COMMA plainColumnDefinition)? COMMA cipherColumnDefinition (COMMA assistedQueryColumnDefinition)? COMMA algorithmDefinition (COMMA algorithmDefinition)? RP
     ;
 
 columnDefinition
diff --git a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-distsql/shardingsphere-encrypt-distsql-parser/src/main/java/org/apache/shardingsphere/encrypt/distsql/parser/core/EncryptDistSQLStatementVisitor.java b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-distsql/shardingsphere-encrypt-distsql-parser/src/main/java/org/apache/shardingsphere/encrypt/distsql/parser/core/EncryptDistSQLStatementVisitor.java
index 8b5fa0c5333..4f39fcc2676 100644
--- a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-distsql/shardingsphere-encrypt-distsql-parser/src/main/java/org/apache/shardingsphere/encrypt/distsql/parser/core/EncryptDistSQLStatementVisitor.java
+++ b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-distsql/shardingsphere-encrypt-distsql-parser/src/main/java/org/apache/shardingsphere/encrypt/distsql/parser/core/EncryptDistSQLStatementVisitor.java
@@ -42,6 +42,8 @@ import org.apache.shardingsphere.sql.parser.sql.common.segment.generic.DatabaseS
 import org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.TableNameSegment;
 import org.apache.shardingsphere.sql.parser.sql.common.value.identifier.IdentifierValue;
 
+import java.util.ArrayList;
+import java.util.List;
 import java.util.Properties;
 import java.util.stream.Collectors;
 
@@ -80,6 +82,10 @@ public final class EncryptDistSQLStatementVisitor extends EncryptDistSQLStatemen
     
     @Override
     public ASTNode visitEncryptColumnDefinition(final EncryptColumnDefinitionContext ctx) {
+        List<AlgorithmSegment> algorithmSegments = new ArrayList<>();
+        for (AlgorithmDefinitionContext each : ctx.algorithmDefinition()) {
+            algorithmSegments.add((AlgorithmSegment) visit(each));
+        }
         return new EncryptColumnSegment(getIdentifierValue(ctx.columnDefinition().columnName()),
                 getIdentifierValue(ctx.cipherColumnDefinition().cipherColumnName()),
                 null == ctx.plainColumnDefinition() ? null : getIdentifierValue(ctx.plainColumnDefinition().plainColumnName()),
@@ -88,7 +94,7 @@ public final class EncryptDistSQLStatementVisitor extends EncryptDistSQLStatemen
                 getIdentifierValue(ctx.cipherColumnDefinition().dataType()),
                 null == ctx.plainColumnDefinition() ? null : getIdentifierValue(ctx.plainColumnDefinition().dataType()),
                 null == ctx.assistedQueryColumnDefinition() ? null : getIdentifierValue(ctx.assistedQueryColumnDefinition().dataType()),
-                (AlgorithmSegment) visit(ctx.algorithmDefinition()));
+                algorithmSegments.get(0), 1 == algorithmSegments.size() ? null : algorithmSegments.get(1));
     }
     
     @Override
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 befb4acd186..2aaeccdbe03 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
@@ -50,6 +50,17 @@ public final class EncryptColumnSegment implements ASTNode {
     
     private final AlgorithmSegment encryptor;
     
+    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.
      *