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

menghaoran 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 65b1c22  Refactor RDL executor engine to support creating schema
     new 70e6596  Merge pull request #6794 from tristaZero/new3
65b1c22 is described below

commit 65b1c2237675b049e430f6b8bf7f35398a881f4e
Author: tristaZero <[email protected]>
AuthorDate: Tue Aug 11 19:23:25 2020 +0800

    Refactor RDL executor engine to support creating schema
---
 .../DatabaseCommunicationEngineFactory.java        | 10 ++--
 .../jdbc/JDBCDatabaseCommunicationEngine.java      |  4 ++
 ...terExecuteEngine.java => RDLExecuteEngine.java} | 59 +++++++++++++++++-----
 .../backend/text/query/QueryBackendHandler.java    |  7 ++-
 ...teEngineTest.java => RDLExecuteEngineTest.java} | 11 ++--
 .../context/CreateSchemaStatementContext.java}     | 29 +++++------
 .../src/main/antlr4/imports/Keyword.g4             |  6 ++-
 .../src/main/antlr4/imports/RDLStatement.g4        |  8 +++
 .../rdl/parser/autogen/ShardingSphereStatement.g4  |  3 +-
 .../parser/sql/visitor/ShardingSphereVisitor.java  |  7 +++
 .../statement/rdl/CreateSchemaStatement.java}      | 27 ++++------
 11 files changed, 112 insertions(+), 59 deletions(-)

diff --git 
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/DatabaseCommunicationEngineFactory.java
 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/DatabaseCommunicationEngineFactory.java
index 7a4a9a2..d60830b 100644
--- 
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/DatabaseCommunicationEngineFactory.java
+++ 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/DatabaseCommunicationEngineFactory.java
@@ -22,14 +22,13 @@ import lombok.NoArgsConstructor;
 import org.apache.shardingsphere.kernel.context.SchemaContext;
 import 
org.apache.shardingsphere.proxy.backend.communication.jdbc.JDBCDatabaseCommunicationEngine;
 import 
org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.BackendConnection;
-import 
org.apache.shardingsphere.proxy.backend.communication.jdbc.execute.engine.jdbc.JDBCExecuteEngine;
-import 
org.apache.shardingsphere.proxy.backend.communication.jdbc.execute.engine.RegistryCenterExecuteEngine;
 import 
org.apache.shardingsphere.proxy.backend.communication.jdbc.execute.SQLExecuteEngine;
+import 
org.apache.shardingsphere.proxy.backend.communication.jdbc.execute.engine.RDLExecuteEngine;
+import 
org.apache.shardingsphere.proxy.backend.communication.jdbc.execute.engine.jdbc.JDBCExecuteEngine;
 import 
org.apache.shardingsphere.proxy.backend.communication.jdbc.wrapper.JDBCExecutorWrapper;
 import 
org.apache.shardingsphere.proxy.backend.communication.jdbc.wrapper.PreparedStatementExecutorWrapper;
 import 
org.apache.shardingsphere.proxy.backend.communication.jdbc.wrapper.StatementExecutorWrapper;
-import 
org.apache.shardingsphere.rdl.parser.statement.rdl.CreateDataSourcesStatement;
-import 
org.apache.shardingsphere.rdl.parser.statement.rdl.CreateShardingRuleStatement;
+import org.apache.shardingsphere.rdl.parser.statement.rdl.RDLStatement;
 import org.apache.shardingsphere.sql.parser.sql.statement.SQLStatement;
 
 import java.util.List;
@@ -80,7 +79,6 @@ public final class DatabaseCommunicationEngineFactory {
     }
     
     private SQLExecuteEngine createSQLExecuteEngine(final SchemaContext 
schema, final SQLStatement sqlStatement, final BackendConnection 
backendConnection, final JDBCExecutorWrapper executorWrapper) {
-        return sqlStatement instanceof CreateDataSourcesStatement || 
sqlStatement instanceof CreateShardingRuleStatement
-                ? new RegistryCenterExecuteEngine(schema.getName(), 
sqlStatement) : new JDBCExecuteEngine(backendConnection, executorWrapper);
+        return sqlStatement instanceof RDLStatement ? new 
RDLExecuteEngine(schema, sqlStatement) : new 
JDBCExecuteEngine(backendConnection, executorWrapper);
     }
 }
