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 6952ba1  Split encrypt ANTLR g4 file and visitor (#10818)
6952ba1 is described below

commit 6952ba1b84f353f7c21751bd3aceb09eece2dffb
Author: Liang Zhang <[email protected]>
AuthorDate: Tue Jun 15 19:16:32 2021 +0800

    Split encrypt ANTLR g4 file and visitor (#10818)
---
 .../src/main/antlr4/imports/RDLStatement.g4        |  56 ----------
 .../src/main/antlr4/imports/RQLStatement.g4        |  12 ---
 .../distsql/parser/autogen/DistSQLStatement.g4     |   4 -
 .../resource/ResourceDistSQLStatementVisitor.java  |  77 --------------
 .../api/DistSQLStatementParserEngineTest.java      |  88 ----------------
 .../shardingsphere-encrypt/pom.xml                 |   1 +
 .../shardingsphere-encrypt-core/pom.xml            |   5 +
 .../pom.xml                                        |  40 ++++---
 .../src/main/antlr4/imports/encrypt/Alphabet.g4    |  50 +++++----
 .../src/main/antlr4/imports/encrypt/Keyword.g4     |  76 +++++++++++---
 .../src/main/antlr4/imports/encrypt/Literals.g4    |  35 ++++---
 .../main/antlr4/imports/encrypt}/RDLStatement.g4   |  40 -------
 .../main/antlr4/imports/encrypt}/RQLStatement.g4   |   4 -
 .../src/main/antlr4/imports/encrypt/Symbol.g4      |  61 +++++++++++
 .../distsql/parser/autogen/EncryptRuleStatement.g4 |  16 +--
 .../distsql/parser/core/EncryptRuleLexer.java      |  34 +++---
 .../distsql/parser/core/EncryptRuleParser.java     |  41 ++++----
 .../core/EncryptRuleSQLStatementVisitor.java       | 115 +++++++++++++++++++++
 .../EncryptRuleSQLStatementParserFacade.java       |  52 ++++++++++
 ...distsql.parser.spi.RuleSQLStatementParserFacade |  18 ++++
 .../core/EncryptRuleStatementParserEngineTest.java |  74 +------------
 21 files changed, 435 insertions(+), 464 deletions(-)

diff --git 
a/shardingsphere-distsql-parser/shardingsphere-distsql-parser-engine/src/main/antlr4/imports/RDLStatement.g4
 
b/shardingsphere-distsql-parser/shardingsphere-distsql-parser-engine/src/main/antlr4/imports/RDLStatement.g4
index f872891..f073e20 100644
--- 
a/shardingsphere-distsql-parser/shardingsphere-distsql-parser-engine/src/main/antlr4/imports/RDLStatement.g4
+++ 
b/shardingsphere-distsql-parser/shardingsphere-distsql-parser-engine/src/main/antlr4/imports/RDLStatement.g4
@@ -58,59 +58,3 @@ user
 password
     : IDENTIFIER | INT | STRING
     ;
-
-resourceName
-    : IDENTIFIER
-    ;
-
-tableName
-    : IDENTIFIER
-    ;
-
-columnName
-    : IDENTIFIER
-    ;
-
-functionDefinition
-    : TYPE LP NAME EQ functionName (COMMA PROPERTIES LP algorithmProperties? 
RP)? RP
-    ;
-
-functionName
-    : IDENTIFIER
-    ;
-
-algorithmProperties
-    : algorithmProperty (COMMA algorithmProperty)*
-    ;
-
-algorithmProperty
-    : key=(IDENTIFIER | STRING) EQ value=(NUMBER | INT | STRING)
-    ;
-
-createEncryptRule
-    : CREATE ENCRYPT RULE encryptRuleDefinition (COMMA encryptRuleDefinition)*
-    ;
-
-encryptRuleDefinition
-    : tableName LP (RESOURCE EQ resourceName COMMA)? COLUMNS LP 
columnDefinition (COMMA columnDefinition)*  RP RP
-    ;
-
-columnDefinition
-    : LP NAME EQ columnName (COMMA PLAIN EQ plainColumnName)? COMMA CIPHER EQ 
cipherColumnName COMMA functionDefinition RP
-    ;
-
-alterEncryptRule
-    : ALTER ENCRYPT RULE encryptRuleDefinition (COMMA encryptRuleDefinition)*
-    ;
-
-dropEncryptRule
-    : DROP ENCRYPT RULE IDENTIFIER (COMMA IDENTIFIER)*
-    ;
-
-plainColumnName
-    : IDENTIFIER
-    ;
-
-cipherColumnName
-    : IDENTIFIER
-    ;
diff --git 
a/shardingsphere-distsql-parser/shardingsphere-distsql-parser-engine/src/main/antlr4/imports/RQLStatement.g4
 
b/shardingsphere-distsql-parser/shardingsphere-distsql-parser-engine/src/main/antlr4/imports/RQLStatement.g4
index 81fcf28..8651318 100644
--- 
a/shardingsphere-distsql-parser/shardingsphere-distsql-parser-engine/src/main/antlr4/imports/RQLStatement.g4
+++ 
b/shardingsphere-distsql-parser/shardingsphere-distsql-parser-engine/src/main/antlr4/imports/RQLStatement.g4
@@ -23,18 +23,6 @@ showResources
     : SHOW RESOURCES (FROM schemaName)?
     ;
 
-showEncryptRules
-    : SHOW ENCRYPT (TABLE tableRule | RULES) (FROM schemaName)?
-    ;
-
-tableRule
-    : RULE tableName
-    ;
-
 schemaName
     : IDENTIFIER
     ;
-
-tableName
-    : IDENTIFIER
-    ;
diff --git 
a/shardingsphere-distsql-parser/shardingsphere-distsql-parser-engine/src/main/antlr4/org/apache/shardingsphere/distsql/parser/autogen/DistSQLStatement.g4
 
