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

wuweijie 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 232647c  Split db-discovery ANTLR g4 file and visitor (#10815)
232647c is described below

commit 232647c37ff042ee279881ce7d13a7293171678d
Author: Liang Zhang <[email protected]>
AuthorDate: Tue Jun 15 17:04:44 2021 +0800

    Split db-discovery ANTLR g4 file and visitor (#10815)
    
    * Split g4 file for db-discovery
    
    * Split g4 file for db-discovery
    
    * Split g4 file for db-discovery
    
    * Fix code format
---
 .../src/main/antlr4/imports/Keyword.g4             |  26 +----
 .../src/main/antlr4/imports/RDLStatement.g4        |  24 -----
 .../src/main/antlr4/imports/RQLStatement.g4        |   4 -
 .../distsql/parser/autogen/DistSQLStatement.g4     |   4 -
 .../resource/ResourceDistSQLStatementVisitor.java  |  49 ---------
 .../api/DistSQLStatementParserEngineTest.java      |  74 --------------
 .../shardingsphere-db-discovery/pom.xml            |   3 +-
 .../shardingsphere-db-discovery-core/pom.xml       |   5 +
 .../pom.xml                                        |  47 +++++----
 .../main/antlr4/imports/db-discovery/Alphabet.g4   |  58 ++++++-----
 .../main/antlr4/imports/db-discovery}/Keyword.g4   |  26 ++---
 .../main/antlr4/imports/db-discovery/Literals.g4   |  37 ++++---
 .../antlr4/imports/db-discovery}/RDLStatement.g4   |  80 ---------------
 .../antlr4/imports/db-discovery}/RQLStatement.g4   |  16 ---
 .../src/main/antlr4/imports/db-discovery/Symbol.g4 |  61 ++++++++++++
 .../autogen/DatabaseDiscoveryRuleStatement.g4      |  20 +---
 .../parser/core/DatabaseDiscoveryRuleLexer.java    |  38 +++----
 .../parser/core/DatabaseDiscoveryRuleParser.java}  |  77 ++++-----------
 .../DatabaseDiscoveryRuleSQLStatementVisitor.java  | 107 ++++++++++++++++++++
 ...baseDiscoveryRuleSQLStatementParserFacade.java} |  20 ++--
 ...distsql.parser.spi.RuleSQLStatementParserFacade |   2 +-
 ...baseDiscoveryRuleStatementParserEngineTest.java | 110 +++++++++++++++++++++
 .../antlr4/imports/readwrite-splitting/Keyword.g4  |   4 +-
 ...ReadwriteSplittingRuleSQLStatementVisitor.java} |   2 +-
 ...riteSplittingRuleSQLStatementParserFacade.java} |  10 +-
 ...distsql.parser.spi.RuleSQLStatementParserFacade |   2 +-
 .../src/main/antlr4/imports/sharding/Keyword.g4    |   6 +-
 ...r.java => ShardingRuleSQLStatementVisitor.java} |   2 +-
 ...a => ShardingRuleSQLStatementParserFacade.java} |  10 +-
 ...distsql.parser.spi.RuleSQLStatementParserFacade |   2 +-
 30 files changed, 439 insertions(+), 487 deletions(-)

diff --git 
a/shardingsphere-distsql-parser/shardingsphere-distsql-parser-engine/src/main/antlr4/imports/Keyword.g4
 
b/shardingsphere-distsql-parser/shardingsphere-distsql-parser-engine/src/main/antlr4/imports/Keyword.g4
index e36cc59..95296f9 100644
--- 
a/shardingsphere-distsql-parser/shardingsphere-distsql-parser-engine/src/main/antlr4/imports/Keyword.g4
+++ 
b/shardingsphere-distsql-parser/shardingsphere-distsql-parser-engine/src/main/antlr4/imports/Keyword.g4
@@ -75,26 +75,6 @@ FROM
     : F R O M
     ;
 
-SHARDING
-    : S H A R D I N G
-    ;
-
-READWRITE_SPLITTING
-    : R E A D W R I T E UL_ S P L I T T I N G
-    ;
-
-WRITE_RESOURCE
-    : W R I T E UL_ R E S O U R C E
-    ;
-
-READ_RESOURCES
-    : R E A D UL_ R E S O U R C E S
-    ;
-
-AUTO_AWARE_RESOURCE
-    : A U T O UL_ A W A R E UL_ R E S O U R C E
-    ;
-
 ENCRYPT
     : E N C R Y P T
     ;
@@ -154,7 +134,7 @@ NAME
 PROPERTIES
     : P R O P E R T I E S
     ;
-    
+
 COLUMN
     : C O L U M N
     ;
@@ -163,10 +143,6 @@ RULES
     : R U L E S
     ;
 
-DB_DISCOVERY
-    : D B UL_ D I S C O V E R Y
-    ;
-
 COLUMNS
     : C O L U M N S
     ;
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 a6e48a2..f872891 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
@@ -59,18 +59,10 @@ password
     : IDENTIFIER | INT | STRING
     ;
 
-resources
-    : RESOURCES LP IDENTIFIER (COMMA IDENTIFIER)* RP
-    ;
-
 resourceName
     : IDENTIFIER
     ;
 
-ruleName
-    : IDENTIFIER
-    ;
-
 tableName
     : IDENTIFIER
     ;
@@ -95,22 +87,6 @@ algorithmProperty
     : key=(IDENTIFIER | STRING) EQ value=(NUMBER | INT | STRING)
     ;
 
-createDatabaseDiscoveryRule
-    : CREATE DB_DISCOVERY RULE databaseDiscoveryRuleDefinition  (COMMA 
databaseDiscoveryRuleDefinition)*
-    ;
-
-databaseDiscoveryRuleDefinition
-    : ruleName LP resources COMMA functionDefinition RP
-    ;
-
-alterDatabaseDiscoveryRule
-    : ALTER DB_DISCOVERY RULE databaseDiscoveryRuleDefinition  (COMMA 
databaseDiscoveryRuleDefinition)*
-    ;
-
-dropDatabaseDiscoveryRule
-    : DROP DB_DISCOVERY RULE IDENTIFIER (COMMA IDENTIFIER)*
-    ;
-
 createEncryptRule
     : CREATE ENCRYPT RULE encryptRuleDefinition (COMMA encryptRuleDefinition)*
     ;
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 ae555b4..81fcf28 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,10 +23,6 @@ showResources
     : SHOW RESOURCES (FROM schemaName)?
     ;
 
-showDatabaseDiscoveryRules
-    : SHOW DB_DISCOVERY RULES (FROM schemaName)?
-    ;
-
 showEncryptRules
     : SHOW ENCRYPT (TABLE tableRule | RULES) (FROM schemaName)?
     ;
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 c857a31..d561f2f 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,14 +22,10 @@ import Symbol, RDLStatement, RQLStatement, RALStatement;
 execute
     : (addResource
     | dropResource
-    | createDatabaseDiscoveryRule
-    | alterDatabaseDiscoveryRule
-    | dropDatabaseDiscoveryRule
     | createEncryptRule
     | alterEncryptRule
     | dropEncryptRule
     | showResources
-    | showDatabaseDiscoveryRules
     | showEncryptRules
     | showScalingJobList
     | showScalingJobStatus
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 28d6498..557006a 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
@@ -21,17 +21,12 @@ 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.AlgorithmPropertiesContext;
 import 
org.apache.shardingsphere.distsql.parser.autogen.DistSQLStatementParser.AlgorithmPropertyContext;
-import 
org.apache.shardingsphere.distsql.parser.autogen.DistSQLStatementParser.AlterDatabaseDiscoveryRuleContext;
 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.CreateDatabaseDiscoveryRuleContext;
 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.DatabaseDiscoveryRuleDefinitionContext;
-import 
org.apache.shardingsphere.distsql.parser.autogen.DistSQLStatementParser.DropDatabaseDiscoveryRuleContext;
 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;
@@ -39,7 +34,6 @@ import 
org.apache.shardingsphere.distsql.parser.autogen.DistSQLStatementParser.E
 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.ShowDatabaseDiscoveryRulesContext;
 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;
@@ -49,7 +43,6 @@ import 
org.apache.shardingsphere.distsql.parser.autogen.DistSQLStatementParser.S
 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.DatabaseDiscoveryRuleSegment;
 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;
@@ -59,16 +52,12 @@ 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.AlterDatabaseDiscoveryRuleStatement;
 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.CreateDatabaseDiscoveryRuleStatement;
 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.DropDatabaseDiscoveryRuleStatement;
 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.ShowDatabaseDiscoveryRulesStatement;
 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;
@@ -122,31 +111,6 @@ public final class ResourceDistSQLStatementVisitor extends 
DistSQLStatementBaseV
     }
     
     @Override