diff --git 
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/JDBCDatabaseCommunicationEngine.java
 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/JDBCDatabaseCommunicationEngine.java
index 6cb82fc..f959089 100644
--- 
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/JDBCDatabaseCommunicationEngine.java
+++ 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/JDBCDatabaseCommunicationEngine.java
@@ -42,6 +42,7 @@ import 
org.apache.shardingsphere.proxy.backend.response.query.QueryData;
 import org.apache.shardingsphere.proxy.backend.response.query.QueryResponse;
 import org.apache.shardingsphere.proxy.backend.response.update.UpdateResponse;
 import org.apache.shardingsphere.proxy.backend.schema.ProxySchemaContexts;
+import 
org.apache.shardingsphere.rdl.parser.binder.context.CreateSchemaStatementContext;
 import 
org.apache.shardingsphere.sql.parser.binder.metadata.table.TableMetaData;
 import 
org.apache.shardingsphere.sql.parser.binder.statement.SQLStatementContext;
 import org.apache.shardingsphere.sql.parser.binder.type.TableAvailable;
@@ -154,6 +155,9 @@ public final class JDBCDatabaseCommunicationEngine 
implements DatabaseCommunicat
     }
     
     private boolean isNeedAccumulate(final SQLStatementContext 
sqlStatementContext) {
+        if (sqlStatementContext instanceof CreateSchemaStatementContext) {
+            return false;
+        }
         Optional<DataNodeRoutedRule> dataNodeRoutedRule = 
schema.getSchema().getRules().stream().filter(each -> each instanceof 
DataNodeRoutedRule).findFirst().map(rule -> (DataNodeRoutedRule) rule);
         return dataNodeRoutedRule.isPresent() && 
dataNodeRoutedRule.get().isNeedAccumulate(sqlStatementContext.getTablesContext().getTableNames());
     }
diff --git 
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/execute/engine/RegistryCenterExecuteEngine.java
 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/execute/engine/RDLExecuteEngine.java
similarity index 67%
rename from 
shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/execute/engine/RegistryCenterExecuteEngine.java
rename to 
shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/execute/engine/RDLExecuteEngine.java
index 91af073..8e8743d 100644
--- 
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/execute/engine/RegistryCenterExecuteEngine.java
+++ 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/execute/engine/RDLExecuteEngine.java
@@ -20,11 +20,15 @@ package 
org.apache.shardingsphere.proxy.backend.communication.jdbc.execute.engin
 import lombok.RequiredArgsConstructor;
 import 
org.apache.shardingsphere.infra.callback.orchestration.DataSourceCallback;
 import org.apache.shardingsphere.infra.callback.orchestration.RuleCallback;
+import 
org.apache.shardingsphere.infra.callback.orchestration.SchemaNameCallback;
 import org.apache.shardingsphere.infra.config.DataSourceConfiguration;
 import org.apache.shardingsphere.infra.config.RuleConfiguration;
 import org.apache.shardingsphere.infra.database.type.DatabaseType;
 import org.apache.shardingsphere.infra.executor.sql.context.ExecutionContext;
+import org.apache.shardingsphere.infra.executor.sql.context.ExecutionUnit;
+import org.apache.shardingsphere.infra.executor.sql.context.SQLUnit;
 import 
org.apache.shardingsphere.infra.yaml.swapper.YamlRuleConfigurationSwapperEngine;
+import org.apache.shardingsphere.kernel.context.SchemaContext;
 import org.apache.shardingsphere.kernel.context.StandardSchemaContexts;
 import 
org.apache.shardingsphere.proxy.backend.communication.jdbc.execute.SQLExecuteEngine;
 import org.apache.shardingsphere.proxy.backend.response.BackendResponse;
@@ -35,8 +39,10 @@ import 
org.apache.shardingsphere.proxy.config.util.DataSourceConverter;
 import org.apache.shardingsphere.proxy.config.yaml.YamlDataSourceParameter;
 import 
org.apache.shardingsphere.proxy.convert.CreateDataSourcesStatementContextConverter;
 import 