b/shardingsphere-distsql-parser/shardingsphere-distsql-parser-engine/src/main/antlr4/org/apache/shardingsphere/distsql/parser/autogen/DistSQLStatement.g4
index d561f2f..6bc69a3 100644
--- 
a/shardingsphere-distsql-parser/shardingsphere-distsql-parser-engine/src/main/antlr4/org/apache/shardingsphere/distsql/parser/autogen/DistSQLStatement.g4
+++ 
b/shardingsphere-distsql-parser/shardingsphere-distsql-parser-engine/src/main/antlr4/org/apache/shardingsphere/distsql/parser/autogen/DistSQLStatement.g4
@@ -22,11 +22,7 @@ import Symbol, RDLStatement, RQLStatement, RALStatement;
 execute
     : (addResource
     | dropResource
-    | createEncryptRule
-    | alterEncryptRule
-    | dropEncryptRule
     | showResources
-    | showEncryptRules
     | showScalingJobList
     | showScalingJobStatus
     | startScalingJob
diff --git 
a/shardingsphere-distsql-parser/shardingsphere-distsql-parser-engine/src/main/java/org/apache/shardingsphere/distsql/parser/core/resource/ResourceDistSQLStatementVisitor.java
 
b/shardingsphere-distsql-parser/shardingsphere-distsql-parser-engine/src/main/java/org/apache/shardingsphere/distsql/parser/core/resource/ResourceDistSQLStatementVisitor.java
index 557006a..51286c0 100644
--- 
a/shardingsphere-distsql-parser/shardingsphere-distsql-parser-engine/src/main/java/org/apache/shardingsphere/distsql/parser/core/resource/ResourceDistSQLStatementVisitor.java
+++ 
b/shardingsphere-distsql-parser/shardingsphere-distsql-parser-engine/src/main/java/org/apache/shardingsphere/distsql/parser/core/resource/ResourceDistSQLStatementVisitor.java
@@ -18,33 +18,20 @@
 package org.apache.shardingsphere.distsql.parser.core.resource;
 
 import org.antlr.v4.runtime.tree.ParseTree;
-import org.antlr.v4.runtime.tree.TerminalNode;
 import 
org.apache.shardingsphere.distsql.parser.autogen.DistSQLStatementBaseVisitor;
 import 
org.apache.shardingsphere.distsql.parser.autogen.DistSQLStatementParser.AddResourceContext;
-import 
org.apache.shardingsphere.distsql.parser.autogen.DistSQLStatementParser.AlgorithmPropertyContext;
-import 
org.apache.shardingsphere.distsql.parser.autogen.DistSQLStatementParser.AlterEncryptRuleContext;
 import 
org.apache.shardingsphere.distsql.parser.autogen.DistSQLStatementParser.CheckScalingJobContext;
-import 
org.apache.shardingsphere.distsql.parser.autogen.DistSQLStatementParser.ColumnDefinitionContext;
-import 
org.apache.shardingsphere.distsql.parser.autogen.DistSQLStatementParser.CreateEncryptRuleContext;
 import 
org.apache.shardingsphere.distsql.parser.autogen.DistSQLStatementParser.DataSourceContext;
-import 
org.apache.shardingsphere.distsql.parser.autogen.DistSQLStatementParser.DropEncryptRuleContext;
 import 
org.apache.shardingsphere.distsql.parser.autogen.DistSQLStatementParser.DropResourceContext;
 import 
org.apache.shardingsphere.distsql.parser.autogen.DistSQLStatementParser.DropScalingJobContext;
-import 
org.apache.shardingsphere.distsql.parser.autogen.DistSQLStatementParser.EncryptRuleDefinitionContext;
-import 
org.apache.shardingsphere.distsql.parser.autogen.DistSQLStatementParser.FunctionDefinitionContext;
 import 
org.apache.shardingsphere.distsql.parser.autogen.DistSQLStatementParser.ResetScalingJobContext;
 import 
org.apache.shardingsphere.distsql.parser.autogen.DistSQLStatementParser.SchemaNameContext;
-import 
org.apache.shardingsphere.distsql.parser.autogen.DistSQLStatementParser.ShowEncryptRulesContext;
 import 
org.apache.shardingsphere.distsql.parser.autogen.DistSQLStatementParser.ShowResourcesContext;
 import 
org.apache.shardingsphere.distsql.parser.autogen.DistSQLStatementParser.ShowScalingJobListContext;
 import 
org.apache.shardingsphere.distsql.parser.autogen.DistSQLStatementParser.ShowScalingJobStatusContext;
 import 
org.apache.shardingsphere.distsql.parser.autogen.DistSQLStatementParser.StartScalingJobContext;
 import 
org.apache.shardingsphere.distsql.parser.autogen.DistSQLStatementParser.StopScalingJobContext;
-import 
org.apache.shardingsphere.distsql.parser.autogen.DistSQLStatementParser.TableNameContext;
 import org.apache.shardingsphere.distsql.parser.segment.DataSourceSegment;
-import org.apache.shardingsphere.distsql.parser.segment.FunctionSegment;
-import 
org.apache.shardingsphere.distsql.parser.segment.rdl.EncryptColumnSegment;
-import org.apache.shardingsphere.distsql.parser.segment.rdl.EncryptRuleSegment;
 import 
org.apache.shardingsphere.distsql.parser.statement.ral.impl.CheckScalingJobStatement;
 import 
org.apache.shardingsphere.distsql.parser.statement.ral.impl.DropScalingJobStatement;
 import 
org.apache.shardingsphere.distsql.parser.statement.ral.impl.ResetScalingJobStatement;
@@ -52,21 +39,14 @@ import 
org.apache.shardingsphere.distsql.parser.statement.ral.impl.ShowScalingJo
 import 
org.apache.shardingsphere.distsql.parser.statement.ral.impl.ShowScalingJobStatusStatement;
 import 
org.apache.shardingsphere.distsql.parser.statement.ral.impl.StartScalingJobStatement;
 import 
org.apache.shardingsphere.distsql.parser.statement.ral.impl.StopScalingJobStatement;
-import 
org.apache.shardingsphere.distsql.parser.statement.rdl.alter.impl.AlterEncryptRuleStatement;
 import 
org.apache.shardingsphere.distsql.parser.statement.rdl.create.AddResourceStatement;
-import 
org.apache.shardingsphere.distsql.parser.statement.rdl.create.impl.CreateEncryptRuleStatement;
 import 
org.apache.shardingsphere.distsql.parser.statement.rdl.drop.DropResourceStatement;
-import 
org.apache.shardingsphere.distsql.parser.statement.rdl.drop.impl.DropEncryptRuleStatement;
 import 
org.apache.shardingsphere.distsql.parser.statement.rql.show.ShowResourcesStatement;
-import 
org.apache.shardingsphere.distsql.parser.statement.rql.show.impl.ShowEncryptRulesStatement;
 import org.apache.shardingsphere.sql.parser.api.visitor.ASTNode;
 import org.apache.shardingsphere.sql.parser.api.visitor.SQLVisitor;
 import 
org.apache.shardingsphere.sql.parser.sql.common.segment.generic.SchemaSegment;
-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.Objects;
-import java.util.Properties;
 import java.util.stream.Collectors;
 
 /**
@@ -97,57 +77,6 @@ public final class ResourceDistSQLStatementVisitor extends 
DistSQLStatementBaseV
     }
     
     @Override
-    public ASTNode visitFunctionDefinition(final FunctionDefinitionContext 
ctx) {
-        FunctionSegment result = new FunctionSegment();
-        result.setAlgorithmName(ctx.functionName().getText());
-        Properties algorithmProps = new Properties();
-        if (null != ctx.algorithmProperties()) {
-            for (AlgorithmPropertyContext each : 
ctx.algorithmProperties().algorithmProperty()) {
-                algorithmProps.setProperty(new 
IdentifierValue(each.key.getText()).getValue(), new 
IdentifierValue(each.value.getText()).getValue());
-            }
-        }
-        result.setAlgorithmProps(algorithmProps);
-        return result;
-    }
-    
-    @Override
-    public ASTNode visitCreateEncryptRule(final CreateEncryptRuleContext ctx) {
-        return new 
CreateEncryptRuleStatement(ctx.encryptRuleDefinition().stream().map(each -> 
(EncryptRuleSegment) visit(each)).collect(Collectors.toList()));
-    }
-    
-    @Override
-    public ASTNode visitEncryptRuleDefinition(final 
EncryptRuleDefinitionContext ctx) {
-        return new EncryptRuleSegment(ctx.tableName().getText(), 
ctx.columnDefinition().stream().map(each -> (EncryptColumnSegment) 
visit(each)).collect(Collectors.toList()));
-    }
-    
-    @Override
-    public ASTNode visitColumnDefinition(final ColumnDefinitionContext ctx) {
-        EncryptColumnSegment result = new EncryptColumnSegment();
-        result.setName(ctx.columnName().getText());
-        result.setCipherColumn(ctx.cipherColumnName().getText());
-        if (Objects.nonNull(ctx.plainColumnName())) {
-            result.setPlainColumn(ctx.plainColumnName().getText());
-        }
-        result.setEncryptor((FunctionSegment) visit(ctx.functionDefinition()));
-        return result;
-    }
-    
-    @Override
-    public ASTNode visitAlterEncryptRule(final AlterEncryptRuleContext ctx) {
-        return new 
AlterEncryptRuleStatement(ctx.encryptRuleDefinition().stream().map(each -> 
(EncryptRuleSegment) visit(each)).collect(Collectors.toList()));
-    }
-    
-    @Override
-    public ASTNode visitDropEncryptRule(final DropEncryptRuleContext ctx) {
-        return new 
DropEncryptRuleStatement(ctx.IDENTIFIER().stream().map(TerminalNode::getText).collect(Collectors.toList()));
-    }
-    
-    @Override
-    public ASTNode visitTableName(final TableNameContext ctx) {
-        return new TableNameSegment(ctx.getStart().getStartIndex(), 
ctx.getStop().getStopIndex(), new IdentifierValue(ctx.getText()));
-    }
-    
-    @Override
     public ASTNode visitShowResources(final ShowResourcesContext ctx) {
         return new ShowResourcesStatement(null == ctx.schemaName() ? null : 
(SchemaSegment) visit(ctx.schemaName()));
     }
@@ -183,12 +112,6 @@ public final class ResourceDistSQLStatementVisitor extends 
DistSQLStatementBaseV
     }
     
     @Override
-    public ASTNode visitShowEncryptRules(final ShowEncryptRulesContext ctx) {
-        return new ShowEncryptRulesStatement(Objects.nonNull(ctx.tableRule()) 
? ctx.tableRule().tableName().getText() : null,
-                Objects.nonNull(ctx.schemaName()) ? (SchemaSegment) 
visit(ctx.schemaName()) : null);
-    }
-    
-    @Override
     public ASTNode visitResetScalingJob(final ResetScalingJobContext ctx) {
         return new 
ResetScalingJobStatement(Long.parseLong(ctx.jobId().getText()));
     }
diff --git 
a/shardingsphere-distsql-parser/shardingsphere-distsql-parser-engine/src/test/java/org/apache/shardingsphere/distsql/parser/api/DistSQLStatementParserEngineTest.java
 
b/shardingsphere-distsql-parser/shardingsphere-distsql-parser-engine/src/test/java/org/apache/shardingsphere/distsql/parser/api/DistSQLStatementParserEngineTest.java
index f5041f2..f05e644 100644
--- 
a/shardingsphere-distsql-parser/shardingsphere-distsql-parser-engine/src/test/java/org/apache/shardingsphere/distsql/parser/api/DistSQLStatementParserEngineTest.java
+++ 
b/shardingsphere-distsql-parser/shardingsphere-distsql-parser-engine/src/test/java/org/apache/shardingsphere/distsql/parser/api/DistSQLStatementParserEngineTest.java
@@ -18,14 +18,8 @@
 package org.apache.shardingsphere.distsql.parser.api;
 
 import org.apache.shardingsphere.distsql.parser.segment.DataSourceSegment;
-import 
org.apache.shardingsphere.distsql.parser.segment.rdl.EncryptColumnSegment;
-import org.apache.shardingsphere.distsql.parser.segment.rdl.EncryptRuleSegment;
-import 
org.apache.shardingsphere.distsql.parser.statement.rdl.alter.impl.AlterEncryptRuleStatement;
 import 
org.apache.shardingsphere.distsql.parser.statement.rdl.create.AddResourceStatement;
-import 
org.apache.shardingsphere.distsql.parser.statement.rdl.create.impl.CreateEncryptRuleStatement;
 import 
org.apache.shardingsphere.distsql.parser.statement.rdl.drop.DropResourceStatement;
-import 
org.apache.shardingsphere.distsql.parser.statement.rdl.drop.impl.DropEncryptRuleStatement;
-import 
org.apache.shardingsphere.distsql.parser.statement.rql.show.impl.ShowEncryptRulesStatement;
 import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement;
 import org.junit.Test;
 
@@ -34,7 +28,6 @@ import java.util.Arrays;
 import java.util.List;
 
 import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertThat;
 import static org.junit.Assert.assertTrue;
 
@@ -50,24 +43,6 @@ public final class DistSQLStatementParserEngineTest {
     
     private static final String DROP_RESOURCE = "DROP RESOURCE ds_0,ds_1";
     
-    private static final String CREATE_ENCRYPT_RULE = "CREATE ENCRYPT RULE 
t_encrypt ("
-            + "COLUMNS("
-            + 
"(NAME=user_id,PLAIN=user_plain,CIPHER=user_cipher,TYPE(NAME=AES,PROPERTIES('aes-key-value'='123456abc'))),"
-            + "(NAME=order_id, CIPHER =order_cipher,TYPE(NAME=MD5))"
-            + "))";
-    
-    private static final String ALTER_ENCRYPT_RULE = "ALTER ENCRYPT RULE 
t_encrypt ("
-            + "COLUMNS("
-            + 
"(NAME=user_id,PLAIN=user_plain,CIPHER=user_cipher,TYPE(NAME=AES,PROPERTIES('aes-key-value'='123456abc'))),"
-            + "(NAME=order_id, CIPHER =order_cipher,TYPE(NAME=MD5))"
-            + "))";
-    
-    private static final String DROP_ENCRYPT_RULE = "DROP ENCRYPT RULE 
t_encrypt,t_encrypt_order";
-    
-    private static final String SHOW_ENCRYPT_RULES = "SHOW ENCRYPT RULES FROM 
encrypt_db";
-    
-    private static final String SHOW_ENCRYPT_TABLE_RULE = "SHOW ENCRYPT TABLE 
RULE t_encrypt FROM encrypt_db";
-    
     private final DistSQLStatementParserEngine engine = new 
DistSQLStatementParserEngine();
     
     @Test
@@ -126,67 +101,4 @@ public final class DistSQLStatementParserEngineTest {
         assertThat(((DropResourceStatement) sqlStatement).getNames().size(), 
is(2));
         assertTrue(((DropResourceStatement) 
sqlStatement).getNames().containsAll(Arrays.asList("ds_0", "ds_1")));
     }
-    
-    @Test
-    public void assertParseCreateEncryptRule() {
-        SQLStatement sqlStatement = engine.parse(CREATE_ENCRYPT_RULE);
-        assertTrue(sqlStatement instanceof CreateEncryptRuleStatement);
-        CreateEncryptRuleStatement createEncryptRuleStatement = 
(CreateEncryptRuleStatement) sqlStatement;
-        assertThat(createEncryptRuleStatement.getRules().size(), is(1));
-        EncryptRuleSegment encryptRuleSegment = 
createEncryptRuleStatement.getRules().iterator().next();
-        assertThat(encryptRuleSegment.getTableName(), is("t_encrypt"));
-        assertThat(encryptRuleSegment.getColumns().size(), is(2));
-        List<EncryptColumnSegment> encryptColumnSegments = new 
ArrayList<>(encryptRuleSegment.getColumns());
-        assertThat(encryptColumnSegments.get(0).getName(), is("user_id"));
-        assertThat(encryptColumnSegments.get(0).getCipherColumn(), 
is("user_cipher"));
-        assertThat(encryptColumnSegments.get(0).getPlainColumn(), 
is("user_plain"));
-        
assertThat(encryptColumnSegments.get(0).getEncryptor().getAlgorithmName(), 
is("AES"));
-        
assertThat(encryptColumnSegments.get(0).getEncryptor().getAlgorithmProps().get("aes-key-value"),
 is("123456abc"));
-        assertThat(encryptColumnSegments.get(1).getName(), is("order_id"));
-        assertThat(encryptColumnSegments.get(1).getCipherColumn(), 
is("order_cipher"));
-        
assertThat(encryptColumnSegments.get(1).getEncryptor().getAlgorithmName(), 
is("MD5"));
-    }
-    
-    @Test
-    public void assertParseAlterEncryptRule() {
-        SQLStatement sqlStatement = engine.parse(ALTER_ENCRYPT_RULE);
-        assertTrue(sqlStatement instanceof AlterEncryptRuleStatement);
-        AlterEncryptRuleStatement alterEncryptRuleStatement = 
(AlterEncryptRuleStatement) sqlStatement;
-        assertThat(alterEncryptRuleStatement.getRules().size(), is(1));
-        EncryptRuleSegment encryptRuleSegment = 
alterEncryptRuleStatement.getRules().iterator().next();
-        assertThat(encryptRuleSegment.getTableName(), is("t_encrypt"));
-        assertThat(encryptRuleSegment.getColumns().size(), is(2));
-        List<EncryptColumnSegment> encryptColumnSegments = new 
ArrayList<>(encryptRuleSegment.getColumns());
-        assertThat(encryptColumnSegments.get(0).getName(), is("user_id"));
-        assertThat(encryptColumnSegments.get(0).getCipherColumn(), 
is("user_cipher"));
-        assertThat(encryptColumnSegments.get(0).getPlainColumn(), 
is("user_plain"));
-        
assertThat(encryptColumnSegments.get(0).getEncryptor().getAlgorithmName(), 
is("AES"));
-        
assertThat(encryptColumnSegments.get(0).getEncryptor().getAlgorithmProps().get("aes-key-value"),
 is("123456abc"));
-        assertThat(encryptColumnSegments.get(1).getName(), is("order_id"));
-        assertThat(encryptColumnSegments.get(1).getCipherColumn(), 
is("order_cipher"));
-        
assertThat(encryptColumnSegments.get(1).getEncryptor().getAlgorithmName(), 
is("MD5"));
-    }
-    
-    @Test
-    public void assertParseDropEncryptRule() {
-        SQLStatement sqlStatement = engine.parse(DROP_ENCRYPT_RULE);
-        assertTrue(sqlStatement instanceof DropEncryptRuleStatement);
-        assertThat(((DropEncryptRuleStatement) sqlStatement).getTables(), 
is(Arrays.asList("t_encrypt", "t_encrypt_order")));
-    }
-    
-    @Test
-    public void assertParseShowEncryptRules() {
-        SQLStatement sqlStatement = engine.parse(SHOW_ENCRYPT_RULES);
-        assertTrue(sqlStatement instanceof ShowEncryptRulesStatement);
-        assertNull(((ShowEncryptRulesStatement) sqlStatement).getTableName());
-        assertThat(((ShowEncryptRulesStatement) 
sqlStatement).getSchema().get().getIdentifier().getValue(), is("encrypt_db"));
-    }
-    
-    @Test
-    public void assertParseShowEncryptTableRule() {
-        SQLStatement sqlStatement = engine.parse(SHOW_ENCRYPT_TABLE_RULE);
-        assertTrue(sqlStatement instanceof ShowEncryptRulesStatement);
-        assertThat(((ShowEncryptRulesStatement) 
sqlStatement).getSchema().get().getIdentifier().getValue(), is("encrypt_db"));
-        assertThat(((ShowEncryptRulesStatement) sqlStatement).getTableName(), 
is("t_encrypt"));
-    }
 }
diff --git a/shardingsphere-features/shardingsphere-encrypt/pom.xml 
b/shardingsphere-features/shardingsphere-encrypt/pom.xml
index a72604a..0d902b5 100644
--- a/shardingsphere-features/shardingsphere-encrypt/pom.xml
+++ b/shardingsphere-features/shardingsphere-encrypt/pom.xml
@@ -32,6 +32,7 @@
     <modules>
         <module>shardingsphere-encrypt-api</module>
         <module>shardingsphere-encrypt-core</module>
+        <module>shardingsphere-encrypt-distsql</module>
         <module>shardingsphere-encrypt-spring</module>
     </modules>
 </project>
diff --git 
a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/pom.xml
 
b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/pom.xml
index ac4c161..dfb0d79 100644
--- 
a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/pom.xml
+++ 
b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/pom.xml
@@ -34,6 +34,11 @@
             <artifactId>shardingsphere-encrypt-api</artifactId>
             <version>${project.version}</version>
         </dependency>
+        <dependency>
+            <groupId>org.apache.shardingsphere</groupId>
+            <artifactId>shardingsphere-encrypt-distsql</artifactId>
+            <version>${project.version}</version>
+        </dependency>
         
         <dependency>
             <groupId>org.apache.shardingsphere</groupId>
diff --git 
a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/pom.xml
 
b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-distsql/pom.xml
similarity index 63%
copy from 
shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/pom.xml
copy to 
shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-distsql/pom.xml
index ac4c161..cc6818d 100644
--- 
a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-core/pom.xml
+++ 
b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-distsql/pom.xml
@@ -25,30 +25,46 @@
         <artifactId>shardingsphere-encrypt</artifactId>
         <version>5.0.0-RC1-SNAPSHOT</version>
     </parent>
-    <artifactId>shardingsphere-encrypt-core</artifactId>
+    <artifactId>shardingsphere-encrypt-distsql</artifactId>
     <name>${project.artifactId}</name>
     
     <dependencies>
         <dependency>
             <groupId>org.apache.shardingsphere</groupId>
-            <artifactId>shardingsphere-encrypt-api</artifactId>
-            <version>${project.version}</version>
+            <artifactId>shardingsphere-sql-parser-spi</artifactId>
+            <version>5.0.0-RC1-SNAPSHOT</version>
         </dependency>
-        
         <dependency>
             <groupId>org.apache.shardingsphere</groupId>
-            <artifactId>shardingsphere-distsql-parser-statement</artifactId>
+            <artifactId>shardingsphere-distsql-parser-engine</artifactId>
             <version>${project.version}</version>
         </dependency>
         <dependency>
             <groupId>org.apache.shardingsphere</groupId>
-            <artifactId>shardingsphere-infra-rewrite</artifactId>
-            <version>${project.version}</version>
-        </dependency>
-        <dependency>
-            <groupId>org.apache.shardingsphere</groupId>
-            <artifactId>shardingsphere-infra-merge</artifactId>
-            <version>${project.version}</version>
+            <artifactId>shardingsphere-distsql-parser-statement</artifactId>
+            <version>5.0.0-RC1-SNAPSHOT</version>
         </dependency>
     </dependencies>
+    
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.antlr</groupId>
+                <artifactId>antlr4-maven-plugin</artifactId>
+                <executions>
+                    <execution>
+                        <id>antlr</id>
+                        <configuration>
+                            
<libDirectory>src/main/antlr4/imports/encrypt/</libDirectory>
+                            <listener>false</listener>
+                            <visitor>true</visitor>
+                        </configuration>
+                        <goals>
+                            <goal>antlr4</goal>
+                        </goals>
+                    </execution>
+                </executions>
+            </plugin>
+        </plugins>
+    </build>
 </project>
diff --git 
a/shardingsphere-distsql-parser/shardingsphere-distsql-parser-engine/src/main/antlr4/imports/RQLStatement.g4
 
b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-distsql/src/main/antlr4/imports/encrypt/Alphabet.g4
similarity index 56%
copy from 
shardingsphere-distsql-parser/shardingsphere-distsql-parser-engine/src/main/antlr4/imports/RQLStatement.g4
copy to 
shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-distsql/src/main/antlr4/imports/encrypt/Alphabet.g4
index 81fcf28..f7603cc 100644
--- 
a/shardingsphere-distsql-parser/shardingsphere-distsql-parser-engine/src/main/antlr4/imports/RQLStatement.g4
+++ 
b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-distsql/src/main/antlr4/imports/encrypt/Alphabet.g4
@@ -15,26 +15,34 @@
  * limitations under the License.
  */
 
-grammar RQLStatement;
+lexer grammar Alphabet;
 
-import Keyword, Literals, Symbol;
+FOR_GENERATOR: 'DO NOT MATCH ANY THING, JUST FOR GENERATOR';
 
-showResources
-    : SHOW RESOURCES (FROM schemaName)?
-    ;
-
-showEncryptRules
-    : SHOW ENCRYPT (TABLE tableRule | RULES) (FROM schemaName)?
-    ;
-
-tableRule
-    : RULE tableName
-    ;
-
-schemaName
-    : IDENTIFIER
-    ;
-
-tableName
-    : IDENTIFIER
-    ;
+fragment A:   [Aa];
+fragment B:   [Bb];
+fragment C:   [Cc];
+fragment D:   [Dd];
+fragment E:   [Ee];
+fragment F:   [Ff];
+fragment G:   [Gg];
+fragment H:   [Hh];
+fragment I:   [Ii];
+fragment J:   [Jj];
+fragment K:   [Kk];
+fragment L:   [Ll];
+fragment M:   [Mm];
+fragment N:   [Nn];
+fragment O:   [Oo];
+fragment P:   [Pp];
+fragment Q:   [Qq];
+fragment R:   [Rr];
+fragment S:   [Ss];
+fragment T:   [Tt];
+fragment U:   [Uu];
+fragment V:   [Vv];
+fragment W:   [Ww];
+fragment X:   [Xx];
+fragment Y:   [Yy];
+fragment Z:   [Zz];
+fragment UL_: '_';
diff --git 
a/shardingsphere-distsql-parser/shardingsphere-distsql-parser-engine/src/main/antlr4/imports/RQLStatement.g4
 
b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-distsql/src/main/antlr4/imports/encrypt/Keyword.g4
similarity index 59%
copy from 
shardingsphere-distsql-parser/shardingsphere-distsql-parser-engine/src/main/antlr4/imports/RQLStatement.g4
copy to 
shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-distsql/src/main/antlr4/imports/encrypt/Keyword.g4
index 81fcf28..94f1356 100644
--- 
a/shardingsphere-distsql-parser/shardingsphere-distsql-parser-engine/src/main/antlr4/imports/RQLStatement.g4
+++ 
b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-distsql/src/main/antlr4/imports/encrypt/Keyword.g4
@@ -15,26 +15,78 @@
  * limitations under the License.
  */
 
-grammar RQLStatement;
+lexer grammar Keyword;
 
-import Keyword, Literals, Symbol;
+import Alphabet;
 
-showResources
-    : SHOW RESOURCES (FROM schemaName)?
+WS
+    : [ \t\r\n] + ->skip
     ;
 
-showEncryptRules
-    : SHOW ENCRYPT (TABLE tableRule | RULES) (FROM schemaName)?
+CREATE
+    : C R E A T E
     ;
 
-tableRule
-    : RULE tableName
+ALTER
+    : A L T E R
     ;
 
-schemaName
-    : IDENTIFIER
+DROP
+    : D R O P
     ;
 
-tableName
-    : IDENTIFIER
+SHOW
+    : S H O W
+    ;
+
+RESOURCE
+    : R E S O U R C E
+    ;
+
+RULE
+    :  R U L E
+    ;
+
+FROM
+    : F R O M
+    ;
+
+ENCRYPT
+    : E N C R Y P T
+    ;
+
+TYPE
+    : T Y P E
+    ;
+    
+NAME
+    : N A M E
+    ;
+
+PROPERTIES
+    : P R O P E R T I E S
+    ;
+
+COLUMN
+    : C O L U M N
+    ;
+
+RULES
+    : R U L E S
+    ;
+
+TABLE
+    : T A B L E
+    ;
+
+COLUMNS
+    : C O L U M N S
+    ;
+
+CIPHER
+    : C I P H E R
+    ;
+
+PLAIN
+    : P L A I N
     ;
diff --git 
a/shardingsphere-distsql-parser/shardingsphere-distsql-parser-engine/src/main/antlr4/imports/RQLStatement.g4
 
b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-distsql/src/main/antlr4/imports/encrypt/Literals.g4
similarity index 64%
copy from 
shardingsphere-distsql-parser/shardingsphere-distsql-parser-engine/src/main/antlr4/imports/RQLStatement.g4
copy to 
shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-distsql/src/main/antlr4/imports/encrypt/Literals.g4
index 81fcf28..e5f807b 100644
--- 
a/shardingsphere-distsql-parser/shardingsphere-distsql-parser-engine/src/main/antlr4/imports/RQLStatement.g4
+++ 
b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-distsql/src/main/antlr4/imports/encrypt/Literals.g4
@@ -15,26 +15,37 @@
  * limitations under the License.
  */
 
-grammar RQLStatement;
+lexer grammar Literals;
 
-import Keyword, Literals, Symbol;
+import Alphabet, Symbol;
 
-showResources
-    : SHOW RESOURCES (FROM schemaName)?
+IDENTIFIER
+    : [A-Za-z_$0-9]*?[A-Za-z_$]+?[A-Za-z_$0-9]*
+    | BQ ~'`'+ BQ
+    | (DQ ( '\\'. | '""' | ~('"'| '\\') )* DQ)
+    ;
+    
+STRING
+    : (DQ ('""' | ~('"'| '\\') )* DQ)
+    | (SQ ('\'\'' | ~('\'' | '\\'))* SQ)
     ;
 
-showEncryptRules
-    : SHOW ENCRYPT (TABLE tableRule | RULES) (FROM schemaName)?
+INT
+    : [0-9]+
     ;
 
-tableRule
-    : RULE tableName
+HEX
+    : [0-9a-fA-F]
     ;
 
-schemaName
-    : IDENTIFIER
+NUMBER
+    : INT? DOT? INT (E (PLUS | MINUS)? INT)?
     ;
 
-tableName
-    : IDENTIFIER
+HEXDIGIT
+    : '0x' HEX+ | 'X' SQ HEX+ SQ
+    ;
+    
+BITNUM
+    : '0b' ('0' | '1')+ | B SQ ('0' | '1')+ SQ
     ;
diff --git 
a/shardingsphere-distsql-parser/shardingsphere-distsql-parser-engine/src/main/antlr4/imports/RDLStatement.g4
 
b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-distsql/src/main/antlr4/imports/encrypt/RDLStatement.g4
similarity index 78%
copy from 
shardingsphere-distsql-parser/shardingsphere-distsql-parser-engine/src/main/antlr4/imports/RDLStatement.g4
copy to 
shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-distsql/src/main/antlr4/imports/encrypt/RDLStatement.g4
index f872891..a764b0e 100644
--- 
a/shardingsphere-distsql-parser/shardingsphere-distsql-parser-engine/src/main/antlr4/imports/RDLStatement.g4
+++ 
b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-distsql/src/main/antlr4/imports/encrypt/RDLStatement.g4
@@ -19,46 +19,6 @@ grammar RDLStatement;
 
 import Keyword, Literals, Symbol;
 
-addResource
-    : ADD RESOURCE dataSource (COMMA dataSource)*
-    ;
-
-dropResource
-    : DROP RESOURCE IDENTIFIER (COMMA IDENTIFIER)*
-    ;
-
-dataSource
-    : dataSourceName LP HOST EQ hostName COMMA PORT EQ port COMMA DB EQ dbName 
COMMA USER EQ user (COMMA PASSWORD EQ password)? RP
-    ;
-
-dataSourceName
-    : IDENTIFIER
-    ;
-
-hostName
-    : IDENTIFIER | ip
-    ;
-
-ip
-    : NUMBER+
-    ;
-
-port
-    : INT
-    ;
-
-dbName
-    : IDENTIFIER
-    ;
-
-user
-    : IDENTIFIER | NUMBER
-    ;
-
-password
-    : IDENTIFIER | INT | STRING
-    ;
-
 resourceName
     : IDENTIFIER
     ;
diff --git 
a/shardingsphere-distsql-parser/shardingsphere-distsql-parser-engine/src/main/antlr4/imports/RQLStatement.g4
 
b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-distsql/src/main/antlr4/imports/encrypt/RQLStatement.g4
similarity index 94%
copy from 
shardingsphere-distsql-parser/shardingsphere-distsql-parser-engine/src/main/antlr4/imports/RQLStatement.g4
copy to 
shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-distsql/src/main/antlr4/imports/encrypt/RQLStatement.g4
index 81fcf28..c393c22 100644
--- 
a/shardingsphere-distsql-parser/shardingsphere-distsql-parser-engine/src/main/antlr4/imports/RQLStatement.g4
+++ 
b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-distsql/src/main/antlr4/imports/encrypt/RQLStatement.g4
@@ -19,10 +19,6 @@ grammar RQLStatement;
 
 import Keyword, Literals, Symbol;
 
-showResources
-    : SHOW RESOURCES (FROM schemaName)?
-    ;
-
 showEncryptRules
     : SHOW ENCRYPT (TABLE tableRule | RULES) (FROM schemaName)?
     ;
diff --git 
a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-distsql/src/main/antlr4/imports/encrypt/Symbol.g4
 
b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-distsql/src/main/antlr4/imports/encrypt/Symbol.g4
new file mode 100644
index 0000000..a332bdd
--- /dev/null
+++ 
b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-distsql/src/main/antlr4/imports/encrypt/Symbol.g4
@@ -0,0 +1,61 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+lexer grammar Symbol;
+
+AND:                '&&';
+OR:                 '||';
+NOT:                '!';
+TILDE:              '~';
+VERTICALBAR:       '|';
+AMPERSAND:          '&';
+SIGNEDLEFTSHIFT:  '<<';
+SIGNEDRIGHTSHIFT: '>>';
+CARET:              '^';
+MOD:                '%';
+COLON:              ':';
+PLUS:               '+';
+MINUS:              '-';
+ASTERISK:           '*';
+SLASH:              '/';
+BACKSLASH:          '\\';
+DOT:                '.';
+DOTASTERISK:       '.*';
+SAFEEQ:            '<=>';
+DEQ:                '==';
+EQ:                 '=';
+NEQ:                '<>' | '!=';
+GT:                 '>';
+GTE:                '>=';
+LT:                 '<';
+LTE:                '<=';
+POUND:              '#';
+LP:                 '(';
+RP:                 ')';
+LBE:                '{';
+RBE:                '}';
+LBT:                '[';
+RBT:                ']';
+COMMA:              ',';
+DQ:                 '"';
+SQ :                '\'';
+BQ:                 '`';
+QUESTION:           '?';
+AT:                 '@';
+SEMI:               ';';
+JSONSEPARATOR:      '->>';
+UL:                 '_';
diff --git 
a/shardingsphere-distsql-parser/shardingsphere-distsql-parser-engine/src/main/antlr4/org/apache/shardingsphere/distsql/parser/autogen/DistSQLStatement.g4
 
b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-distsql/src/main/antlr4/org/apache/shardingsphere/distsql/parser/autogen/EncryptRuleStatement.g4
similarity index 73%
copy from 
shardingsphere-distsql-parser/shardingsphere-distsql-parser-engine/src/main/antlr4/org/apache/shardingsphere/distsql/parser/autogen/DistSQLStatement.g4
copy to 
shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-distsql/src/main/antlr4/org/apache/shardingsphere/distsql/parser/autogen/EncryptRuleStatement.g4
index d561f2f..a2fd2be 100644
--- 
a/shardingsphere-distsql-parser/shardingsphere-distsql-parser-engine/src/main/antlr4/org/apache/shardingsphere/distsql/parser/autogen/DistSQLStatement.g4
+++ 
b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-distsql/src/main/antlr4/org/apache/shardingsphere/distsql/parser/autogen/EncryptRuleStatement.g4
@@ -15,24 +15,14 @@
  * limitations under the License.
  */
 
-grammar DistSQLStatement;
+grammar EncryptRuleStatement;
 
-import Symbol, RDLStatement, RQLStatement, RALStatement;
+import Symbol, RDLStatement, RQLStatement;
 
 execute
-    : (addResource
-    | dropResource
-    | createEncryptRule
+    : (createEncryptRule
     | alterEncryptRule
     | dropEncryptRule
-    | showResources
     | showEncryptRules
-    | showScalingJobList
-    | showScalingJobStatus
-    | startScalingJob
-    | stopScalingJob
-    | dropScalingJob
-    | resetScalingJob
-    | checkScalingJob
     ) SEMI?
     ;
diff --git 
a/shardingsphere-distsql-parser/shardingsphere-distsql-parser-engine/src/main/antlr4/imports/RQLStatement.g4
 
b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-distsql/src/main/java/org/apache/shardingsphere/encrypt/distsql/parser/core/EncryptRuleLexer.java
similarity index 63%
copy from 
shardingsphere-distsql-parser/shardingsphere-distsql-parser-engine/src/main/antlr4/imports/RQLStatement.g4
copy to 
shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-distsql/src/main/java/org/apache/shardingsphere/encrypt/distsql/parser/core/EncryptRuleLexer.java
index 81fcf28..9d0616e 100644
--- 
a/shardingsphere-distsql-parser/shardingsphere-distsql-parser-engine/src/main/antlr4/imports/RQLStatement.g4
+++ 
b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-distsql/src/main/java/org/apache/shardingsphere/encrypt/distsql/parser/core/EncryptRuleLexer.java
@@ -15,26 +15,18 @@
  * limitations under the License.
  */
 
-grammar RQLStatement;
+package org.apache.shardingsphere.encrypt.distsql.parser.core;
 
-import Keyword, Literals, Symbol;
+import org.antlr.v4.runtime.CharStream;
+import 
org.apache.shardingsphere.distsql.parser.autogen.EncryptRuleStatementLexer;
+import org.apache.shardingsphere.sql.parser.api.parser.SQLLexer;
 
-showResources
-    : SHOW RESOURCES (FROM schemaName)?
-    ;
-
-showEncryptRules
-    : SHOW ENCRYPT (TABLE tableRule | RULES) (FROM schemaName)?
-    ;
-
-tableRule
-    : RULE tableName
-    ;
-
-schemaName
-    : IDENTIFIER
-    ;
-
-tableName
-    : IDENTIFIER
-    ;
+/**
+ * SQL lexer for encrypt rule.
+ */
+public final class EncryptRuleLexer extends EncryptRuleStatementLexer 
implements SQLLexer {
+    
+    public EncryptRuleLexer(final CharStream input) {
+        super(input);
+    }
+}
diff --git 
a/shardingsphere-distsql-parser/shardingsphere-distsql-parser-engine/src/main/antlr4/imports/RQLStatement.g4
 
b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-distsql/src/main/java/org/apache/shardingsphere/encrypt/distsql/parser/core/EncryptRuleParser.java
similarity index 53%
copy from 
shardingsphere-distsql-parser/shardingsphere-distsql-parser-engine/src/main/antlr4/imports/RQLStatement.g4
copy to 
shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-distsql/src/main/java/org/apache/shardingsphere/encrypt/distsql/parser/core/EncryptRuleParser.java
index 81fcf28..89393ee 100644
--- 
a/shardingsphere-distsql-parser/shardingsphere-distsql-parser-engine/src/main/antlr4/imports/RQLStatement.g4
+++ 
b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-distsql/src/main/java/org/apache/shardingsphere/encrypt/distsql/parser/core/EncryptRuleParser.java
@@ -15,26 +15,25 @@
  * limitations under the License.
  */
 
-grammar RQLStatement;
+package org.apache.shardingsphere.encrypt.distsql.parser.core;
 
-import Keyword, Literals, Symbol;
+import org.antlr.v4.runtime.TokenStream;
+import 
org.apache.shardingsphere.distsql.parser.autogen.EncryptRuleStatementParser;
+import org.apache.shardingsphere.sql.parser.api.parser.SQLParser;
+import org.apache.shardingsphere.sql.parser.api.visitor.ASTNode;
+import org.apache.shardingsphere.sql.parser.core.ParseASTNode;
 
-showResources
-    : SHOW RESOURCES (FROM schemaName)?
-    ;
-
-showEncryptRules
-    : SHOW ENCRYPT (TABLE tableRule | RULES) (FROM schemaName)?
-    ;
-
-tableRule
-    : RULE tableName
-    ;
-
-schemaName
-    : IDENTIFIER
-    ;
-
-tableName
-    : IDENTIFIER
-    ;
+/**
+ * SQL parser for encrypt rule.
+ */
+public final class EncryptRuleParser extends EncryptRuleStatementParser 
implements SQLParser {
+    
+    public EncryptRuleParser(final TokenStream input) {
+        super(input);
+    }
+    
+    @Override
+    public ASTNode parse() {
+        return new ParseASTNode(execute());
+    }
+}
diff --git 
a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-distsql/src/main/java/org/apache/shardingsphere/encrypt/distsql/parser/core/EncryptRuleSQLStatementVisitor.java
 
b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-distsql/src/main/java/org/apache/shardingsphere/encrypt/distsql/parser/core/EncryptRuleSQLStatementVisitor.java
new file mode 100644
index 0000000..baace3f
--- /dev/null
+++ 
b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-distsql/src/main/java/org/apache/shardingsphere/encrypt/distsql/parser/core/EncryptRuleSQLStatementVisitor.java
@@ -0,0 +1,115 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.encrypt.distsql.parser.core;
+
+import org.antlr.v4.runtime.tree.TerminalNode;
+import 
org.apache.shardingsphere.distsql.parser.autogen.EncryptRuleStatementBaseVisitor;
+import 
org.apache.shardingsphere.distsql.parser.autogen.EncryptRuleStatementParser.AlgorithmPropertyContext;
+import 
org.apache.shardingsphere.distsql.parser.autogen.EncryptRuleStatementParser.AlterEncryptRuleContext;
+import 
org.apache.shardingsphere.distsql.parser.autogen.EncryptRuleStatementParser.ColumnDefinitionContext;
+import 
org.apache.shardingsphere.distsql.parser.autogen.EncryptRuleStatementParser.CreateEncryptRuleContext;
+import 
org.apache.shardingsphere.distsql.parser.autogen.EncryptRuleStatementParser.DropEncryptRuleContext;
+import 
org.apache.shardingsphere.distsql.parser.autogen.EncryptRuleStatementParser.EncryptRuleDefinitionContext;
+import 
org.apache.shardingsphere.distsql.parser.autogen.EncryptRuleStatementParser.FunctionDefinitionContext;
+import 
org.apache.shardingsphere.distsql.parser.autogen.EncryptRuleStatementParser.SchemaNameContext;
+import 
org.apache.shardingsphere.distsql.parser.autogen.EncryptRuleStatementParser.ShowEncryptRulesContext;
+import 
org.apache.shardingsphere.distsql.parser.autogen.EncryptRuleStatementParser.TableNameContext;
+import org.apache.shardingsphere.distsql.parser.segment.FunctionSegment;
+import 
org.apache.shardingsphere.distsql.parser.segment.rdl.EncryptColumnSegment;
+import org.apache.shardingsphere.distsql.parser.segment.rdl.EncryptRuleSegment;
+import 
org.apache.shardingsphere.distsql.parser.statement.rdl.alter.impl.AlterEncryptRuleStatement;
+import 
org.apache.shardingsphere.distsql.parser.statement.rdl.create.impl.CreateEncryptRuleStatement;
+import 
org.apache.shardingsphere.distsql.parser.statement.rdl.drop.impl.DropEncryptRuleStatement;
+import 
org.apache.shardingsphere.distsql.parser.statement.rql.show.impl.ShowEncryptRulesStatement;
+import org.apache.shardingsphere.sql.parser.api.visitor.ASTNode;
+import org.apache.shardingsphere.sql.parser.api.visitor.SQLVisitor;
+import 
org.apache.shardingsphere.sql.parser.sql.common.segment.generic.SchemaSegment;
+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.Objects;
+import java.util.Properties;
+import java.util.stream.Collectors;
+
+/**
+ * SQL statement visitor for encrypt rule.
+ */
+public final class EncryptRuleSQLStatementVisitor extends 
EncryptRuleStatementBaseVisitor<ASTNode> implements SQLVisitor {
+    
+    @Override
+    public ASTNode visitCreateEncryptRule(final CreateEncryptRuleContext ctx) {
+        return new 
CreateEncryptRuleStatement(ctx.encryptRuleDefinition().stream().map(each -> 
(EncryptRuleSegment) visit(each)).collect(Collectors.toList()));
+    }
+    
+    @Override
+    public ASTNode visitEncryptRuleDefinition(final 
EncryptRuleDefinitionContext ctx) {
+        return new EncryptRuleSegment(ctx.tableName().getText(), 
ctx.columnDefinition().stream().map(each -> (EncryptColumnSegment) 
visit(each)).collect(Collectors.toList()));
+    }
+    
+    @Override
+    public ASTNode visitColumnDefinition(final ColumnDefinitionContext ctx) {
+        EncryptColumnSegment result = new EncryptColumnSegment();
+        result.setName(ctx.columnName().getText());
+        result.setCipherColumn(ctx.cipherColumnName().getText());
+        if (Objects.nonNull(ctx.plainColumnName())) {
+            result.setPlainColumn(ctx.plainColumnName().getText());
+        }
+        result.setEncryptor((FunctionSegment) visit(ctx.functionDefinition()));
+        return result;
+    }
+    
+    @Override
+    public ASTNode visitAlterEncryptRule(final AlterEncryptRuleContext ctx) {
+        return new 
AlterEncryptRuleStatement(ctx.encryptRuleDefinition().stream().map(each -> 
(EncryptRuleSegment) visit(each)).collect(Collectors.toList()));
+    }
+    
+    @Override
+    public ASTNode visitDropEncryptRule(final DropEncryptRuleContext ctx) {
+        return new 
DropEncryptRuleStatement(ctx.IDENTIFIER().stream().map(TerminalNode::getText).collect(Collectors.toList()));
+    }
+    
+    @Override
+    public ASTNode visitShowEncryptRules(final ShowEncryptRulesContext ctx) {
+        return new ShowEncryptRulesStatement(Objects.nonNull(ctx.tableRule()) 
? ctx.tableRule().tableName().getText() : null,
+                Objects.nonNull(ctx.schemaName()) ? (SchemaSegment) 
visit(ctx.schemaName()) : null);
+    }
+    
+    @Override
+    public ASTNode visitFunctionDefinition(final FunctionDefinitionContext 
ctx) {
+        FunctionSegment result = new FunctionSegment();
+        result.setAlgorithmName(ctx.functionName().getText());
+        Properties algorithmProps = new Properties();
+        if (null != ctx.algorithmProperties()) {
+            for (AlgorithmPropertyContext each : 
ctx.algorithmProperties().algorithmProperty()) {
+                algorithmProps.setProperty(new 
IdentifierValue(each.key.getText()).getValue(), new 
IdentifierValue(each.value.getText()).getValue());
+            }
+        }
+        result.setAlgorithmProps(algorithmProps);
+        return result;
+    }
+    
+    @Override
+    public ASTNode visitTableName(final TableNameContext ctx) {
+        return new TableNameSegment(ctx.getStart().getStartIndex(), 
ctx.getStop().getStopIndex(), new IdentifierValue(ctx.getText()));
+    }
+    
+    @Override
+    public ASTNode visitSchemaName(final SchemaNameContext ctx) {
+        return new SchemaSegment(ctx.getStart().getStartIndex(), 
ctx.getStop().getStopIndex(), new IdentifierValue(ctx.getText()));
+    }
+}
diff --git 
a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-distsql/src/main/java/org/apache/shardingsphere/encrypt/distsql/parser/facade/EncryptRuleSQLStatementParserFacade.java
 
b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-distsql/src/main/java/org/apache/shardingsphere/encrypt/distsql/parser/facade/EncryptRuleSQLStatementParserFacade.java
new file mode 100644
index 0000000..61835ab
--- /dev/null
+++ 
b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-distsql/src/main/java/org/apache/shardingsphere/encrypt/distsql/parser/facade/EncryptRuleSQLStatementParserFacade.java
@@ -0,0 +1,52 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.encrypt.distsql.parser.facade;
+
+import 
org.apache.shardingsphere.distsql.parser.spi.RuleSQLStatementParserFacade;
+import org.apache.shardingsphere.encrypt.distsql.parser.core.EncryptRuleLexer;
+import org.apache.shardingsphere.encrypt.distsql.parser.core.EncryptRuleParser;
+import 
org.apache.shardingsphere.encrypt.distsql.parser.core.EncryptRuleSQLStatementVisitor;
+import org.apache.shardingsphere.sql.parser.api.parser.SQLLexer;
+import org.apache.shardingsphere.sql.parser.api.parser.SQLParser;
+import org.apache.shardingsphere.sql.parser.api.visitor.SQLVisitor;
+
+/**
+ * SQL parser facade for encrypt rule SQL statement.
+ */
+public final class EncryptRuleSQLStatementParserFacade implements 
RuleSQLStatementParserFacade {
+    
+    @Override
+    public Class<? extends SQLLexer> getLexerClass() {
+        return EncryptRuleLexer.class;
+    }
+    
+    @Override
+    public Class<? extends SQLParser> getParserClass() {
+        return EncryptRuleParser.class;
+    }
+    
+    @Override
+    public Class<? extends SQLVisitor> getVisitorClass() {
+        return EncryptRuleSQLStatementVisitor.class;
+    }
+    
+    @Override
+    public String getRuleType() {
+        return "encrypt";
+    }
+}
diff --git 
a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-distsql/src/main/resources/META-INF/services/org.apache.shardingsphere.distsql.parser.spi.RuleSQLStatementParserFacade
 
b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-distsql/src/main/resources/META-INF/services/org.apache.shardingsphere.distsql.parser.spi.RuleSQLStatementParserFacade
new file mode 100644
index 0000000..bcc34d0
--- /dev/null
+++ 
b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-distsql/src/main/resources/META-INF/services/org.apache.shardingsphere.distsql.parser.spi.RuleSQLStatementParserFacade
@@ -0,0 +1,18 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+org.apache.shardingsphere.encrypt.distsql.parser.facade.EncryptRuleSQLStatementParserFacade
diff --git 
a/shardingsphere-distsql-parser/shardingsphere-distsql-parser-engine/src/test/java/org/apache/shardingsphere/distsql/parser/api/DistSQLStatementParserEngineTest.java
 
b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-distsql/src/test/java/org/apache/shardingsphere/encrypt/distsql/parser/core/EncryptRuleStatementParserEngineTest.java
similarity index 62%
copy from 
shardingsphere-distsql-parser/shardingsphere-distsql-parser-engine/src/test/java/org/apache/shardingsphere/distsql/parser/api/DistSQLStatementParserEngineTest.java
copy to 
shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-distsql/src/test/java/org/apache/shardingsphere/encrypt/distsql/parser/core/EncryptRuleStatementParserEngineTest.java
index f5041f2..9d63aab 100644
--- 
a/shardingsphere-distsql-parser/shardingsphere-distsql-parser-engine/src/test/java/org/apache/shardingsphere/distsql/parser/api/DistSQLStatementParserEngineTest.java
+++ 
b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-distsql/src/test/java/org/apache/shardingsphere/encrypt/distsql/parser/core/EncryptRuleStatementParserEngineTest.java
@@ -15,15 +15,13 @@
  * limitations under the License.
  */
 
-package org.apache.shardingsphere.distsql.parser.api;
+package org.apache.shardingsphere.encrypt.distsql.parser.core;
 
-import org.apache.shardingsphere.distsql.parser.segment.DataSourceSegment;
+import 
org.apache.shardingsphere.distsql.parser.api.DistSQLStatementParserEngine;
 import 
org.apache.shardingsphere.distsql.parser.segment.rdl.EncryptColumnSegment;
 import org.apache.shardingsphere.distsql.parser.segment.rdl.EncryptRuleSegment;
 import 
org.apache.shardingsphere.distsql.parser.statement.rdl.alter.impl.AlterEncryptRuleStatement;
-import 
org.apache.shardingsphere.distsql.parser.statement.rdl.create.AddResourceStatement;
 import 
org.apache.shardingsphere.distsql.parser.statement.rdl.create.impl.CreateEncryptRuleStatement;
-import 
org.apache.shardingsphere.distsql.parser.statement.rdl.drop.DropResourceStatement;
 import 
org.apache.shardingsphere.distsql.parser.statement.rdl.drop.impl.DropEncryptRuleStatement;
 import 
org.apache.shardingsphere.distsql.parser.statement.rql.show.impl.ShowEncryptRulesStatement;
 import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement;
@@ -39,16 +37,7 @@ import static org.junit.Assert.assertThat;
 import static org.junit.Assert.assertTrue;
 
 // TODO use Parameterized + XML instead of static test
-public final class DistSQLStatementParserEngineTest {
-    
-    private static final String ADD_RESOURCE_SINGLE_WITHOUT_PASSWORD = "ADD 
RESOURCE ds_0(HOST=127.0.0.1,PORT=3306,DB=test0,USER=ROOT);";
-    
-    private static final String ADD_RESOURCE_SINGLE_WITH_PASSWORD = "ADD 
RESOURCE ds_0(HOST=127.0.0.1,PORT=3306,DB=test0,USER=ROOT,PASSWORD=123456);";
-    
-    private static final String ADD_RESOURCE_MULTIPLE = "ADD RESOURCE 
ds_0(HOST=127.0.0.1,PORT=3306,DB=test0,USER=ROOT,PASSWORD=123456),"
-            + 
"ds_1(HOST=127.0.0.1,PORT=3306,DB=test1,USER=ROOT,PASSWORD=123456);";
-    
-    private static final String DROP_RESOURCE = "DROP RESOURCE ds_0,ds_1";
+public final class EncryptRuleStatementParserEngineTest {
     
     private static final String CREATE_ENCRYPT_RULE = "CREATE ENCRYPT RULE 
t_encrypt ("
             + "COLUMNS("
@@ -71,63 +60,6 @@ public final class DistSQLStatementParserEngineTest {
     private final DistSQLStatementParserEngine engine = new 
DistSQLStatementParserEngine();
     
     @Test
-    public void assertParseAddSingleResourceWithoutPassword() {
-        SQLStatement sqlStatement = 
engine.parse(ADD_RESOURCE_SINGLE_WITHOUT_PASSWORD);
-        assertTrue(sqlStatement instanceof AddResourceStatement);
-        assertThat(((AddResourceStatement) 
sqlStatement).getDataSources().size(), is(1));
-        DataSourceSegment dataSourceSegment = ((AddResourceStatement) 
sqlStatement).getDataSources().iterator().next();
-        assertThat(dataSourceSegment.getName(), is("ds_0"));
-        assertThat(dataSourceSegment.getHostName(), is("127.0.0.1"));
-        assertThat(dataSourceSegment.getPort(), is("3306"));
-        assertThat(dataSourceSegment.getDb(), is("test0"));
-        assertThat(dataSourceSegment.getUser(), is("ROOT"));
-    }
-    
-    @Test
-    public void assertParseAddSingleResourceWithPassword() {
-        SQLStatement sqlStatement = 
engine.parse(ADD_RESOURCE_SINGLE_WITH_PASSWORD);
-        assertTrue(sqlStatement instanceof AddResourceStatement);
-        assertThat(((AddResourceStatement) 
sqlStatement).getDataSources().size(), is(1));
-        DataSourceSegment dataSourceSegment = ((AddResourceStatement) 
sqlStatement).getDataSources().iterator().next();
-        assertThat(dataSourceSegment.getName(), is("ds_0"));
-        assertThat(dataSourceSegment.getHostName(), is("127.0.0.1"));
-        assertThat(dataSourceSegment.getPort(), is("3306"));
-        assertThat(dataSourceSegment.getDb(), is("test0"));
-        assertThat(dataSourceSegment.getUser(), is("ROOT"));
-        assertThat(dataSourceSegment.getPassword(), is("123456"));
-    }
-    
-    @Test
-    public void assertParseAddMultipleResources() {
-        SQLStatement sqlStatement = engine.parse(ADD_RESOURCE_MULTIPLE);
-        assertTrue(sqlStatement instanceof AddResourceStatement);
-        assertThat(((AddResourceStatement) 
sqlStatement).getDataSources().size(), is(2));
-        List<DataSourceSegment> dataSourceSegments = new 
ArrayList<>(((AddResourceStatement) sqlStatement).getDataSources());
-        DataSourceSegment dataSourceSegment = dataSourceSegments.get(0);
-        assertThat(dataSourceSegment.getName(), is("ds_0"));
-        assertThat(dataSourceSegment.getHostName(), is("127.0.0.1"));
-        assertThat(dataSourceSegment.getPort(), is("3306"));
-        assertThat(dataSourceSegment.getDb(), is("test0"));
-        assertThat(dataSourceSegment.getUser(), is("ROOT"));
-        assertThat(dataSourceSegment.getPassword(), is("123456"));
-        dataSourceSegment = dataSourceSegments.get(1);
-        assertThat(dataSourceSegment.getName(), is("ds_1"));
-        assertThat(dataSourceSegment.getHostName(), is("127.0.0.1"));
-        assertThat(dataSourceSegment.getPort(), is("3306"));
-        assertThat(dataSourceSegment.getDb(), is("test1"));
-        assertThat(dataSourceSegment.getUser(), is("ROOT"));
-        assertThat(dataSourceSegment.getPassword(), is("123456"));
-    }
-    
-    @Test
-    public void assertParseDropResource() {
-        SQLStatement sqlStatement = engine.parse(DROP_RESOURCE);
-        assertTrue(sqlStatement instanceof DropResourceStatement);
-        assertThat(((DropResourceStatement) sqlStatement).getNames().size(), 
is(2));
-        assertTrue(((DropResourceStatement) 
sqlStatement).getNames().containsAll(Arrays.asList("ds_0", "ds_1")));
-    }
-    
-    @Test
     public void assertParseCreateEncryptRule() {
         SQLStatement sqlStatement = engine.parse(CREATE_ENCRYPT_RULE);
         assertTrue(sqlStatement instanceof CreateEncryptRuleStatement);

Reply via email to