-    public ASTNode visitCreateDatabaseDiscoveryRule(final 
CreateDatabaseDiscoveryRuleContext ctx) {
-        return new 
CreateDatabaseDiscoveryRuleStatement(ctx.databaseDiscoveryRuleDefinition().stream().map(each
 -> (DatabaseDiscoveryRuleSegment) visit(each)).collect(Collectors.toList()));
-    }
-    
-    @Override
-    public ASTNode visitDatabaseDiscoveryRuleDefinition(final 
DatabaseDiscoveryRuleDefinitionContext ctx) {
-        DatabaseDiscoveryRuleSegment result = new 
DatabaseDiscoveryRuleSegment();
-        result.setName(ctx.ruleName().getText());
-        result.setDataSources(ctx.resources().IDENTIFIER().stream().map(each 
-> new 
IdentifierValue(each.getText()).getValue()).collect(Collectors.toList()));
-        
result.setDiscoveryTypeName(ctx.functionDefinition().functionName().getText());
-        
result.setProps(buildAlgorithmProperties(ctx.functionDefinition().algorithmProperties()));
-        return result;
-    }
-    
-    @Override
-    public ASTNode visitAlterDatabaseDiscoveryRule(final 
AlterDatabaseDiscoveryRuleContext ctx) {
-        return new 
AlterDatabaseDiscoveryRuleStatement(ctx.databaseDiscoveryRuleDefinition().stream().map(each
 -> (DatabaseDiscoveryRuleSegment) visit(each)).collect(Collectors.toList()));
-    }
-    
-    @Override
-    public ASTNode visitDropDatabaseDiscoveryRule(final 
DropDatabaseDiscoveryRuleContext ctx) {
-        return new 
DropDatabaseDiscoveryRuleStatement(ctx.IDENTIFIER().stream().map(TerminalNode::getText).collect(Collectors.toList()));
-    }
-    
-    @Override
     public ASTNode visitCreateEncryptRule(final CreateEncryptRuleContext ctx) {
         return new 
CreateEncryptRuleStatement(ctx.encryptRuleDefinition().stream().map(each -> 
(EncryptRuleSegment) visit(each)).collect(Collectors.toList()));
     }
@@ -219,11 +183,6 @@ public final class ResourceDistSQLStatementVisitor extends 
DistSQLStatementBaseV
     }
     
     @Override
-    public ASTNode visitShowDatabaseDiscoveryRules(final 
ShowDatabaseDiscoveryRulesContext ctx) {
-        return new 
ShowDatabaseDiscoveryRulesStatement(Objects.nonNull(ctx.schemaName()) ? 
(SchemaSegment) visit(ctx.schemaName()) : null);
-    }
-    
-    @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);
@@ -238,12 +197,4 @@ public final class ResourceDistSQLStatementVisitor extends 
DistSQLStatementBaseV
     public ASTNode visitCheckScalingJob(final CheckScalingJobContext ctx) {
         return new 
CheckScalingJobStatement(Long.parseLong(ctx.jobId().getText()));
     }
-    
-    private Properties buildAlgorithmProperties(final 
AlgorithmPropertiesContext ctx) {
-        Properties result = new Properties();
-        for (AlgorithmPropertyContext each : ctx.algorithmProperty()) {
-            result.setProperty(new 
IdentifierValue(each.key.getText()).getValue(), new 
IdentifierValue(each.value.getText()).getValue());
-        }
-        return result;
-    }
 }
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 779a2fd..f5041f2 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,18 +18,13 @@
 package org.apache.shardingsphere.distsql.parser.api;
 
 import org.apache.shardingsphere.distsql.parser.segment.DataSourceSegment;
-import 
org.apache.shardingsphere.distsql.parser.segment.rdl.DatabaseDiscoveryRuleSegment;
 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.AlterDatabaseDiscoveryRuleStatement;
 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.CreateDatabaseDiscoveryRuleStatement;
 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.DropDatabaseDiscoveryRuleStatement;
 import 
org.apache.shardingsphere.distsql.parser.statement.rdl.drop.impl.DropEncryptRuleStatement;
-import 
org.apache.shardingsphere.distsql.parser.statement.rql.show.impl.ShowDatabaseDiscoveryRulesStatement;
 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;