org.apache.shardingsphere.rdl.parser.binder.context.CreateDataSourcesStatementContext;
+import 
org.apache.shardingsphere.rdl.parser.binder.context.CreateSchemaStatementContext;
 import 
org.apache.shardingsphere.rdl.parser.binder.context.CreateShardingRuleStatementContext;
 import 
org.apache.shardingsphere.rdl.parser.statement.rdl.CreateDataSourcesStatement;
+import 
org.apache.shardingsphere.rdl.parser.statement.rdl.CreateSchemaStatement;
 import 
org.apache.shardingsphere.rdl.parser.statement.rdl.CreateShardingRuleStatement;
 import 
org.apache.shardingsphere.sharding.convert.CreateShardingRuleStatementContextConverter;
 import 
org.apache.shardingsphere.sharding.yaml.config.YamlShardingRuleConfiguration;
@@ -50,22 +56,18 @@ import java.util.LinkedList;
 import java.util.Map;
 
 /**
- * Registry center execute engine.
+ * RDL execute engine.
  */
 @RequiredArgsConstructor
-public final class RegistryCenterExecuteEngine implements SQLExecuteEngine {
+public final class RDLExecuteEngine implements SQLExecuteEngine {
     
-    private final String schemaName;
+    private final SchemaContext schema;
     
     private final SQLStatement sqlStatement;
     
     @Override
     public ExecutionContext execute(final String sql) {
-        DatabaseType databaseType = 
ProxySchemaContexts.getInstance().getSchemaContexts().getDatabaseType();
-        SQLStatementContext<?> sqlStatementContext = sqlStatement instanceof 
CreateDataSourcesStatement
-                ? new 
CreateDataSourcesStatementContext((CreateDataSourcesStatement) sqlStatement, 
databaseType)
-                : new 
CreateShardingRuleStatementContext((CreateShardingRuleStatement) sqlStatement);
-        return new ExecutionContext(sqlStatementContext, new LinkedList<>());
+        return new ExecutionContext(getSqlStatementContext(), 
Collections.singleton(getExecutionUnit(sql)));
     }
     
     @Override
@@ -73,17 +75,22 @@ public final class RegistryCenterExecuteEngine implements 
SQLExecuteEngine {
         if (!isRegistryCenterExisted()) {
             return new ErrorResponse(new SQLException("No Registry center to 
execute `%s` SQL", 
executionContext.getSqlStatementContext().getClass().getSimpleName()));
         }
-        if (executionContext.getSqlStatementContext() instanceof 
CreateDataSourcesStatementContext) {
-            return execute((CreateDataSourcesStatementContext) 
executionContext.getSqlStatementContext());
-        }
-        return execute((CreateShardingRuleStatementContext) 
executionContext.getSqlStatementContext());
+        return getBackendResponse(executionContext.getSqlStatementContext());
+    }
+    
+    private BackendResponse execute(final CreateSchemaStatementContext 
context) {
+        
SchemaNameCallback.getInstance().run(context.getSqlStatement().getSchemaName(), 
true);
+        // TODO Need to get the executed feedback from registry center for 
returning.
+        UpdateResponse result = new UpdateResponse();
+        result.setType("CREATE");
+        return result;
     }
     
     private BackendResponse execute(final CreateDataSourcesStatementContext 
context) {
         Map<String, YamlDataSourceParameter> parameters = new 
CreateDataSourcesStatementContextConverter().convert(context);
         Map<String, DataSourceConfiguration> dataSources = 
DataSourceConverter.getDataSourceConfigurationMap(DataSourceConverter.getDataSourceParameterMap2(parameters));
         // TODO Need to get the executed feedback from registry center for 
returning.
-        DataSourceCallback.getInstance().run(schemaName, dataSources);
+        DataSourceCallback.getInstance().run(schema.getName(), dataSources);
         UpdateResponse result = new UpdateResponse();
         result.setType("CREATE");
         return result;
@@ -93,12 +100,36 @@ public final class RegistryCenterExecuteEngine implements 
SQLExecuteEngine {
         YamlShardingRuleConfiguration configurations = new 
CreateShardingRuleStatementContextConverter().convert(context);
         Collection<RuleConfiguration> rules = new 
YamlRuleConfigurationSwapperEngine().swapToRuleConfigurations(Collections.singleton(configurations));
         // TODO Need to get the executed feedback from registry center for 
returning.
-        RuleCallback.getInstance().run(schemaName, rules);
+        RuleCallback.getInstance().run(schema.getName(), rules);
         UpdateResponse result = new UpdateResponse();
         result.setType("CREATE");
         return result;
     }
     
+    private SQLStatementContext<?> getSqlStatementContext() {
+        DatabaseType databaseType = 
ProxySchemaContexts.getInstance().getSchemaContexts().getDatabaseType();
+        if (sqlStatement instanceof CreateDataSourcesStatement) {
+            return new 
CreateDataSourcesStatementContext((CreateDataSourcesStatement) sqlStatement, 
databaseType);
+        } else if (sqlStatement instanceof CreateShardingRuleStatement) {
+            return new 
CreateShardingRuleStatementContext((CreateShardingRuleStatement) sqlStatement);
+        }
+        return new CreateSchemaStatementContext((CreateSchemaStatement) 
sqlStatement);
+    }
+    
+    private ExecutionUnit getExecutionUnit(final String sql) {
+        return new ExecutionUnit("", new SQLUnit(sql, new LinkedList<>()));
+    }
+    
+    private BackendResponse getBackendResponse(final SQLStatementContext 
context) {
+        if (context instanceof CreateSchemaStatementContext) {
+            return execute((CreateSchemaStatementContext) context);
+        }
+        if (context instanceof CreateDataSourcesStatementContext) {
+            return execute((CreateDataSourcesStatementContext) context);
+        }
+        return execute((CreateShardingRuleStatementContext) context);
+    }
+    
     private boolean isRegistryCenterExisted() {
         return !(ProxySchemaContexts.getInstance().getSchemaContexts() 
instanceof StandardSchemaContexts);
     }
diff --git 
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/query/QueryBackendHandler.java
 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/query/QueryBackendHandler.java
index c37e8fa..e53dc84 100644
--- 
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/query/QueryBackendHandler.java
+++ 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/query/QueryBackendHandler.java
@@ -26,6 +26,7 @@ import 
org.apache.shardingsphere.proxy.backend.response.BackendResponse;
 import org.apache.shardingsphere.proxy.backend.response.error.ErrorResponse;
 import org.apache.shardingsphere.proxy.backend.response.query.QueryData;
 import org.apache.shardingsphere.proxy.backend.text.TextProtocolBackendHandler;
+import 
org.apache.shardingsphere.rdl.parser.statement.rdl.CreateSchemaStatement;
 import org.apache.shardingsphere.sql.parser.sql.statement.SQLStatement;
 
 import java.sql.SQLException;
@@ -48,13 +49,17 @@ public final class QueryBackendHandler implements 
TextProtocolBackendHandler {
     
     @Override
     public BackendResponse execute() {
-        if (null == backendConnection.getSchema()) {
+        if (!hasSelectedOrNewSchema()) {
             return new ErrorResponse(new NoDatabaseSelectedException());
         }
         databaseCommunicationEngine = 
databaseCommunicationEngineFactory.newTextProtocolInstance(sqlStatement, sql, 
backendConnection);
         return databaseCommunicationEngine.execute();
     }
     
+    private boolean hasSelectedOrNewSchema() {
+        return null != backendConnection.getSchema() || sqlStatement 
instanceof CreateSchemaStatement;
+    }
+    
     @Override
     public boolean next() throws SQLException {
         return databaseCommunicationEngine.next();
diff --git 
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/execute/RegistryCenterExecuteEngineTest.java
 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/execute/RDLExecuteEngineTest.java
similarity index 90%
rename from 
shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/execute/RegistryCenterExecuteEngineTest.java
rename to 
shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/execute/RDLExecuteEngineTest.java
index 7416d0d..0f3c715 100644
--- 
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/execute/RegistryCenterExecuteEngineTest.java
+++ 
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/execute/RDLExecuteEngineTest.java
@@ -19,8 +19,9 @@ package 
org.apache.shardingsphere.proxy.backend.communication.jdbc.execute;
 
 import lombok.SneakyThrows;
 import org.apache.shardingsphere.infra.executor.sql.context.ExecutionContext;
+import org.apache.shardingsphere.kernel.context.SchemaContext;
 import org.apache.shardingsphere.kernel.context.StandardSchemaContexts;
-import 
org.apache.shardingsphere.proxy.backend.communication.jdbc.execute.engine.RegistryCenterExecuteEngine;
+import 
org.apache.shardingsphere.proxy.backend.communication.jdbc.execute.engine.RDLExecuteEngine;
 import org.apache.shardingsphere.proxy.backend.response.BackendResponse;
 import org.apache.shardingsphere.proxy.backend.response.error.ErrorResponse;
 import org.apache.shardingsphere.proxy.backend.response.update.UpdateResponse;
@@ -44,7 +45,7 @@ import static org.junit.Assert.assertThat;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 
-public final class RegistryCenterExecuteEngineTest {
+public final class RDLExecuteEngineTest {
     
     private CreateDataSourcesStatementContext dataSourcesContext;
     
@@ -74,7 +75,8 @@ public final class RegistryCenterExecuteEngineTest {
     
     @Test
     public void assertExecuteDataSourcesContext() {
-        RegistryCenterExecuteEngine executeEngine = new 
RegistryCenterExecuteEngine("sharding_db", 
mock(CreateDataSourcesStatement.class));
+        SchemaContext context = new SchemaContext("sharding_db", null, null);
+        RDLExecuteEngine executeEngine = new RDLExecuteEngine(context, 
mock(CreateDataSourcesStatement.class));
         BackendResponse response = executeEngine.execute(new 
ExecutionContext(dataSourcesContext, new LinkedList<>()));
         assertThat(response, instanceOf(ErrorResponse.class));
         setOrchestrationSchemaContexts(true);
@@ -84,7 +86,8 @@ public final class RegistryCenterExecuteEngineTest {
     
     @Test
     public void assertExecuteShardingRuleContext() {
-        RegistryCenterExecuteEngine executeEngine = new 
RegistryCenterExecuteEngine("sharding_db", 
mock(CreateShardingRuleStatement.class));
+        SchemaContext context = new SchemaContext("sharding_db", null, null);
+        RDLExecuteEngine executeEngine = new RDLExecuteEngine(context, 
mock(CreateShardingRuleStatement.class));
         BackendResponse response = executeEngine.execute(new 
ExecutionContext(ruleContext, new LinkedList<>()));
         assertThat(response, instanceOf(ErrorResponse.class));
         setOrchestrationSchemaContexts(true);
diff --git 
a/shardingsphere-rdl-parser/shardingsphere-rdl-parser-sql/src/main/antlr4/imports/Keyword.g4
 
b/shardingsphere-rdl-parser/shardingsphere-rdl-parser-binder/src/main/java/org/apache/shardingsphere/rdl/parser/binder/context/CreateSchemaStatementContext.java
similarity index 60%
copy from 
shardingsphere-rdl-parser/shardingsphere-rdl-parser-sql/src/main/antlr4/imports/Keyword.g4
copy to 
shardingsphere-rdl-parser/shardingsphere-rdl-parser-binder/src/main/java/org/apache/shardingsphere/rdl/parser/binder/context/CreateSchemaStatementContext.java
index fcb8ead..60739cc 100644
--- 
a/shardingsphere-rdl-parser/shardingsphere-rdl-parser-sql/src/main/antlr4/imports/Keyword.g4
+++ 
b/shardingsphere-rdl-parser/shardingsphere-rdl-parser-binder/src/main/java/org/apache/shardingsphere/rdl/parser/binder/context/CreateSchemaStatementContext.java
@@ -15,22 +15,19 @@
  * limitations under the License.
  */
 
-lexer grammar Keyword;
+package org.apache.shardingsphere.rdl.parser.binder.context;
 
-import Alphabet;
+import lombok.Getter;
+import 
org.apache.shardingsphere.rdl.parser.statement.rdl.CreateSchemaStatement;
+import 
org.apache.shardingsphere.sql.parser.binder.statement.CommonSQLStatementContext;
 
-WS
-    : [ \t\r\n] + ->skip
-    ;
-    
-CREATE
-    : C R E A T E
-    ;
-    
-DATASOURCE
-    : D A T A S O U R C E
-    ;
+/**
+ * Create schema statement context.
+ */
+@Getter
+public final class CreateSchemaStatementContext extends 
CommonSQLStatementContext<CreateSchemaStatement> {
     
-SHARDINGRULE
-    : S H A R D I N G R U L E
-    ;
+    public CreateSchemaStatementContext(final CreateSchemaStatement 
sqlStatement) {
+        super(sqlStatement);
+    }
+}
diff --git 
a/shardingsphere-rdl-parser/shardingsphere-rdl-parser-sql/src/main/antlr4/imports/Keyword.g4
 
b/shardingsphere-rdl-parser/shardingsphere-rdl-parser-sql/src/main/antlr4/imports/Keyword.g4
index fcb8ead..4380b16 100644
--- 
a/shardingsphere-rdl-parser/shardingsphere-rdl-parser-sql/src/main/antlr4/imports/Keyword.g4
+++ 
b/shardingsphere-rdl-parser/shardingsphere-rdl-parser-sql/src/main/antlr4/imports/Keyword.g4
@@ -26,7 +26,11 @@ WS
 CREATE
     : C R E A T E
     ;
-    
+
+SCHEMA
+    : S C H E M A
+    ;
+
 DATASOURCE
     : D A T A S O U R C E
     ;
diff --git 
a/shardingsphere-rdl-parser/shardingsphere-rdl-parser-sql/src/main/antlr4/imports/RDLStatement.g4
 
b/shardingsphere-rdl-parser/shardingsphere-rdl-parser-sql/src/main/antlr4/imports/RDLStatement.g4
index dacf511..081bc0a 100644
--- 
a/shardingsphere-rdl-parser/shardingsphere-rdl-parser-sql/src/main/antlr4/imports/RDLStatement.g4
+++ 
b/shardingsphere-rdl-parser/shardingsphere-rdl-parser-sql/src/main/antlr4/imports/RDLStatement.g4
@@ -19,6 +19,10 @@ grammar RDLStatement;
 
 import Keyword, Literals, Symbol;
 
+createSchema
+    : CREATE SCHEMA schemaName
+    ;
+
 createDatasource
     : CREATE DATASOURCE datasource (COMMA datasource)*
     ;
@@ -62,6 +66,10 @@ strategyProp
     : IDENTIFIER | NUMBER | INT
     ;
 
+schemaName
+    : IDENTIFIER
+    ;
+
 tableName
     : IDENTIFIER
     ;
diff --git 
a/shardingsphere-rdl-parser/shardingsphere-rdl-parser-sql/src/main/antlr4/org/apache/shardingsphere/rdl/parser/autogen/ShardingSphereStatement.g4
 
b/shardingsphere-rdl-parser/shardingsphere-rdl-parser-sql/src/main/antlr4/org/apache/shardingsphere/rdl/parser/autogen/ShardingSphereStatement.g4
index 4e25fc0..7640aee 100644
--- 
a/shardingsphere-rdl-parser/shardingsphere-rdl-parser-sql/src/main/antlr4/org/apache/shardingsphere/rdl/parser/autogen/ShardingSphereStatement.g4
+++ 
b/shardingsphere-rdl-parser/shardingsphere-rdl-parser-sql/src/main/antlr4/org/apache/shardingsphere/rdl/parser/autogen/ShardingSphereStatement.g4
@@ -20,6 +20,7 @@ grammar ShardingSphereStatement;
 import Symbol, RDLStatement;
 
 execute
-    : (createDatasource
+    : (createSchema
+    | createDatasource
     ) SEMI?
     ;
diff --git 
a/shardingsphere-rdl-parser/shardingsphere-rdl-parser-sql/src/main/java/org/apache/shardingsphere/rdl/parser/sql/visitor/ShardingSphereVisitor.java
 
b/shardingsphere-rdl-parser/shardingsphere-rdl-parser-sql/src/main/java/org/apache/shardingsphere/rdl/parser/sql/visitor/ShardingSphereVisitor.java
index 17a34c9..299f26d 100644
--- 
a/shardingsphere-rdl-parser/shardingsphere-rdl-parser-sql/src/main/java/org/apache/shardingsphere/rdl/parser/sql/visitor/ShardingSphereVisitor.java
+++ 
b/shardingsphere-rdl-parser/shardingsphere-rdl-parser-sql/src/main/java/org/apache/shardingsphere/rdl/parser/sql/visitor/ShardingSphereVisitor.java
@@ -20,10 +20,12 @@ package org.apache.shardingsphere.rdl.parser.sql.visitor;
 import lombok.AccessLevel;
 import lombok.Getter;
 import 
org.apache.shardingsphere.rdl.parser.autogen.ShardingSphereStatementBaseVisitor;
+import 
org.apache.shardingsphere.rdl.parser.autogen.ShardingSphereStatementParser.CreateSchemaContext;
 import 
org.apache.shardingsphere.rdl.parser.autogen.ShardingSphereStatementParser.CreateDatasourceContext;
 import 
org.apache.shardingsphere.rdl.parser.autogen.ShardingSphereStatementParser.DatasourceContext;
 import 
org.apache.shardingsphere.rdl.parser.autogen.ShardingSphereStatementParser.DatasourceValueContext;
 import 
org.apache.shardingsphere.rdl.parser.statement.rdl.CreateDataSourcesStatement;
+import 
org.apache.shardingsphere.rdl.parser.statement.rdl.CreateSchemaStatement;
 import 
org.apache.shardingsphere.rdl.parser.statement.rdl.DataSourceConnectionSegment;
 import org.apache.shardingsphere.sql.parser.api.ASTNode;
 
@@ -37,6 +39,11 @@ import java.util.LinkedList;
 public final class ShardingSphereVisitor extends 
ShardingSphereStatementBaseVisitor<ASTNode> {
     
     @Override
+    public ASTNode visitCreateSchema(final CreateSchemaContext ctx) {
+        return new CreateSchemaStatement(ctx.schemaName().getText());
+    }
+    
+    @Override
     public ASTNode visitCreateDatasource(final CreateDatasourceContext ctx) {
         Collection<DataSourceConnectionSegment> connectionInfos = new 
LinkedList<>();
         for (DatasourceContext each : ctx.datasource()) {
diff --git 
a/shardingsphere-rdl-parser/shardingsphere-rdl-parser-sql/src/main/antlr4/imports/Keyword.g4
 
b/shardingsphere-rdl-parser/shardingsphere-rdl-parser-statement/src/main/java/org/apache/shardingsphere/rdl/parser/statement/rdl/CreateSchemaStatement.java
similarity index 73%
copy from 
shardingsphere-rdl-parser/shardingsphere-rdl-parser-sql/src/main/antlr4/imports/Keyword.g4
copy to 
shardingsphere-rdl-parser/shardingsphere-rdl-parser-statement/src/main/java/org/apache/shardingsphere/rdl/parser/statement/rdl/CreateSchemaStatement.java
index fcb8ead..30b49c3 100644
--- 
a/shardingsphere-rdl-parser/shardingsphere-rdl-parser-sql/src/main/antlr4/imports/Keyword.g4
+++ 
b/shardingsphere-rdl-parser/shardingsphere-rdl-parser-statement/src/main/java/org/apache/shardingsphere/rdl/parser/statement/rdl/CreateSchemaStatement.java
@@ -15,22 +15,17 @@
  * limitations under the License.
  */
 
-lexer grammar Keyword;
+package org.apache.shardingsphere.rdl.parser.statement.rdl;
 
-import Alphabet;
+import lombok.Getter;
+import lombok.RequiredArgsConstructor;
 
-WS
-    : [ \t\r\n] + ->skip
-    ;
-    
-CREATE
-    : C R E A T E
-    ;
-    
-DATASOURCE
-    : D A T A S O U R C E
-    ;
+/**
+ * Create schema statement.
+ */
+@RequiredArgsConstructor
+@Getter
+public final class CreateSchemaStatement extends RDLStatement {
     
-SHARDINGRULE
-    : S H A R D I N G R U L E
-    ;
+    private final String schemaName;
+}

Reply via email to