@@ -55,24 +50,6 @@ public final class DistSQLStatementParserEngineTest {
     
     private static final String DROP_RESOURCE = "DROP RESOURCE ds_0,ds_1";
     
-    private static final String CREATE_DATABASE_DISCOVERY_RULE = "CREATE 
DB_DISCOVERY RULE ha_group_0 ("
-            + "RESOURCES(resource0,resource1),"
-            + 
"TYPE(NAME=mgr,PROPERTIES(groupName='92504d5b-6dec',keepAliveCron=''))),"
-            + "ha_group_1 ("
-            + "RESOURCES(resource2,resource3),"
-            + 
"TYPE(NAME=mgr2,PROPERTIES(groupName='92504d5b-6dec-2',keepAliveCron=''))"
-            + ")";
-    
-    private static final String ALTER_DATABASE_DISCOVERY_RULE = "ALTER 
DB_DISCOVERY RULE ha_group_0 ("
-            + "RESOURCES(resource0,resource1),"
-            + 
"TYPE(NAME=mgr,PROPERTIES(groupName='92504d5b-6dec',keepAliveCron=''))),"
-            + "ha_group_1 ("
-            + "RESOURCES(resource2,resource3),"
-            + 
"TYPE(NAME=mgr2,PROPERTIES(groupName='92504d5b-6dec-2',keepAliveCron=''))"
-            + ")";
-    
-    private static final String DROP_DATABASE_DISCOVERY_RULE = "DROP 
DB_DISCOVERY RULE ha_group_0,ha_group_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'))),"
@@ -87,8 +64,6 @@ public final class DistSQLStatementParserEngineTest {
     
     private static final String DROP_ENCRYPT_RULE = "DROP ENCRYPT RULE 
t_encrypt,t_encrypt_order";
     
-    private static final String SHOW_DB_DISCOVERY_RULES = "SHOW DB_DISCOVERY 
RULES FROM db_discovery_db";
-    
     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";
@@ -153,48 +128,6 @@ public final class DistSQLStatementParserEngineTest {
     }
     
     @Test
-    public void assertParseCreateDatabaseDiscoveryRule() {
-        SQLStatement sqlStatement = 
engine.parse(CREATE_DATABASE_DISCOVERY_RULE);
-        assertTrue(sqlStatement instanceof 
CreateDatabaseDiscoveryRuleStatement);
-        CreateDatabaseDiscoveryRuleStatement statement = 
(CreateDatabaseDiscoveryRuleStatement) sqlStatement;
-        assertThat(statement.getRules().size(), is(2));
-        List<DatabaseDiscoveryRuleSegment> databaseDiscoveryRuleSegments
-                = new ArrayList<>(((CreateDatabaseDiscoveryRuleStatement) 
sqlStatement).getRules());
-        assertThat(databaseDiscoveryRuleSegments.get(0).getName(), 
is("ha_group_0"));
-        
assertThat(databaseDiscoveryRuleSegments.get(0).getDiscoveryTypeName(), 
is("mgr"));
-        assertThat(databaseDiscoveryRuleSegments.get(0).getDataSources(), 
is(Arrays.asList("resource0", "resource1")));
-        
assertThat(databaseDiscoveryRuleSegments.get(0).getProps().get("groupName"), 
is("92504d5b-6dec"));
-        assertThat(databaseDiscoveryRuleSegments.get(1).getName(), 
is("ha_group_1"));
-        
assertThat(databaseDiscoveryRuleSegments.get(1).getDiscoveryTypeName(), 
is("mgr2"));
-        assertThat(databaseDiscoveryRuleSegments.get(1).getDataSources(), 
is(Arrays.asList("resource2", "resource3")));
-        
assertThat(databaseDiscoveryRuleSegments.get(1).getProps().get("groupName"), 
is("92504d5b-6dec-2"));
-    }
-    
-    @Test
-    public void assertParseAlterDatabaseDiscoveryRule() {
-        SQLStatement sqlStatement = 
engine.parse(ALTER_DATABASE_DISCOVERY_RULE);
-        assertTrue(sqlStatement instanceof 
AlterDatabaseDiscoveryRuleStatement);
-        AlterDatabaseDiscoveryRuleStatement statement = 
(AlterDatabaseDiscoveryRuleStatement) sqlStatement;
-        assertThat(statement.getRules().size(), is(2));
-        List<DatabaseDiscoveryRuleSegment> databaseDiscoveryRuleSegments = new 
ArrayList<>(((AlterDatabaseDiscoveryRuleStatement) sqlStatement).getRules());
-        assertThat(databaseDiscoveryRuleSegments.get(0).getName(), 
is("ha_group_0"));
-        
assertThat(databaseDiscoveryRuleSegments.get(0).getDiscoveryTypeName(), 
is("mgr"));
-        assertThat(databaseDiscoveryRuleSegments.get(0).getDataSources(), 
is(Arrays.asList("resource0", "resource1")));
-        
assertThat(databaseDiscoveryRuleSegments.get(0).getProps().get("groupName"), 
is("92504d5b-6dec"));
-        assertThat(databaseDiscoveryRuleSegments.get(1).getName(), 
is("ha_group_1"));
-        
assertThat(databaseDiscoveryRuleSegments.get(1).getDiscoveryTypeName(), 
is("mgr2"));
-        assertThat(databaseDiscoveryRuleSegments.get(1).getDataSources(), 
is(Arrays.asList("resource2", "resource3")));
-        
assertThat(databaseDiscoveryRuleSegments.get(1).getProps().get("groupName"), 
is("92504d5b-6dec-2"));
-    }
-    
-    @Test
-    public void assertParseDropDatabaseDiscoveryRule() {
-        SQLStatement sqlStatement = engine.parse(DROP_DATABASE_DISCOVERY_RULE);
-        assertTrue(sqlStatement instanceof DropDatabaseDiscoveryRuleStatement);
-        assertThat(((DropDatabaseDiscoveryRuleStatement) 
sqlStatement).getRuleNames(), is(Arrays.asList("ha_group_0", "ha_group_1")));
-    }
-    
-    @Test
     public void assertParseCreateEncryptRule() {
         SQLStatement sqlStatement = engine.parse(CREATE_ENCRYPT_RULE);
         assertTrue(sqlStatement instanceof CreateEncryptRuleStatement);
@@ -242,13 +175,6 @@ public final class DistSQLStatementParserEngineTest {
     }
     
     @Test
-    public void assertParseShowDatabaseDiscoveryRules() {
-        SQLStatement sqlStatement = engine.parse(SHOW_DB_DISCOVERY_RULES);
-        assertTrue(sqlStatement instanceof 
ShowDatabaseDiscoveryRulesStatement);
-        assertThat(((ShowDatabaseDiscoveryRulesStatement) 
sqlStatement).getSchema().get().getIdentifier().getValue(), 
is("db_discovery_db"));
-    }
-    
-    @Test
     public void assertParseShowEncryptRules() {
         SQLStatement sqlStatement = engine.parse(SHOW_ENCRYPT_RULES);
         assertTrue(sqlStatement instanceof ShowEncryptRulesStatement);
diff --git a/shardingsphere-features/shardingsphere-db-discovery/pom.xml 
b/shardingsphere-features/shardingsphere-db-discovery/pom.xml
index 8223bc5..288bd34 100644
--- a/shardingsphere-features/shardingsphere-db-discovery/pom.xml
+++ b/shardingsphere-features/shardingsphere-db-discovery/pom.xml
@@ -32,7 +32,8 @@
     <modules>
         <module>shardingsphere-db-discovery-api</module>
         <module>shardingsphere-db-discovery-core</module>
-        <module>shardingsphere-db-discovery-spring</module>
+        <module>shardingsphere-db-discovery-distsql</module>
         <module>shardingsphere-db-discovery-provider</module>
+        <module>shardingsphere-db-discovery-spring</module>
     </modules>
 </project>
diff --git 
a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/pom.xml
 
b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/pom.xml
index 14682a3..50f56e9 100644
--- 
a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/pom.xml
+++ 
b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/pom.xml
@@ -34,6 +34,11 @@
             <artifactId>shardingsphere-db-discovery-api</artifactId>
             <version>${project.version}</version>
         </dependency>
+        <dependency>
+            <groupId>org.apache.shardingsphere</groupId>
+            <artifactId>shardingsphere-db-discovery-distsql</artifactId>
+            <version>${project.version}</version>
+        </dependency>
         
         <dependency>
             <groupId>org.apache.shardingsphere</groupId>
diff --git 
a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/pom.xml
 
b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/pom.xml
similarity index 62%
copy from 
shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/pom.xml
copy to 
shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/pom.xml
index 14682a3..efc7f3e 100644
--- 
a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-core/pom.xml
+++ 
b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/pom.xml
@@ -25,39 +25,46 @@
         <artifactId>shardingsphere-db-discovery</artifactId>
         <version>5.0.0-RC1-SNAPSHOT</version>
     </parent>
-    <artifactId>shardingsphere-db-discovery-core</artifactId>
+    <artifactId>shardingsphere-db-discovery-distsql</artifactId>
     <name>${project.artifactId}</name>
     
     <dependencies>
         <dependency>
             <groupId>org.apache.shardingsphere</groupId>
-            <artifactId>shardingsphere-db-discovery-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-infra-route</artifactId>
+            <artifactId>shardingsphere-distsql-parser-engine</artifactId>
             <version>${project.version}</version>
         </dependency>
         <dependency>
             <groupId>org.apache.shardingsphere</groupId>
             <artifactId>shardingsphere-distsql-parser-statement</artifactId>
-            <version>${project.version}</version>
-        </dependency>
-        <dependency>
-            <groupId>org.apache.shardingsphere</groupId>
-            <artifactId>shardingsphere-db-discovery-mgr</artifactId>
-            <version>${project.version}</version>
-        </dependency>
-        
-        <dependency>
-            <groupId>com.h2database</groupId>
-            <artifactId>h2</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>com.zaxxer</groupId>
-            <artifactId>HikariCP</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/db-discovery/</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-db-discovery/shardingsphere-db-discovery-distsql/src/main/antlr4/imports/db-discovery/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-db-discovery/shardingsphere-db-discovery-distsql/src/main/antlr4/imports/db-discovery/Alphabet.g4
index ae555b4..f7603cc 100644
--- 
a/shardingsphere-distsql-parser/shardingsphere-distsql-parser-engine/src/main/antlr4/imports/RQLStatement.g4
+++ 
b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/src/main/antlr4/imports/db-discovery/Alphabet.g4
@@ -15,30 +15,34 @@
  * limitations under the License.
  */
 
-grammar RQLStatement;
-
-import Keyword, Literals, Symbol;
-
-showResources
-    : SHOW RESOURCES (FROM schemaName)?
-    ;
-
-showDatabaseDiscoveryRules
-    : SHOW DB_DISCOVERY RULES (FROM schemaName)?
-    ;
-
-showEncryptRules
-    : SHOW ENCRYPT (TABLE tableRule | RULES) (FROM schemaName)?
-    ;
-
-tableRule
-    : RULE tableName
-    ;
-
-schemaName
-    : IDENTIFIER
-    ;
-
-tableName
-    : IDENTIFIER
-    ;
+lexer grammar Alphabet;
+
+FOR_GENERATOR: 'DO NOT MATCH ANY THING, JUST FOR GENERATOR';
+
+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-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-distsql/src/main/antlr4/imports/readwrite-splitting/Keyword.g4
 
b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/src/main/antlr4/imports/db-discovery/Keyword.g4
similarity index 82%
copy from 
shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-distsql/src/main/antlr4/imports/readwrite-splitting/Keyword.g4
copy to 
shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/src/main/antlr4/imports/db-discovery/Keyword.g4
index b222a80..6f30a45 100644
--- 
a/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-distsql/src/main/antlr4/imports/readwrite-splitting/Keyword.g4
+++ 
b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/src/main/antlr4/imports/db-discovery/Keyword.g4
@@ -39,6 +39,10 @@ SHOW
     : S H O W
     ;
 
+RESOURCES
+    : R E S O U R C E S
+    ;
+
 RULE
     :  R U L E
     ;
@@ -47,26 +51,10 @@ FROM
     : F R O M
     ;
 
-READWRITE_SPLITTING
-    : R E A D W R I T E UL_ S P L I T T I N G
-    ;
-
-WRITE_RESOURCE
-    : W R I T E UL_ R E S O U R C E
-    ;
-
-READ_RESOURCES
-    : R E A D UL_ R E S O U R C E S
-    ;
-
-AUTO_AWARE_RESOURCE
-    : A U T O UL_ A W A R E UL_ R E S O U R C E
-    ;
-    
 TYPE
     : T Y P E
     ;
-    
+
 NAME
     : N A M E
     ;
@@ -78,3 +66,7 @@ PROPERTIES
 RULES
     : R U L E S
     ;
+
+DB_DISCOVERY
+    : D B UL_ D I S C O V E R Y
+    ;
diff --git 
a/shardingsphere-distsql-parser/shardingsphere-distsql-parser-engine/src/main/antlr4/imports/RQLStatement.g4
 
b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/src/main/antlr4/imports/db-discovery/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-db-discovery/shardingsphere-db-discovery-distsql/src/main/antlr4/imports/db-discovery/Literals.g4
index ae555b4..e5f807b 100644
--- 
a/shardingsphere-distsql-parser/shardingsphere-distsql-parser-engine/src/main/antlr4/imports/RQLStatement.g4
+++ 
b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/src/main/antlr4/imports/db-discovery/Literals.g4
@@ -15,30 +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)
     ;
-
-showDatabaseDiscoveryRules
-    : SHOW DB_DISCOVERY RULES (FROM schemaName)?
+    
+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-db-discovery/shardingsphere-db-discovery-distsql/src/main/antlr4/imports/db-discovery/RDLStatement.g4
similarity index 57%
copy from 
shardingsphere-distsql-parser/shardingsphere-distsql-parser-engine/src/main/antlr4/imports/RDLStatement.g4
copy to 
shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/src/main/antlr4/imports/db-discovery/RDLStatement.g4
index a6e48a2..93139ee 100644
--- 
a/shardingsphere-distsql-parser/shardingsphere-distsql-parser-engine/src/main/antlr4/imports/RDLStatement.g4
+++ 
b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/src/main/antlr4/imports/db-discovery/RDLStatement.g4
@@ -19,66 +19,14 @@ 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
-    ;
-
 resources
     : RESOURCES LP IDENTIFIER (COMMA IDENTIFIER)* RP
     ;
 
-resourceName
-    : IDENTIFIER
-    ;
-
 ruleName
     : IDENTIFIER
     ;
 
-tableName
-    : IDENTIFIER
-    ;
-
-columnName
-    : IDENTIFIER
-    ;
-
 functionDefinition
     : TYPE LP NAME EQ functionName (COMMA PROPERTIES LP algorithmProperties? 
RP)? RP
     ;
@@ -110,31 +58,3 @@ alterDatabaseDiscoveryRule
 dropDatabaseDiscoveryRule
     : DROP DB_DISCOVERY RULE IDENTIFIER (COMMA IDENTIFIER)*
     ;
-
-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-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/src/main/antlr4/imports/db-discovery/RQLStatement.g4
similarity index 81%
copy from 
shardingsphere-distsql-parser/shardingsphere-distsql-parser-engine/src/main/antlr4/imports/RQLStatement.g4
copy to 
shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/src/main/antlr4/imports/db-discovery/RQLStatement.g4
index ae555b4..b87b860 100644
--- 
a/shardingsphere-distsql-parser/shardingsphere-distsql-parser-engine/src/main/antlr4/imports/RQLStatement.g4
+++ 
b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/src/main/antlr4/imports/db-discovery/RQLStatement.g4
@@ -19,26 +19,10 @@ grammar RQLStatement;
 
 import Keyword, Literals, Symbol;
 
-showResources
-    : SHOW RESOURCES (FROM schemaName)?
-    ;
-
 showDatabaseDiscoveryRules
     : SHOW DB_DISCOVERY RULES (FROM schemaName)?
     ;
 
-showEncryptRules
-    : SHOW ENCRYPT (TABLE tableRule | RULES) (FROM schemaName)?
-    ;
-
-tableRule
-    : RULE tableName
-    ;
-
 schemaName
     : IDENTIFIER
     ;
-
-tableName
-    : IDENTIFIER
-    ;
diff --git 
a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/src/main/antlr4/imports/db-discovery/Symbol.g4
 
b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/src/main/antlr4/imports/db-discovery/Symbol.g4
new file mode 100644
index 0000000..a332bdd
--- /dev/null
+++ 
b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/src/main/antlr4/imports/db-discovery/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-db-discovery/shardingsphere-db-discovery-distsql/src/main/antlr4/org/apache/shardingsphere/distsql/parser/autogen/DatabaseDiscoveryRuleStatement.g4
similarity index 68%
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-db-discovery/shardingsphere-db-discovery-distsql/src/main/antlr4/org/apache/shardingsphere/distsql/parser/autogen/DatabaseDiscoveryRuleStatement.g4
index c857a31..2748267 100644
--- 
a/shardingsphere-distsql-parser/shardingsphere-distsql-parser-engine/src/main/antlr4/org/apache/shardingsphere/distsql/parser/autogen/DistSQLStatement.g4
+++ 
b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/src/main/antlr4/org/apache/shardingsphere/distsql/parser/autogen/DatabaseDiscoveryRuleStatement.g4
@@ -15,28 +15,14 @@
  * limitations under the License.
  */
 
-grammar DistSQLStatement;
+grammar DatabaseDiscoveryRuleStatement;
 
-import Symbol, RDLStatement, RQLStatement, RALStatement;
+import Symbol, RDLStatement, RQLStatement;
 
 execute
-    : (addResource
-    | dropResource
-    | createDatabaseDiscoveryRule
+    : (createDatabaseDiscoveryRule
     | alterDatabaseDiscoveryRule
     | dropDatabaseDiscoveryRule
-    | createEncryptRule
-    | alterEncryptRule
-    | dropEncryptRule
-    | showResources
     | showDatabaseDiscoveryRules
-    | 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-db-discovery/shardingsphere-db-discovery-distsql/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/parser/core/DatabaseDiscoveryRuleLexer.java
similarity index 60%
copy from 
shardingsphere-distsql-parser/shardingsphere-distsql-parser-engine/src/main/antlr4/imports/RQLStatement.g4
copy to 
shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/parser/core/DatabaseDiscoveryRuleLexer.java
index ae555b4..0e3723e 100644
--- 
a/shardingsphere-distsql-parser/shardingsphere-distsql-parser-engine/src/main/antlr4/imports/RQLStatement.g4
+++ 
b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/parser/core/DatabaseDiscoveryRuleLexer.java
@@ -15,30 +15,18 @@
  * limitations under the License.
  */
 
-grammar RQLStatement;
+package org.apache.shardingsphere.dbdiscovery.distsql.parser.core;
 
-import Keyword, Literals, Symbol;
+import org.antlr.v4.runtime.CharStream;
+import 
org.apache.shardingsphere.distsql.parser.autogen.DatabaseDiscoveryRuleStatementLexer;
+import org.apache.shardingsphere.sql.parser.api.parser.SQLLexer;
 
-showResources
-    : SHOW RESOURCES (FROM schemaName)?
-    ;
-
-showDatabaseDiscoveryRules
-    : SHOW DB_DISCOVERY RULES (FROM schemaName)?
-    ;
-
-showEncryptRules
-    : SHOW ENCRYPT (TABLE tableRule | RULES) (FROM schemaName)?
-    ;
-
-tableRule
-    : RULE tableName
-    ;
-
-schemaName
-    : IDENTIFIER
-    ;
-
-tableName
-    : IDENTIFIER
-    ;
+/**
+ * SQL lexer for database discovery rule.
+ */
+public final class DatabaseDiscoveryRuleLexer extends 
DatabaseDiscoveryRuleStatementLexer implements SQLLexer {
+    
+    public DatabaseDiscoveryRuleLexer(final CharStream input) {
+        super(input);
+    }
+}
diff --git 
a/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-distsql/src/main/antlr4/imports/readwrite-splitting/Keyword.g4
 
b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/parser/core/DatabaseDiscoveryRuleParser.java
similarity index 52%
copy from 
shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-distsql/src/main/antlr4/imports/readwrite-splitting/Keyword.g4
copy to 
shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/parser/core/DatabaseDiscoveryRuleParser.java
index b222a80..089a5c1 100644
--- 
a/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-distsql/src/main/antlr4/imports/readwrite-splitting/Keyword.g4
+++ 
b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/parser/core/DatabaseDiscoveryRuleParser.java
@@ -15,66 +15,25 @@
  * limitations under the License.
  */
 
-lexer grammar Keyword;
+package org.apache.shardingsphere.dbdiscovery.distsql.parser.core;
 
-import Alphabet;
+import org.antlr.v4.runtime.TokenStream;
+import 
org.apache.shardingsphere.distsql.parser.autogen.DatabaseDiscoveryRuleStatementParser;
+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;
 
-WS
-    : [ \t\r\n] + ->skip
-    ;
-
-CREATE
-    : C R E A T E
-    ;
-
-ALTER
-    : A L T E R
-    ;
-
-DROP
-    : D R O P
-    ;
-
-SHOW
-    : S H O W
-    ;
-
-RULE
-    :  R U L E
-    ;
-
-FROM
-    : F R O M
-    ;
-
-READWRITE_SPLITTING
-    : R E A D W R I T E UL_ S P L I T T I N G
-    ;
-
-WRITE_RESOURCE
-    : W R I T E UL_ R E S O U R C E
-    ;
-
-READ_RESOURCES
-    : R E A D UL_ R E S O U R C E S
-    ;
-
-AUTO_AWARE_RESOURCE
-    : A U T O UL_ A W A R E UL_ R E S O U R C E
-    ;
+/**
+ * SQL parser for database discovery rule.
+ */
+public final class DatabaseDiscoveryRuleParser extends 
DatabaseDiscoveryRuleStatementParser implements SQLParser {
     
-TYPE
-    : T Y P E
-    ;
+    public DatabaseDiscoveryRuleParser(final TokenStream input) {
+        super(input);
+    }
     
-NAME
-    : N A M E
-    ;
-
-PROPERTIES
-    : P R O P E R T I E S
-    ;
-
-RULES
-    : R U L E S
-    ;
+    @Override
+    public ASTNode parse() {
+        return new ParseASTNode(execute());
+    }
+}
diff --git 
a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/parser/core/DatabaseDiscoveryRuleSQLStatementVisitor.java
 
b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/parser/core/DatabaseDiscoveryRuleSQLStatementVisitor.java
new file mode 100644
index 0000000..a465ae6
--- /dev/null
+++ 
b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/parser/core/DatabaseDiscoveryRuleSQLStatementVisitor.java
@@ -0,0 +1,107 @@
+/*
+ * 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.dbdiscovery.distsql.parser.core;
+
+import org.antlr.v4.runtime.tree.TerminalNode;
+import 
org.apache.shardingsphere.distsql.parser.autogen.DatabaseDiscoveryRuleStatementBaseVisitor;
+import 
org.apache.shardingsphere.distsql.parser.autogen.DatabaseDiscoveryRuleStatementParser.AlgorithmPropertiesContext;
+import 
org.apache.shardingsphere.distsql.parser.autogen.DatabaseDiscoveryRuleStatementParser.AlgorithmPropertyContext;
+import 
org.apache.shardingsphere.distsql.parser.autogen.DatabaseDiscoveryRuleStatementParser.AlterDatabaseDiscoveryRuleContext;
+import 
org.apache.shardingsphere.distsql.parser.autogen.DatabaseDiscoveryRuleStatementParser.CreateDatabaseDiscoveryRuleContext;
+import 
org.apache.shardingsphere.distsql.parser.autogen.DatabaseDiscoveryRuleStatementParser.DatabaseDiscoveryRuleDefinitionContext;
+import 
org.apache.shardingsphere.distsql.parser.autogen.DatabaseDiscoveryRuleStatementParser.DropDatabaseDiscoveryRuleContext;
+import 
org.apache.shardingsphere.distsql.parser.autogen.DatabaseDiscoveryRuleStatementParser.FunctionDefinitionContext;
+import 
org.apache.shardingsphere.distsql.parser.autogen.DatabaseDiscoveryRuleStatementParser.SchemaNameContext;
+import 
org.apache.shardingsphere.distsql.parser.autogen.DatabaseDiscoveryRuleStatementParser.ShowDatabaseDiscoveryRulesContext;
+import org.apache.shardingsphere.distsql.parser.segment.FunctionSegment;
+import 
org.apache.shardingsphere.distsql.parser.segment.rdl.DatabaseDiscoveryRuleSegment;
+import 
org.apache.shardingsphere.distsql.parser.statement.rdl.alter.impl.AlterDatabaseDiscoveryRuleStatement;
+import 
org.apache.shardingsphere.distsql.parser.statement.rdl.create.impl.CreateDatabaseDiscoveryRuleStatement;
+import 
org.apache.shardingsphere.distsql.parser.statement.rdl.drop.impl.DropDatabaseDiscoveryRuleStatement;
+import 
org.apache.shardingsphere.distsql.parser.statement.rql.show.impl.ShowDatabaseDiscoveryRulesStatement;
+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.value.identifier.IdentifierValue;
+
+import java.util.Objects;
+import java.util.Properties;
+import java.util.stream.Collectors;
+
+/**
+ * SQL statement visitor for database discovery rule.
+ */
+public final class DatabaseDiscoveryRuleSQLStatementVisitor extends 
DatabaseDiscoveryRuleStatementBaseVisitor<ASTNode> implements SQLVisitor {
+    
+    @Override
+    public ASTNode visitCreateDatabaseDiscoveryRule(final 
CreateDatabaseDiscoveryRuleContext ctx) {
+        return new 
CreateDatabaseDiscoveryRuleStatement(ctx.databaseDiscoveryRuleDefinition().stream().map(each
 -> (DatabaseDiscoveryRuleSegment) visit(each)).collect(Collectors.toList()));
+    }
+    
+    @Override
+    public ASTNode visitDatabaseDiscoveryRuleDefinition(final 
DatabaseDiscoveryRuleDefinitionContext ctx) {
+        DatabaseDiscoveryRuleSegment result = new 
DatabaseDiscoveryRuleSegment();
+        result.setName(ctx.ruleName().getText());
+        result.setDataSources(ctx.resources().IDENTIFIER().stream().map(each 
-> new 
IdentifierValue(each.getText()).getValue()).collect(Collectors.toList()));
+        
result.setDiscoveryTypeName(ctx.functionDefinition().functionName().getText());
+        
result.setProps(buildAlgorithmProperties(ctx.functionDefinition().algorithmProperties()));
+        return result;
+    }
+    
+    @Override
+    public ASTNode visitAlterDatabaseDiscoveryRule(final 
AlterDatabaseDiscoveryRuleContext ctx) {
+        return new 
AlterDatabaseDiscoveryRuleStatement(ctx.databaseDiscoveryRuleDefinition().stream().map(each
 -> (DatabaseDiscoveryRuleSegment) visit(each)).collect(Collectors.toList()));
+    }
+    
+    @Override
+    public ASTNode visitDropDatabaseDiscoveryRule(final 
DropDatabaseDiscoveryRuleContext ctx) {
+        return new 
DropDatabaseDiscoveryRuleStatement(ctx.IDENTIFIER().stream().map(TerminalNode::getText).collect(Collectors.toList()));
+    }
+    
+    @Override
+    public ASTNode visitSchemaName(final SchemaNameContext ctx) {
+        return new SchemaSegment(ctx.getStart().getStartIndex(), 
ctx.getStop().getStopIndex(), new IdentifierValue(ctx.getText()));
+    }
+    
+    @Override
+    public ASTNode visitShowDatabaseDiscoveryRules(final 
ShowDatabaseDiscoveryRulesContext ctx) {
+        return new 
ShowDatabaseDiscoveryRulesStatement(Objects.nonNull(ctx.schemaName()) ? 
(SchemaSegment) visit(ctx.schemaName()) : null);
+    }
+    
+    private Properties buildAlgorithmProperties(final 
AlgorithmPropertiesContext ctx) {
+        Properties result = new Properties();
+        for (AlgorithmPropertyContext each : ctx.algorithmProperty()) {
+            result.setProperty(new 
IdentifierValue(each.key.getText()).getValue(), new 
IdentifierValue(each.value.getText()).getValue());
+        }
+        return result;
+    }
+    
+    @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;
+    }
+}
diff --git 
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/src/main/java/org/apache/shardingsphere/sharding/distsql/parser/facade/ShardingRuleStatementParserFacade.java
 
b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/parser/facade/DatabaseDiscoveryRuleSQLStatementParserFacade.java
similarity index 65%
copy from 
shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/src/main/java/org/apache/shardingsphere/sharding/distsql/parser/facade/ShardingRuleStatementParserFacade.java
copy to 
shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/parser/facade/DatabaseDiscoveryRuleSQLStatementParserFacade.java
index d29468d..4e8ef57 100644
--- 
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/src/main/java/org/apache/shardingsphere/sharding/distsql/parser/facade/ShardingRuleStatementParserFacade.java
+++ 
b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/parser/facade/DatabaseDiscoveryRuleSQLStatementParserFacade.java
@@ -15,38 +15,38 @@
  * limitations under the License.
  */
 
-package org.apache.shardingsphere.sharding.distsql.parser.facade;
+package org.apache.shardingsphere.dbdiscovery.distsql.parser.facade;
 
+import 
org.apache.shardingsphere.dbdiscovery.distsql.parser.core.DatabaseDiscoveryRuleLexer;
+import 
org.apache.shardingsphere.dbdiscovery.distsql.parser.core.DatabaseDiscoveryRuleParser;
+import 
org.apache.shardingsphere.dbdiscovery.distsql.parser.core.DatabaseDiscoveryRuleSQLStatementVisitor;
 import 
org.apache.shardingsphere.distsql.parser.spi.RuleSQLStatementParserFacade;
-import 
org.apache.shardingsphere.sharding.distsql.parser.core.ShardingRuleDistSQLStatementVisitor;
-import 
org.apache.shardingsphere.sharding.distsql.parser.core.ShardingRuleLexer;
-import 
org.apache.shardingsphere.sharding.distsql.parser.core.ShardingRuleParser;
 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 sharding rule statement.
+ * SQL parser facade for database discovery rule SQL statement.
  */
-public final class ShardingRuleStatementParserFacade implements 
RuleSQLStatementParserFacade {
+public final class DatabaseDiscoveryRuleSQLStatementParserFacade implements 
RuleSQLStatementParserFacade {
     
     @Override
     public Class<? extends SQLLexer> getLexerClass() {
-        return ShardingRuleLexer.class;
+        return DatabaseDiscoveryRuleLexer.class;
     }
     
     @Override
     public Class<? extends SQLParser> getParserClass() {
-        return ShardingRuleParser.class;
+        return DatabaseDiscoveryRuleParser.class;
     }
     
     @Override
     public Class<? extends SQLVisitor> getVisitorClass() {
-        return ShardingRuleDistSQLStatementVisitor.class;
+        return DatabaseDiscoveryRuleSQLStatementVisitor.class;
     }
     
     @Override
     public String getRuleType() {
-        return "Sharding";
+        return "database-discovery";
     }
 }
diff --git 
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/src/main/resources/META-INF/services/org.apache.shardingsphere.distsql.parser.spi.RuleSQLStatementParserFacade
 
b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/src/main/resources/META-INF/services/org.apache.shardingsphere.distsql.parser.spi.RuleSQLStatementParserFacade
similarity index 88%
copy from 
shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/src/main/resources/META-INF/services/org.apache.shardingsphere.distsql.parser.spi.RuleSQLStatementParserFacade
copy to 
shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/src/main/resources/META-INF/services/org.apache.shardingsphere.distsql.parser.spi.RuleSQLStatementParserFacade
index fcb17bd..8abc1ef 100644
--- 
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/src/main/resources/META-INF/services/org.apache.shardingsphere.distsql.parser.spi.RuleSQLStatementParserFacade
+++ 
b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/src/main/resources/META-INF/services/org.apache.shardingsphere.distsql.parser.spi.RuleSQLStatementParserFacade
@@ -15,4 +15,4 @@
 # limitations under the License.
 #
 
-org.apache.shardingsphere.sharding.distsql.parser.facade.ShardingRuleStatementParserFacade
+org.apache.shardingsphere.dbdiscovery.distsql.parser.facade.DatabaseDiscoveryRuleSQLStatementParserFacade
diff --git 
a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/src/test/java/org/apache/shardingsphere/dbdiscovery/distsql/parser/core/DatabaseDiscoveryRuleStatementParserEngineTest.java
 
b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/src/test/java/org/apache/shardingsphere/dbdiscovery/distsql/parser/core/DatabaseDiscoveryRuleStatementParserEngineTest.java
new file mode 100644
index 0000000..07955f8
--- /dev/null
+++ 
b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/src/test/java/org/apache/shardingsphere/dbdiscovery/distsql/parser/core/DatabaseDiscoveryRuleStatementParserEngineTest.java
@@ -0,0 +1,110 @@
+/*
+ * 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.dbdiscovery.distsql.parser.core;
+
+import 
org.apache.shardingsphere.distsql.parser.api.DistSQLStatementParserEngine;
+import 
org.apache.shardingsphere.distsql.parser.segment.rdl.DatabaseDiscoveryRuleSegment;
+import 
org.apache.shardingsphere.distsql.parser.statement.rdl.alter.impl.AlterDatabaseDiscoveryRuleStatement;
+import 
org.apache.shardingsphere.distsql.parser.statement.rdl.create.impl.CreateDatabaseDiscoveryRuleStatement;
+import 
org.apache.shardingsphere.distsql.parser.statement.rdl.drop.impl.DropDatabaseDiscoveryRuleStatement;
+import 
org.apache.shardingsphere.distsql.parser.statement.rql.show.impl.ShowDatabaseDiscoveryRulesStatement;
+import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement;
+import org.junit.Test;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertTrue;
+
+// TODO use Parameterized + XML instead of static test
+public final class DatabaseDiscoveryRuleStatementParserEngineTest {
+    
+    private static final String CREATE_DATABASE_DISCOVERY_RULE = "CREATE 
DB_DISCOVERY RULE ha_group_0 ("
+            + "RESOURCES(resource0,resource1),"
+            + 
"TYPE(NAME=mgr,PROPERTIES(groupName='92504d5b-6dec',keepAliveCron=''))),"
+            + "ha_group_1 ("
+            + "RESOURCES(resource2,resource3),"
+            + 
"TYPE(NAME=mgr2,PROPERTIES(groupName='92504d5b-6dec-2',keepAliveCron=''))"
+            + ")";
+    
+    private static final String ALTER_DATABASE_DISCOVERY_RULE = "ALTER 
DB_DISCOVERY RULE ha_group_0 ("
+            + "RESOURCES(resource0,resource1),"
+            + 
"TYPE(NAME=mgr,PROPERTIES(groupName='92504d5b-6dec',keepAliveCron=''))),"
+            + "ha_group_1 ("
+            + "RESOURCES(resource2,resource3),"
+            + 
"TYPE(NAME=mgr2,PROPERTIES(groupName='92504d5b-6dec-2',keepAliveCron=''))"
+            + ")";
+    
+    private static final String DROP_DATABASE_DISCOVERY_RULE = "DROP 
DB_DISCOVERY RULE ha_group_0,ha_group_1";
+    
+    private static final String SHOW_DB_DISCOVERY_RULES = "SHOW DB_DISCOVERY 
RULES FROM db_discovery_db";
+    
+    private final DistSQLStatementParserEngine engine = new 
DistSQLStatementParserEngine();
+    
+    @Test
+    public void assertParseCreateDatabaseDiscoveryRule() {
+        SQLStatement sqlStatement = 
engine.parse(CREATE_DATABASE_DISCOVERY_RULE);
+        assertTrue(sqlStatement instanceof 
CreateDatabaseDiscoveryRuleStatement);
+        CreateDatabaseDiscoveryRuleStatement statement = 
(CreateDatabaseDiscoveryRuleStatement) sqlStatement;
+        assertThat(statement.getRules().size(), is(2));
+        List<DatabaseDiscoveryRuleSegment> databaseDiscoveryRuleSegments
+                = new ArrayList<>(((CreateDatabaseDiscoveryRuleStatement) 
sqlStatement).getRules());
+        assertThat(databaseDiscoveryRuleSegments.get(0).getName(), 
is("ha_group_0"));
+        
assertThat(databaseDiscoveryRuleSegments.get(0).getDiscoveryTypeName(), 
is("mgr"));
+        assertThat(databaseDiscoveryRuleSegments.get(0).getDataSources(), 
is(Arrays.asList("resource0", "resource1")));
+        
assertThat(databaseDiscoveryRuleSegments.get(0).getProps().get("groupName"), 
is("92504d5b-6dec"));
+        assertThat(databaseDiscoveryRuleSegments.get(1).getName(), 
is("ha_group_1"));
+        
assertThat(databaseDiscoveryRuleSegments.get(1).getDiscoveryTypeName(), 
is("mgr2"));
+        assertThat(databaseDiscoveryRuleSegments.get(1).getDataSources(), 
is(Arrays.asList("resource2", "resource3")));
+        
assertThat(databaseDiscoveryRuleSegments.get(1).getProps().get("groupName"), 
is("92504d5b-6dec-2"));
+    }
+    
+    @Test
+    public void assertParseAlterDatabaseDiscoveryRule() {
+        SQLStatement sqlStatement = 
engine.parse(ALTER_DATABASE_DISCOVERY_RULE);
+        assertTrue(sqlStatement instanceof 
AlterDatabaseDiscoveryRuleStatement);
+        AlterDatabaseDiscoveryRuleStatement statement = 
(AlterDatabaseDiscoveryRuleStatement) sqlStatement;
+        assertThat(statement.getRules().size(), is(2));
+        List<DatabaseDiscoveryRuleSegment> databaseDiscoveryRuleSegments = new 
ArrayList<>(((AlterDatabaseDiscoveryRuleStatement) sqlStatement).getRules());
+        assertThat(databaseDiscoveryRuleSegments.get(0).getName(), 
is("ha_group_0"));
+        
assertThat(databaseDiscoveryRuleSegments.get(0).getDiscoveryTypeName(), 
is("mgr"));
+        assertThat(databaseDiscoveryRuleSegments.get(0).getDataSources(), 
is(Arrays.asList("resource0", "resource1")));
+        
assertThat(databaseDiscoveryRuleSegments.get(0).getProps().get("groupName"), 
is("92504d5b-6dec"));
+        assertThat(databaseDiscoveryRuleSegments.get(1).getName(), 
is("ha_group_1"));
+        
assertThat(databaseDiscoveryRuleSegments.get(1).getDiscoveryTypeName(), 
is("mgr2"));
+        assertThat(databaseDiscoveryRuleSegments.get(1).getDataSources(), 
is(Arrays.asList("resource2", "resource3")));
+        
assertThat(databaseDiscoveryRuleSegments.get(1).getProps().get("groupName"), 
is("92504d5b-6dec-2"));
+    }
+    
+    @Test
+    public void assertParseDropDatabaseDiscoveryRule() {
+        SQLStatement sqlStatement = engine.parse(DROP_DATABASE_DISCOVERY_RULE);
+        assertTrue(sqlStatement instanceof DropDatabaseDiscoveryRuleStatement);
+        assertThat(((DropDatabaseDiscoveryRuleStatement) 
sqlStatement).getRuleNames(), is(Arrays.asList("ha_group_0", "ha_group_1")));
+    }
+    
+    @Test
+    public void assertParseShowDatabaseDiscoveryRules() {
+        SQLStatement sqlStatement = engine.parse(SHOW_DB_DISCOVERY_RULES);
+        assertTrue(sqlStatement instanceof 
ShowDatabaseDiscoveryRulesStatement);
+        assertThat(((ShowDatabaseDiscoveryRulesStatement) 
sqlStatement).getSchema().get().getIdentifier().getValue(), 
is("db_discovery_db"));
+    }
+}
diff --git 
a/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-distsql/src/main/antlr4/imports/readwrite-splitting/Keyword.g4
 
b/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-distsql/src/main/antlr4/imports/readwrite-splitting/Keyword.g4
index b222a80..3c3ab60 100644
--- 
a/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-distsql/src/main/antlr4/imports/readwrite-splitting/Keyword.g4
+++ 
b/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-distsql/src/main/antlr4/imports/readwrite-splitting/Keyword.g4
@@ -62,11 +62,11 @@ READ_RESOURCES
 AUTO_AWARE_RESOURCE
     : A U T O UL_ A W A R E UL_ R E S O U R C E
     ;
-    
+
 TYPE
     : T Y P E
     ;
-    
+
 NAME
     : N A M E
     ;
diff --git 
a/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-distsql/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/parser/core/ReadwriteSplittingRuleDistSQLStatementVisitor.java
 
b/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-distsql/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/parser/core/ReadwriteSplittingRuleSQLStatementVisitor.java
similarity index 97%
rename from 
shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-distsql/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/parser/core/ReadwriteSplittingRuleDistSQLStatementVisitor.java
rename to 
shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-distsql/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/parser/core/ReadwriteSplittingRuleSQLStatementVisitor.java
index fc49abe..57014bc 100644
--- 
a/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-distsql/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/parser/core/ReadwriteSplittingRuleDistSQLStatementVisitor.java
+++ 
b/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-distsql/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/parser/core/ReadwriteSplittingRuleSQLStatementVisitor.java
@@ -48,7 +48,7 @@ import java.util.stream.Collectors;
 /**
  * SQL statement visitor for readwrite-splitting rule.
  */
-public final class ReadwriteSplittingRuleDistSQLStatementVisitor extends 
ReadwriteSplittingRuleStatementBaseVisitor<ASTNode> implements SQLVisitor {
+public final class ReadwriteSplittingRuleSQLStatementVisitor extends 
ReadwriteSplittingRuleStatementBaseVisitor<ASTNode> implements SQLVisitor {
     
     @Override
     public ASTNode visitCreateReadwriteSplittingRule(final 
CreateReadwriteSplittingRuleContext ctx) {
diff --git 
a/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-distsql/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/parser/facade/ReadwriteSplittingRuleStatementParserFacade.java
 
b/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-distsql/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/parser/facade/ReadwriteSplittingRuleSQLStatementParserFacade.java
similarity index 84%
rename from 
shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-distsql/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/parser/facade/ReadwriteSplittingRuleStatementParserFacade.java
rename to 
shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-distsql/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/parser/facade/ReadwriteSplittingRuleSQLStatementParserFacade.java
index c4aee59..d0e20f8 100644
--- 
a/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-distsql/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/parser/facade/ReadwriteSplittingRuleStatementParserFacade.java
+++ 
b/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-distsql/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/parser/facade/ReadwriteSplittingRuleSQLStatementParserFacade.java
@@ -18,7 +18,7 @@
 package org.apache.shardingsphere.readwritesplitting.distsql.parser.facade;
 
 import 
org.apache.shardingsphere.distsql.parser.spi.RuleSQLStatementParserFacade;
-import 
org.apache.shardingsphere.readwritesplitting.distsql.parser.core.ReadwriteSplittingRuleDistSQLStatementVisitor;
+import 
org.apache.shardingsphere.readwritesplitting.distsql.parser.core.ReadwriteSplittingRuleSQLStatementVisitor;
 import 
org.apache.shardingsphere.readwritesplitting.distsql.parser.core.ReadwriteSplittingRuleLexer;
 import 
org.apache.shardingsphere.readwritesplitting.distsql.parser.core.ReadwriteSplittingRuleParser;
 import org.apache.shardingsphere.sql.parser.api.parser.SQLLexer;
@@ -26,9 +26,9 @@ import 
org.apache.shardingsphere.sql.parser.api.parser.SQLParser;
 import org.apache.shardingsphere.sql.parser.api.visitor.SQLVisitor;
 
 /**
- * SQL parser facade for readwrite-splitting rule statement.
+ * SQL parser facade for readwrite-splitting rule SQL statement.
  */
-public final class ReadwriteSplittingRuleStatementParserFacade implements 
RuleSQLStatementParserFacade {
+public final class ReadwriteSplittingRuleSQLStatementParserFacade implements 
RuleSQLStatementParserFacade {
     
     @Override
     public Class<? extends SQLLexer> getLexerClass() {
@@ -42,11 +42,11 @@ public final class 
ReadwriteSplittingRuleStatementParserFacade implements RuleSQ
     
     @Override
     public Class<? extends SQLVisitor> getVisitorClass() {
-        return ReadwriteSplittingRuleDistSQLStatementVisitor.class;
+        return ReadwriteSplittingRuleSQLStatementVisitor.class;
     }
     
     @Override
     public String getRuleType() {
-        return "Readwrite-splitting";
+        return "readwrite-splitting";
     }
 }
diff --git 
a/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-distsql/src/main/resources/META-INF/services/org.apache.shardingsphere.distsql.parser.spi.RuleSQLStatementParserFacade
 
b/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-distsql/src/main/resources/META-INF/services/org.apache.shardingsphere.distsql.parser.spi.RuleSQLStatementParserFacade
index 6a877b9..92bac21 100644
--- 
a/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-distsql/src/main/resources/META-INF/services/org.apache.shardingsphere.distsql.parser.spi.RuleSQLStatementParserFacade
+++ 
b/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-distsql/src/main/resources/META-INF/services/org.apache.shardingsphere.distsql.parser.spi.RuleSQLStatementParserFacade
@@ -15,4 +15,4 @@
 # limitations under the License.
 #
 
-org.apache.shardingsphere.readwritesplitting.distsql.parser.facade.ReadwriteSplittingRuleStatementParserFacade
+org.apache.shardingsphere.readwritesplitting.distsql.parser.facade.ReadwriteSplittingRuleSQLStatementParserFacade
diff --git 
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/src/main/antlr4/imports/sharding/Keyword.g4
 
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/src/main/antlr4/imports/sharding/Keyword.g4
index fd08625..0f5cc1a 100644
--- 
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/src/main/antlr4/imports/sharding/Keyword.g4
+++ 
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/src/main/antlr4/imports/sharding/Keyword.g4
@@ -70,11 +70,11 @@ TABLE
 SHARDING_COLUMN
     : S H A R D I N G UL_ C O L U M N
     ;
-    
+
 TYPE
     : T Y P E
     ;
-    
+
 NAME
     : N A M E
     ;
@@ -82,7 +82,7 @@ NAME
 PROPERTIES
     : P R O P E R T I E S
     ;
-    
+
 COLUMN
     : C O L U M N
     ;
diff --git 
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/src/main/java/org/apache/shardingsphere/sharding/distsql/parser/core/ShardingRuleDistSQLStatementVisitor.java
 
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/src/main/java/org/apache/shardingsphere/sharding/distsql/parser/core/ShardingRuleSQLStatementVisitor.java
similarity index 98%
rename from 
shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/src/main/java/org/apache/shardingsphere/sharding/distsql/parser/core/ShardingRuleDistSQLStatementVisitor.java
rename to 
shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/src/main/java/org/apache/shardingsphere/sharding/distsql/parser/core/ShardingRuleSQLStatementVisitor.java
index b267a27..80af0c8 100644
--- 
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/src/main/java/org/apache/shardingsphere/sharding/distsql/parser/core/ShardingRuleDistSQLStatementVisitor.java
+++ 
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/src/main/java/org/apache/shardingsphere/sharding/distsql/parser/core/ShardingRuleSQLStatementVisitor.java
@@ -69,7 +69,7 @@ import java.util.stream.Collectors;
 /**
  * SQL statement visitor for sharding rule.
  */
-public final class ShardingRuleDistSQLStatementVisitor extends 
ShardingRuleStatementBaseVisitor<ASTNode> implements SQLVisitor {
+public final class ShardingRuleSQLStatementVisitor extends 
ShardingRuleStatementBaseVisitor<ASTNode> implements SQLVisitor {
     
     @Override
     public ASTNode visitCreateShardingTableRule(final 
CreateShardingTableRuleContext ctx) {
diff --git 
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/src/main/java/org/apache/shardingsphere/sharding/distsql/parser/facade/ShardingRuleStatementParserFacade.java
 
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/src/main/java/org/apache/shardingsphere/sharding/distsql/parser/facade/ShardingRuleSQLStatementParserFacade.java
similarity index 87%
rename from 
shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/src/main/java/org/apache/shardingsphere/sharding/distsql/parser/facade/ShardingRuleStatementParserFacade.java
rename to 
shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/src/main/java/org/apache/shardingsphere/sharding/distsql/parser/facade/ShardingRuleSQLStatementParserFacade.java
index d29468d..d844940 100644
--- 
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/src/main/java/org/apache/shardingsphere/sharding/distsql/parser/facade/ShardingRuleStatementParserFacade.java
+++ 
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/src/main/java/org/apache/shardingsphere/sharding/distsql/parser/facade/ShardingRuleSQLStatementParserFacade.java
@@ -18,7 +18,7 @@
 package org.apache.shardingsphere.sharding.distsql.parser.facade;
 
 import 
org.apache.shardingsphere.distsql.parser.spi.RuleSQLStatementParserFacade;
-import 
org.apache.shardingsphere.sharding.distsql.parser.core.ShardingRuleDistSQLStatementVisitor;
+import 
org.apache.shardingsphere.sharding.distsql.parser.core.ShardingRuleSQLStatementVisitor;
 import 
org.apache.shardingsphere.sharding.distsql.parser.core.ShardingRuleLexer;
 import 
org.apache.shardingsphere.sharding.distsql.parser.core.ShardingRuleParser;
 import org.apache.shardingsphere.sql.parser.api.parser.SQLLexer;
@@ -26,9 +26,9 @@ import 
org.apache.shardingsphere.sql.parser.api.parser.SQLParser;
 import org.apache.shardingsphere.sql.parser.api.visitor.SQLVisitor;
 
 /**
- * SQL parser facade for sharding rule statement.
+ * SQL parser facade for sharding rule SQL statement.
  */
-public final class ShardingRuleStatementParserFacade implements 
RuleSQLStatementParserFacade {
+public final class ShardingRuleSQLStatementParserFacade implements 
RuleSQLStatementParserFacade {
     
     @Override
     public Class<? extends SQLLexer> getLexerClass() {
@@ -42,11 +42,11 @@ public final class ShardingRuleStatementParserFacade 
implements RuleSQLStatement
     
     @Override
     public Class<? extends SQLVisitor> getVisitorClass() {
-        return ShardingRuleDistSQLStatementVisitor.class;
+        return ShardingRuleSQLStatementVisitor.class;
     }
     
     @Override
     public String getRuleType() {
-        return "Sharding";
+        return "sharding";
     }
 }
diff --git 
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/src/main/resources/META-INF/services/org.apache.shardingsphere.distsql.parser.spi.RuleSQLStatementParserFacade
 
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/src/main/resources/META-INF/services/org.apache.shardingsphere.distsql.parser.spi.RuleSQLStatementParserFacade
index fcb17bd..96c5f62 100644
--- 
a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/src/main/resources/META-INF/services/org.apache.shardingsphere.distsql.parser.spi.RuleSQLStatementParserFacade
+++ 
b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/src/main/resources/META-INF/services/org.apache.shardingsphere.distsql.parser.spi.RuleSQLStatementParserFacade
@@ -15,4 +15,4 @@
 # limitations under the License.
 #
 
-org.apache.shardingsphere.sharding.distsql.parser.facade.ShardingRuleStatementParserFacade
+org.apache.shardingsphere.sharding.distsql.parser.facade.ShardingRuleSQLStatementParserFacade

Reply via email to