This is an automated email from the ASF dual-hosted git repository.
jianglongtao 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 4d32950a898 Migrate global rule (SQLParserRule) to
shardingsphere-parser-distsql module. (#20804)
4d32950a898 is described below
commit 4d32950a89816ec0a80d060b5c4a6f29869720f9
Author: yx9o <[email protected]>
AuthorDate: Tue Sep 6 10:56:23 2022 +0800
Migrate global rule (SQLParserRule) to shardingsphere-parser-distsql
module. (#20804)
---
.../src/main/antlr4/imports/Keyword.g4 | 28 ---------
.../src/main/antlr4/imports/RALStatement.g4 | 40 ------------
.../parser/autogen/KernelDistSQLStatement.g4 | 2 -
.../core/kernel/KernelDistSQLStatementVisitor.java | 32 ----------
.../shardingsphere-parser/pom.xml | 2 +-
.../{ => shardingsphere-parser-distsql}/pom.xml | 11 ++--
.../shardingsphere-parser-distsql-handler}/pom.xml | 28 ++++++---
.../handler/query/SQLParserRuleQueryResultSet.java | 73 ++++++++++++++++++++++
.../update/AlterSQLParserRuleStatementUpdater.java | 68 ++++++++++++++++++++
...dingsphere.infra.distsql.query.DistSQLResultSet | 18 ++++++
...phere.infra.distsql.update.GlobalRuleRALUpdater | 18 ++++++
.../query/SQLParserRuleQueryResultSetTest.java | 46 ++++++--------
.../AlterSQLParserRuleStatementUpdaterTest.java | 46 +++++---------
.../shardingsphere-parser-distsql-parser/pom.xml | 69 ++++++++++++++++++++
.../src/main/antlr4/imports/parser/Alphabet.g4 | 44 ++++++++-----
.../src/main/antlr4/imports/parser/Keyword.g4 | 68 +++++++++++++++-----
.../src/main/antlr4/imports/parser/Literals.g4 | 22 ++++---
.../src/main/antlr4/imports/parser/RALStatement.g4 | 48 +++++++++++---
.../src/main/antlr4/imports/parser/Symbol.g4 | 62 ++++++++++++++++++
.../parser/autogen/SQLParserDistSQLStatement.g4 | 14 ++---
.../distsql/parser/core/SQLParserDistSQLLexer.java | 20 +++---
.../parser/core/SQLParserDistSQLParser.java | 24 ++++---
.../core/SQLParserDistSQLStatementVisitor.java | 66 +++++++++++++++++++
.../SQLParserDistSQLStatementParserFacade.java | 52 +++++++++++++++
...engine.spi.FeaturedDistSQLStatementParserFacade | 18 ++++++
.../pom.xml | 18 +++---
.../distsql/parser/segment/CacheOptionSegment.java | 2 +-
.../queryable/ShowSQLParserRuleStatement.java | 6 +-
.../updatable/AlterSQLParserRuleStatement.java | 8 +--
.../shardingsphere-proxy-backend/pom.xml | 5 ++
.../distsql/ral/RALBackendHandlerFactory.java | 6 --
.../ral/queryable/ShowSQLParserRuleHandler.java | 60 ------------------
.../ral/updatable/AlterSQLParserRuleHandler.java | 73 ----------------------
.../shardingsphere/sql/parser/api/CacheOption.java | 5 ++
.../shardingsphere-parser-test/pom.xml | 5 ++
.../ral/impl/QueryableRALStatementAssert.java | 2 +-
.../ral/impl/UpdatableRALStatementAssert.java | 2 +-
.../ShowSQLParserRuleStatementAssert.java | 10 ++-
.../AlterSQLParserRuleStatementAssert.java | 4 +-
39 files changed, 719 insertions(+), 406 deletions(-)
diff --git
a/shardingsphere-distsql/shardingsphere-distsql-parser/src/main/antlr4/imports/Keyword.g4
b/shardingsphere-distsql/shardingsphere-distsql-parser/src/main/antlr4/imports/Keyword.g4
index d0c065eadfd..a80064da811 100644
---
a/shardingsphere-distsql/shardingsphere-distsql-parser/src/main/antlr4/imports/Keyword.g4
+++
b/shardingsphere-distsql/shardingsphere-distsql-parser/src/main/antlr4/imports/Keyword.g4
@@ -179,10 +179,6 @@ METADATA
: M E T A D A T A
;
-SQL_PARSER
- : S Q L UL_ P A R S E R
- ;
-
AUTHORITY
: A U T H O R I T Y
;
@@ -195,30 +191,6 @@ FALSE
: F A L S E
;
-SQL_COMMENT_PARSE_ENABLE
- : S Q L UL_ C O M M E N T UL_ P A R S E UL_ E N A B L E
- ;
-
-PARSE_TREE_CACHE
- : P A R S E UL_ T R E E UL_ C A C H E
- ;
-
-SQL_STATEMENT_CACHE
- : S Q L UL_ S T A T E M E N T UL_ C A C H E
- ;
-
-INITIAL_CAPACITY
- : I N I T I A L UL_ C A P A C I T Y
- ;
-
-MAXIMUM_SIZE
- : M A X I M U M UL_ S I Z E
- ;
-
-CONCURRENCY_LEVEL
- : C O N C U R R E N C Y UL_ L E V E L
- ;
-
IF
: I F
;
diff --git
a/shardingsphere-distsql/shardingsphere-distsql-parser/src/main/antlr4/imports/RALStatement.g4
b/shardingsphere-distsql/shardingsphere-distsql-parser/src/main/antlr4/imports/RALStatement.g4
index 61825fc545b..32107480059 100644
---
a/shardingsphere-distsql/shardingsphere-distsql-parser/src/main/antlr4/imports/RALStatement.g4
+++
b/shardingsphere-distsql/shardingsphere-distsql-parser/src/main/antlr4/imports/RALStatement.g4
@@ -59,14 +59,6 @@ showTableMetadata
: SHOW TABLE METADATA tableName (COMMA tableName*)? (FROM databaseName)?
;
-showSQLParserRule
- : SHOW SQL_PARSER RULE
- ;
-
-alterSQLParserRule
- : ALTER SQL_PARSER RULE sqlParserRuleDefinition
- ;
-
showInstanceInfo
: SHOW INSTANCE INFO
;
@@ -155,10 +147,6 @@ filePath
: STRING
;
-sqlParserRuleDefinition
- : SQL_COMMENT_PARSE_ENABLE EQ sqlCommentParseEnable (COMMA
PARSE_TREE_CACHE LP parseTreeCache RP)? (COMMA SQL_STATEMENT_CACHE LP
sqlStatementCache RP)?
- ;
-
variableName
: IDENTIFIER
;
@@ -183,34 +171,6 @@ fromSegment
: FROM RESOURCE resourceName (SCHEMA schemaName)?
;
-sqlCommentParseEnable
- : TRUE | FALSE
- ;
-
-parseTreeCache
- : cacheOption
- ;
-
-sqlStatementCache
- : cacheOption
- ;
-
-cacheOption
- : (INITIAL_CAPACITY EQ initialCapacity)? (COMMA? MAXIMUM_SIZE EQ
maximumSize)? (COMMA? CONCURRENCY_LEVEL EQ concurrencyLevel)?
- ;
-
-initialCapacity
- : INT
- ;
-
-maximumSize
- : INT
- ;
-
-concurrencyLevel
- : INT
- ;
-
label
: IDENTIFIER
;
diff --git
a/shardingsphere-distsql/shardingsphere-distsql-parser/src/main/antlr4/org/apache/shardingsphere/distsql/parser/autogen/KernelDistSQLStatement.g4
b/shardingsphere-distsql/shardingsphere-distsql-parser/src/main/antlr4/org/apache/shardingsphere/distsql/parser/autogen/KernelDistSQLStatement.g4
index c4b2b79b4a4..d551ddbd684 100644
---
a/shardingsphere-distsql/shardingsphere-distsql-parser/src/main/antlr4/org/apache/shardingsphere/distsql/parser/autogen/KernelDistSQLStatement.g4
+++
b/shardingsphere-distsql/shardingsphere-distsql-parser/src/main/antlr4/org/apache/shardingsphere/distsql/parser/autogen/KernelDistSQLStatement.g4
@@ -49,8 +49,6 @@ execute
| dropDefaultSingleTableRule
| refreshTableMetadata
| showTableMetadata
- | showSQLParserRule
- | alterSQLParserRule
| exportDatabaseConfiguration
| showRulesUsedResource
| importDatabaseConfiguration
diff --git
a/shardingsphere-distsql/shardingsphere-distsql-parser/src/main/java/org/apache/shardingsphere/distsql/parser/core/kernel/KernelDistSQLStatementVisitor.java
b/shardingsphere-distsql/shardingsphere-distsql-parser/src/main/java/org/apache/shardingsphere/distsql/parser/core/kernel/KernelDistSQLStatementVisitor.java
index fcfc88d2575..eaa0cad5322 100644
---
a/shardingsphere-distsql/shardingsphere-distsql-parser/src/main/java/org/apache/shardingsphere/distsql/parser/core/kernel/KernelDistSQLStatementVisitor.java
+++
b/shardingsphere-distsql/shardingsphere-distsql-parser/src/main/java/org/apache/shardingsphere/distsql/parser/core/kernel/KernelDistSQLStatementVisitor.java
@@ -26,10 +26,8 @@ import
org.apache.shardingsphere.distsql.parser.autogen.KernelDistSQLStatementPa
import
org.apache.shardingsphere.distsql.parser.autogen.KernelDistSQLStatementParser.AlterInstanceContext;
import
org.apache.shardingsphere.distsql.parser.autogen.KernelDistSQLStatementParser.AlterMigrationProcessConfigurationContext;
import
org.apache.shardingsphere.distsql.parser.autogen.KernelDistSQLStatementParser.AlterResourceContext;
-import
org.apache.shardingsphere.distsql.parser.autogen.KernelDistSQLStatementParser.AlterSQLParserRuleContext;
import
org.apache.shardingsphere.distsql.parser.autogen.KernelDistSQLStatementParser.ApplyDistSQLContext;
import
org.apache.shardingsphere.distsql.parser.autogen.KernelDistSQLStatementParser.BatchSizeContext;
-import
org.apache.shardingsphere.distsql.parser.autogen.KernelDistSQLStatementParser.CacheOptionContext;
import
org.apache.shardingsphere.distsql.parser.autogen.KernelDistSQLStatementParser.ClearHintContext;
import
org.apache.shardingsphere.distsql.parser.autogen.KernelDistSQLStatementParser.ConvertYamlConfigurationContext;
import
org.apache.shardingsphere.distsql.parser.autogen.KernelDistSQLStatementParser.CountDatabaseRulesContext;
@@ -65,20 +63,17 @@ import
org.apache.shardingsphere.distsql.parser.autogen.KernelDistSQLStatementPa
import
org.apache.shardingsphere.distsql.parser.autogen.KernelDistSQLStatementParser.ShowModeInfoContext;
import
org.apache.shardingsphere.distsql.parser.autogen.KernelDistSQLStatementParser.ShowResourcesContext;
import
org.apache.shardingsphere.distsql.parser.autogen.KernelDistSQLStatementParser.ShowRulesUsedResourceContext;
-import
org.apache.shardingsphere.distsql.parser.autogen.KernelDistSQLStatementParser.ShowSQLParserRuleContext;
import
org.apache.shardingsphere.distsql.parser.autogen.KernelDistSQLStatementParser.ShowSQLTranslatorRuleContext;
import
org.apache.shardingsphere.distsql.parser.autogen.KernelDistSQLStatementParser.ShowSingleTableContext;
import
org.apache.shardingsphere.distsql.parser.autogen.KernelDistSQLStatementParser.ShowSingleTableRulesContext;
import
org.apache.shardingsphere.distsql.parser.autogen.KernelDistSQLStatementParser.ShowTableMetadataContext;
import
org.apache.shardingsphere.distsql.parser.autogen.KernelDistSQLStatementParser.ShowUnusedResourcesContext;
import
org.apache.shardingsphere.distsql.parser.autogen.KernelDistSQLStatementParser.ShowVariableContext;
-import
org.apache.shardingsphere.distsql.parser.autogen.KernelDistSQLStatementParser.SqlParserRuleDefinitionContext;
import
org.apache.shardingsphere.distsql.parser.autogen.KernelDistSQLStatementParser.StreamChannelContext;
import
org.apache.shardingsphere.distsql.parser.autogen.KernelDistSQLStatementParser.UnlabelInstanceContext;
import
org.apache.shardingsphere.distsql.parser.autogen.KernelDistSQLStatementParser.WorkerThreadContext;
import
org.apache.shardingsphere.distsql.parser.autogen.KernelDistSQLStatementParser.WriteDefinitionContext;
import org.apache.shardingsphere.distsql.parser.segment.AlgorithmSegment;
-import org.apache.shardingsphere.distsql.parser.segment.CacheOptionSegment;
import org.apache.shardingsphere.distsql.parser.segment.DataSourceSegment;
import
org.apache.shardingsphere.distsql.parser.segment.HostnameAndPortBasedDataSourceSegment;
import
org.apache.shardingsphere.distsql.parser.segment.MigrationProcessConfigurationSegment;
@@ -92,13 +87,11 @@ import
org.apache.shardingsphere.distsql.parser.statement.ral.queryable.ShowInst
import
org.apache.shardingsphere.distsql.parser.statement.ral.queryable.ShowInstanceListStatement;
import
org.apache.shardingsphere.distsql.parser.statement.ral.queryable.ShowMigrationProcessConfigurationStatement;
import
org.apache.shardingsphere.distsql.parser.statement.ral.queryable.ShowModeInfoStatement;
-import
org.apache.shardingsphere.distsql.parser.statement.ral.queryable.ShowSQLParserRuleStatement;
import
org.apache.shardingsphere.distsql.parser.statement.ral.queryable.ShowSQLTranslatorRuleStatement;
import
org.apache.shardingsphere.distsql.parser.statement.ral.queryable.ShowTableMetadataStatement;
import
org.apache.shardingsphere.distsql.parser.statement.ral.queryable.ShowVariableStatement;
import
org.apache.shardingsphere.distsql.parser.statement.ral.updatable.AlterInstanceStatement;
import
org.apache.shardingsphere.distsql.parser.statement.ral.updatable.AlterMigrationProcessConfigurationStatement;
-import
org.apache.shardingsphere.distsql.parser.statement.ral.updatable.AlterSQLParserRuleStatement;
import
org.apache.shardingsphere.distsql.parser.statement.ral.updatable.ApplyDistSQLStatement;
import
org.apache.shardingsphere.distsql.parser.statement.ral.updatable.CreateMigrationProcessConfigurationStatement;
import
org.apache.shardingsphere.distsql.parser.statement.ral.updatable.DiscardDistSQLStatement;
@@ -323,31 +316,6 @@ public final class KernelDistSQLStatementVisitor extends
KernelDistSQLStatementB
return new RefreshTableMetadataStatement(tableName, resourceName,
schemaName);
}
- @Override
- public ASTNode visitShowSQLParserRule(final ShowSQLParserRuleContext ctx) {
- return new ShowSQLParserRuleStatement();
- }
-
- @Override
- public ASTNode visitAlterSQLParserRule(final AlterSQLParserRuleContext
ctx) {
- return super.visit(ctx.sqlParserRuleDefinition());
- }
-
- @Override
- public ASTNode visitSqlParserRuleDefinition(final
SqlParserRuleDefinitionContext ctx) {
- Boolean sqlCommentParseEnable = null == ctx.sqlCommentParseEnable() ?
null : Boolean.parseBoolean(getIdentifierValue(ctx.sqlCommentParseEnable()));
- CacheOptionSegment parseTreeCache = null == ctx.parseTreeCache() ?
null : visitCacheOption(ctx.parseTreeCache().cacheOption());
- CacheOptionSegment sqlStatementCache = null == ctx.sqlStatementCache()
? null : visitCacheOption(ctx.sqlStatementCache().cacheOption());
- return new AlterSQLParserRuleStatement(sqlCommentParseEnable,
parseTreeCache, sqlStatementCache);
- }
-
- @Override
- public CacheOptionSegment visitCacheOption(final CacheOptionContext ctx) {
- return new CacheOptionSegment(
- null == ctx.initialCapacity() ? null :
Integer.parseInt(getIdentifierValue(ctx.initialCapacity())),
- null == ctx.maximumSize() ? null :
Long.parseLong(getIdentifierValue(ctx.maximumSize())));
- }
-
@Override
public ASTNode visitExportDatabaseConfiguration(final
ExportDatabaseConfigurationContext ctx) {
return new ExportDatabaseConfigurationStatement(null ==
ctx.databaseName() ? null : (DatabaseSegment) visit(ctx.databaseName()),
getIdentifierValue(ctx.filePath()));
diff --git a/shardingsphere-kernel/shardingsphere-parser/pom.xml
b/shardingsphere-kernel/shardingsphere-parser/pom.xml
index f4da24627c9..f5e60c44a55 100644
--- a/shardingsphere-kernel/shardingsphere-parser/pom.xml
+++ b/shardingsphere-kernel/shardingsphere-parser/pom.xml
@@ -32,6 +32,6 @@
<module>shardingsphere-parser-api</module>
<module>shardingsphere-parser-core</module>
<module>shardingsphere-parser-spring</module>
+ <module>shardingsphere-parser-distsql</module>
</modules>
-
</project>
diff --git a/shardingsphere-kernel/shardingsphere-parser/pom.xml
b/shardingsphere-kernel/shardingsphere-parser/shardingsphere-parser-distsql/pom.xml
similarity index 81%
copy from shardingsphere-kernel/shardingsphere-parser/pom.xml
copy to
shardingsphere-kernel/shardingsphere-parser/shardingsphere-parser-distsql/pom.xml
index f4da24627c9..1dc2c81f967 100644
--- a/shardingsphere-kernel/shardingsphere-parser/pom.xml
+++
b/shardingsphere-kernel/shardingsphere-parser/shardingsphere-parser-distsql/pom.xml
@@ -21,17 +21,16 @@
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache.shardingsphere</groupId>
- <artifactId>shardingsphere-kernel</artifactId>
+ <artifactId>shardingsphere-parser</artifactId>
<version>5.1.3-SNAPSHOT</version>
</parent>
- <artifactId>shardingsphere-parser</artifactId>
+ <artifactId>shardingsphere-parser-distsql</artifactId>
<packaging>pom</packaging>
<name>${project.artifactId}</name>
<modules>
- <module>shardingsphere-parser-api</module>
- <module>shardingsphere-parser-core</module>
- <module>shardingsphere-parser-spring</module>
+ <module>shardingsphere-parser-distsql-statement</module>
+ <module>shardingsphere-parser-distsql-parser</module>
+ <module>shardingsphere-parser-distsql-handler</module>
</modules>
-
</project>
diff --git a/shardingsphere-kernel/shardingsphere-parser/pom.xml
b/shardingsphere-kernel/shardingsphere-parser/shardingsphere-parser-distsql/shardingsphere-parser-distsql-handler/pom.xml
similarity index 60%
copy from shardingsphere-kernel/shardingsphere-parser/pom.xml
copy to
shardingsphere-kernel/shardingsphere-parser/shardingsphere-parser-distsql/shardingsphere-parser-distsql-handler/pom.xml
index f4da24627c9..4c0fc400395 100644
--- a/shardingsphere-kernel/shardingsphere-parser/pom.xml
+++
b/shardingsphere-kernel/shardingsphere-parser/shardingsphere-parser-distsql/shardingsphere-parser-distsql-handler/pom.xml
@@ -21,17 +21,27 @@
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache.shardingsphere</groupId>
- <artifactId>shardingsphere-kernel</artifactId>
+ <artifactId>shardingsphere-parser-distsql</artifactId>
<version>5.1.3-SNAPSHOT</version>
</parent>
- <artifactId>shardingsphere-parser</artifactId>
- <packaging>pom</packaging>
+ <artifactId>shardingsphere-parser-distsql-handler</artifactId>
<name>${project.artifactId}</name>
- <modules>
- <module>shardingsphere-parser-api</module>
- <module>shardingsphere-parser-core</module>
- <module>shardingsphere-parser-spring</module>
- </modules>
-
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.shardingsphere</groupId>
+ <artifactId>shardingsphere-parser-core</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.shardingsphere</groupId>
+ <artifactId>shardingsphere-parser-distsql-statement</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.shardingsphere</groupId>
+ <artifactId>shardingsphere-parser-distsql-parser</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ </dependencies>
</project>
diff --git
a/shardingsphere-kernel/shardingsphere-parser/shardingsphere-parser-distsql/shardingsphere-parser-distsql-handler/src/main/java/org/apache/shardingsphere/parser/distsql/handler/query/SQLParserRuleQueryResultSet.java
b/shardingsphere-kernel/shardingsphere-parser/shardingsphere-parser-distsql/shardingsphere-parser-distsql-handler/src/main/java/org/apache/shardingsphere/parser/distsql/handler/query/SQLParserRuleQueryResultSet.java
new file mode 100644
index 00000000000..0b99067d0c3
--- /dev/null
+++
b/shardingsphere-kernel/shardingsphere-parser/shardingsphere-parser-distsql/shardingsphere-parser-distsql-handler/src/main/java/org/apache/shardingsphere/parser/distsql/handler/query/SQLParserRuleQueryResultSet.java
@@ -0,0 +1,73 @@
+/*
+ * 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.parser.distsql.handler.query;
+
+import
org.apache.shardingsphere.infra.distsql.query.GlobalRuleDistSQLResultSet;
+import
org.apache.shardingsphere.infra.metadata.database.rule.ShardingSphereRuleMetaData;
+import
org.apache.shardingsphere.parser.distsql.parser.statement.queryable.ShowSQLParserRuleStatement;
+import org.apache.shardingsphere.parser.rule.SQLParserRule;
+import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Iterator;
+
+/**
+ * Query result set for SQL parser rule.
+ */
+public final class SQLParserRuleQueryResultSet implements
GlobalRuleDistSQLResultSet {
+
+ private static final String SQL_COMMENT_PARSE_ENABLE =
"sql_comment_parse_enable";
+
+ private static final String PARSE_TREE_CACHE = "parse_tree_cache";
+
+ private static final String SQL_STATEMENT_CACHE = "sql_statement_cache";
+
+ private Iterator<Collection<Object>> data = Collections.emptyIterator();
+
+ @Override
+ public void init(final ShardingSphereRuleMetaData ruleMetaData, final
SQLStatement sqlStatement) {
+ ruleMetaData.findSingleRule(SQLParserRule.class).ifPresent(optional ->
data = buildData(optional).iterator());
+ }
+
+ private Collection<Collection<Object>> buildData(final SQLParserRule rule)
{
+ return
Collections.singleton(Arrays.asList(String.valueOf(rule.isSqlCommentParseEnabled()),
+ null != rule.getParseTreeCache() ?
rule.getParseTreeCache().toString() : "", null != rule.getSqlStatementCache() ?
rule.getSqlStatementCache().toString() : ""));
+ }
+
+ @Override
+ public Collection<String> getColumnNames() {
+ return Arrays.asList(SQL_COMMENT_PARSE_ENABLE, PARSE_TREE_CACHE,
SQL_STATEMENT_CACHE);
+ }
+
+ @Override
+ public boolean next() {
+ return data.hasNext();
+ }
+
+ @Override
+ public Collection<Object> getRowData() {
+ return data.next();
+ }
+
+ @Override
+ public String getType() {
+ return ShowSQLParserRuleStatement.class.getName();
+ }
+}
diff --git
a/shardingsphere-kernel/shardingsphere-parser/shardingsphere-parser-distsql/shardingsphere-parser-distsql-handler/src/main/java/org/apache/shardingsphere/parser/distsql/handler/update/AlterSQLParserRuleStatementUpdater.java
b/shardingsphere-kernel/shardingsphere-parser/shardingsphere-parser-distsql/shardingsphere-parser-distsql-handler/src/main/java/org/apache/shardingsphere/parser/distsql/handler/update/AlterSQLParserRuleStatementUpdater.java
new file mode 100644
index 00000000000..88809f5106f
--- /dev/null
+++
b/shardingsphere-kernel/shardingsphere-parser/shardingsphere-parser-distsql/shardingsphere-parser-distsql-handler/src/main/java/org/apache/shardingsphere/parser/distsql/handler/update/AlterSQLParserRuleStatementUpdater.java
@@ -0,0 +1,68 @@
+/*
+ * 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.parser.distsql.handler.update;
+
+import org.apache.shardingsphere.infra.distsql.exception.DistSQLException;
+import org.apache.shardingsphere.infra.distsql.update.GlobalRuleRALUpdater;
+import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
+import
org.apache.shardingsphere.infra.metadata.database.rule.ShardingSphereRuleMetaData;
+import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
+import org.apache.shardingsphere.parser.config.SQLParserRuleConfiguration;
+import
org.apache.shardingsphere.parser.distsql.parser.segment.CacheOptionSegment;
+import
org.apache.shardingsphere.parser.distsql.parser.statement.updatable.AlterSQLParserRuleStatement;
+import org.apache.shardingsphere.parser.rule.SQLParserRule;
+import org.apache.shardingsphere.sql.parser.api.CacheOption;
+import org.apache.shardingsphere.sql.parser.sql.common.statement.SQLStatement;
+
+import java.util.Collection;
+
+/**
+ * Alter SQL parser rule statement handler.
+ */
+public final class AlterSQLParserRuleStatementUpdater implements
GlobalRuleRALUpdater {
+
+ @Override
+ public void executeUpdate(final ShardingSphereMetaData metaData, final
SQLStatement sqlStatement) throws DistSQLException {
+ SQLParserRuleConfiguration toBeAlteredRuleConfig =
createToBeAlteredRuleConfiguration(metaData.getGlobalRuleMetaData(),
sqlStatement);
+ Collection<ShardingSphereRule> globalRules =
metaData.getGlobalRuleMetaData().getRules();
+ globalRules.removeIf(each -> each instanceof SQLParserRule);
+ globalRules.add(new SQLParserRule(toBeAlteredRuleConfig));
+ }
+
+ private SQLParserRuleConfiguration
createToBeAlteredRuleConfiguration(final ShardingSphereRuleMetaData
ruleMetaData, final SQLStatement sqlStatement) {
+ AlterSQLParserRuleStatement ruleStatement =
(AlterSQLParserRuleStatement) sqlStatement;
+ SQLParserRuleConfiguration currentConfig =
ruleMetaData.getSingleRule(SQLParserRule.class).getConfiguration();
+ boolean sqlCommentParseEnabled = null ==
ruleStatement.getSqlCommentParseEnable() ?
currentConfig.isSqlCommentParseEnabled() :
ruleStatement.getSqlCommentParseEnable();
+ CacheOption parseTreeCache =
+ null == ruleStatement.getParseTreeCache() ?
currentConfig.getParseTreeCache() :
createCacheOption(currentConfig.getParseTreeCache(),
ruleStatement.getParseTreeCache());
+ CacheOption sqlStatementCache =
+ null == ruleStatement.getSqlStatementCache() ?
currentConfig.getSqlStatementCache() :
createCacheOption(currentConfig.getSqlStatementCache(),
ruleStatement.getSqlStatementCache());
+ return new SQLParserRuleConfiguration(sqlCommentParseEnabled,
parseTreeCache, sqlStatementCache);
+ }
+
+ private CacheOption createCacheOption(final CacheOption cacheOption, final
CacheOptionSegment segment) {
+ int initialCapacity = null == segment.getInitialCapacity() ?
cacheOption.getInitialCapacity() : segment.getInitialCapacity();
+ long maximumSize = null == segment.getMaximumSize() ?
cacheOption.getMaximumSize() : segment.getMaximumSize();
+ return new CacheOption(initialCapacity, maximumSize);
+ }
+
+ @Override
+ public String getType() {
+ return AlterSQLParserRuleStatement.class.getName();
+ }
+}
diff --git
a/shardingsphere-kernel/shardingsphere-parser/shardingsphere-parser-distsql/shardingsphere-parser-distsql-handler/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.distsql.query.DistSQLResultSet
b/shardingsphere-kernel/shardingsphere-parser/shardingsphere-parser-distsql/shardingsphere-parser-distsql-handler/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.distsql.query.DistSQLResultSet
new file mode 100644
index 00000000000..113a3ce4093
--- /dev/null
+++
b/shardingsphere-kernel/shardingsphere-parser/shardingsphere-parser-distsql/shardingsphere-parser-distsql-handler/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.distsql.query.DistSQLResultSet
@@ -0,0 +1,18 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+org.apache.shardingsphere.parser.distsql.handler.query.SQLParserRuleQueryResultSet
diff --git
a/shardingsphere-kernel/shardingsphere-parser/shardingsphere-parser-distsql/shardingsphere-parser-distsql-handler/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.distsql.update.GlobalRuleRALUpdater
b/shardingsphere-kernel/shardingsphere-parser/shardingsphere-parser-distsql/shardingsphere-parser-distsql-handler/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.distsql.update.GlobalRuleRALUpdater
new file mode 100644
index 00000000000..691a753a8ca
--- /dev/null
+++
b/shardingsphere-kernel/shardingsphere-parser/shardingsphere-parser-distsql/shardingsphere-parser-distsql-handler/src/main/resources/META-INF/services/org.apache.shardingsphere.infra.distsql.update.GlobalRuleRALUpdater
@@ -0,0 +1,18 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+org.apache.shardingsphere.parser.distsql.handler.update.AlterSQLParserRuleStatementUpdater
diff --git
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowSQLParserRuleHandlerTest.java
b/shardingsphere-kernel/shardingsphere-parser/shardingsphere-parser-distsql/shardingsphere-parser-distsql-handler/src/test/java/org/apache/shardingsphere/parser/distsql/handler/query/SQLParserRuleQueryResultSetTest.java
similarity index 50%
rename from
shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowSQLParserRuleHandlerTest.java
rename to
shardingsphere-kernel/shardingsphere-parser/shardingsphere-parser-distsql/shardingsphere-parser-distsql-handler/src/test/java/org/apache/shardingsphere/parser/distsql/handler/query/SQLParserRuleQueryResultSetTest.java
index 2d086729bed..303a6d2d9a1 100644
---
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowSQLParserRuleHandlerTest.java
+++
b/shardingsphere-kernel/shardingsphere-parser/shardingsphere-parser-distsql/shardingsphere-parser-distsql-handler/src/test/java/org/apache/shardingsphere/parser/distsql/handler/query/SQLParserRuleQueryResultSetTest.java
@@ -15,49 +15,41 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.proxy.backend.handler.distsql.ral.queryable;
+package org.apache.shardingsphere.parser.distsql.handler.query;
-import
org.apache.shardingsphere.distsql.parser.statement.ral.queryable.ShowSQLParserRuleStatement;
import
org.apache.shardingsphere.infra.metadata.database.rule.ShardingSphereRuleMetaData;
-import org.apache.shardingsphere.mode.manager.ContextManager;
import org.apache.shardingsphere.parser.config.SQLParserRuleConfiguration;
+import
org.apache.shardingsphere.parser.distsql.parser.statement.queryable.ShowSQLParserRuleStatement;
import org.apache.shardingsphere.parser.rule.SQLParserRule;
-import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
-import org.apache.shardingsphere.proxy.backend.util.ProxyContextRestorer;
import org.apache.shardingsphere.sql.parser.api.CacheOption;
import org.junit.Test;
-import java.sql.SQLException;
+import java.util.Collection;
import java.util.Collections;
-import java.util.List;
+import java.util.Iterator;
import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
-import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-public final class ShowSQLParserRuleHandlerTest extends ProxyContextRestorer {
+public final class SQLParserRuleQueryResultSetTest {
@Test
- public void assertSQLParserRule() throws SQLException {
- ContextManager contextManager = mock(ContextManager.class,
RETURNS_DEEP_STUBS);
-
when(contextManager.getMetaDataContexts().getMetaData().getGlobalRuleMetaData()).thenReturn(createGlobalRuleMetaData());
- ProxyContext.init(contextManager);
- ShowSQLParserRuleHandler handler = new ShowSQLParserRuleHandler();
- handler.init(new ShowSQLParserRuleStatement(), null);
- handler.execute();
- handler.next();
- List<Object> data = handler.getRowData().getData();
- assertThat(data.size(), is(3));
- assertThat(data.get(0), is(Boolean.TRUE.toString()));
- String parseTreeCache = String.valueOf(data.get(1));
- assertThat(parseTreeCache, containsString("\"initialCapacity\":128"));
- assertThat(parseTreeCache, containsString("\"maximumSize\":1024"));
- String sqlStatementCache = String.valueOf(data.get(2));
- assertThat(sqlStatementCache,
containsString("\"initialCapacity\":2000"));
- assertThat(sqlStatementCache, containsString("\"maximumSize\":65535"));
+ public void assertSQLParserRule() {
+ ShardingSphereRuleMetaData ruleMetaData = createGlobalRuleMetaData();
+ SQLParserRuleQueryResultSet resultSet = new
SQLParserRuleQueryResultSet();
+ resultSet.init(ruleMetaData, mock(ShowSQLParserRuleStatement.class));
+ Collection<Object> actual = resultSet.getRowData();
+ assertThat(actual.size(), is(3));
+ Iterator<Object> rowData = actual.iterator();
+ assertThat(rowData.next(), is(Boolean.TRUE.toString()));
+ String parseTreeCache = (String) rowData.next();
+ assertThat(parseTreeCache, containsString("initialCapacity: 128"));
+ assertThat(parseTreeCache, containsString("maximumSize: 1024"));
+ String sqlStatementCache = (String) rowData.next();
+ assertThat(sqlStatementCache, containsString("initialCapacity: 2000"));
+ assertThat(sqlStatementCache, containsString("maximumSize: 65535"));
}
private ShardingSphereRuleMetaData createGlobalRuleMetaData() {
diff --git
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/AlterSQLParserRuleHandlerTest.java
b/shardingsphere-kernel/shardingsphere-parser/shardingsphere-parser-distsql/shardingsphere-parser-distsql-handler/src/test/java/org/apache/shardingsphere/parser/distsql/handler/update/AlterSQLParserRuleStatementUpdaterTest.java
similarity index 53%
rename from
shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/AlterSQLParserRuleHandlerTest.java
rename to
shardingsphere-kernel/shardingsphere-parser/shardingsphere-parser-distsql/shardingsphere-parser-distsql-handler/src/test/java/org/apache/shardingsphere/parser/distsql/handler/update/AlterSQLParserRuleStatementUpdaterTest.java
index 92b42f30fd0..f58bddf32f6 100644
---
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/AlterSQLParserRuleHandlerTest.java
+++
b/shardingsphere-kernel/shardingsphere-parser/shardingsphere-parser-distsql/shardingsphere-parser-distsql-handler/src/test/java/org/apache/shardingsphere/parser/distsql/handler/update/AlterSQLParserRuleStatementUpdaterTest.java
@@ -15,57 +15,45 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.proxy.backend.handler.distsql.ral.updatable;
+package org.apache.shardingsphere.parser.distsql.handler.update;
-import org.apache.shardingsphere.distsql.parser.segment.CacheOptionSegment;
-import
org.apache.shardingsphere.distsql.parser.statement.ral.updatable.AlterSQLParserRuleStatement;
+import org.apache.shardingsphere.infra.config.props.ConfigurationProperties;
+import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
import
org.apache.shardingsphere.infra.metadata.database.rule.ShardingSphereRuleMetaData;
-import org.apache.shardingsphere.mode.manager.ContextManager;
+import
org.apache.shardingsphere.parser.distsql.parser.segment.CacheOptionSegment;
+import
org.apache.shardingsphere.parser.distsql.parser.statement.updatable.AlterSQLParserRuleStatement;
import org.apache.shardingsphere.parser.rule.SQLParserRule;
import
org.apache.shardingsphere.parser.rule.builder.DefaultSQLParserRuleConfigurationBuilder;
-import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
-import
org.apache.shardingsphere.proxy.backend.response.header.update.UpdateResponseHeader;
-import org.apache.shardingsphere.proxy.backend.session.ConnectionSession;
-import org.apache.shardingsphere.proxy.backend.util.ProxyContextRestorer;
import org.junit.Test;
import java.sql.SQLException;
import java.util.Collections;
import java.util.LinkedList;
+import java.util.Properties;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
-import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-public final class AlterSQLParserRuleHandlerTest extends ProxyContextRestorer {
+public final class AlterSQLParserRuleStatementUpdaterTest {
@Test
public void assertExecute() throws SQLException {
- ContextManager contextManager = mockContextManager();
- AlterSQLParserRuleHandler handler = new AlterSQLParserRuleHandler();
+ AlterSQLParserRuleStatementUpdater updater = new
AlterSQLParserRuleStatementUpdater();
AlterSQLParserRuleStatement sqlStatement = new
AlterSQLParserRuleStatement(true, new CacheOptionSegment(64, 512L), new
CacheOptionSegment(1000, 1000L));
- handler.init(sqlStatement, mock(ConnectionSession.class));
- UpdateResponseHeader responseHeader = (UpdateResponseHeader)
handler.execute();
- assertThat(responseHeader.getSqlStatement(), is(sqlStatement));
-
assertAlteredRule(contextManager.getMetaDataContexts().getMetaData().getGlobalRuleMetaData().getSingleRule(SQLParserRule.class));
- }
-
- private ContextManager mockContextManager() {
- ContextManager result = mock(ContextManager.class, RETURNS_DEEP_STUBS);
- SQLParserRule rule = new SQLParserRule(new
DefaultSQLParserRuleConfigurationBuilder().build());
-
when(result.getMetaDataContexts().getMetaData().getGlobalRuleMetaData()).thenReturn(new
ShardingSphereRuleMetaData(new LinkedList<>(Collections.singleton(rule))));
- ProxyContext.init(result);
- return result;
- }
-
- private void assertAlteredRule(final SQLParserRule actual) {
+ ShardingSphereMetaData metaData = createMetaData();
+ updater.executeUpdate(metaData, sqlStatement);
+ SQLParserRule actual =
metaData.getGlobalRuleMetaData().getSingleRule(SQLParserRule.class);
assertTrue(actual.isSqlCommentParseEnabled());
assertThat(actual.getSqlStatementCache().getInitialCapacity(),
is(1000));
assertThat(actual.getSqlStatementCache().getMaximumSize(), is(1000L));
assertThat(actual.getParseTreeCache().getInitialCapacity(), is(64));
assertThat(actual.getParseTreeCache().getMaximumSize(), is(512L));
}
+
+ private ShardingSphereMetaData createMetaData() {
+ SQLParserRule rule = new SQLParserRule(new
DefaultSQLParserRuleConfigurationBuilder().build());
+ ShardingSphereRuleMetaData ruleMetaData = new
ShardingSphereRuleMetaData(new LinkedList<>(Collections.singleton(rule)));
+ return new ShardingSphereMetaData(Collections.emptyMap(),
ruleMetaData, new ConfigurationProperties(new Properties()));
+ }
}
diff --git
a/shardingsphere-kernel/shardingsphere-parser/shardingsphere-parser-distsql/shardingsphere-parser-distsql-parser/pom.xml
b/shardingsphere-kernel/shardingsphere-parser/shardingsphere-parser-distsql/shardingsphere-parser-distsql-parser/pom.xml
new file mode 100644
index 00000000000..273f0477a47
--- /dev/null
+++
b/shardingsphere-kernel/shardingsphere-parser/shardingsphere-parser-distsql/shardingsphere-parser-distsql-parser/pom.xml
@@ -0,0 +1,69 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ 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.
+ -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.apache.shardingsphere</groupId>
+ <artifactId>shardingsphere-parser-distsql</artifactId>
+ <version>5.1.3-SNAPSHOT</version>
+ </parent>
+ <artifactId>shardingsphere-parser-distsql-parser</artifactId>
+ <name>${project.artifactId}</name>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.shardingsphere</groupId>
+ <artifactId>shardingsphere-sql-parser-spi</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.shardingsphere</groupId>
+ <artifactId>shardingsphere-distsql-parser</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.shardingsphere</groupId>
+ <artifactId>shardingsphere-parser-distsql-statement</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.antlr</groupId>
+ <artifactId>antlr4-maven-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>antlr</id>
+ <goals>
+ <goal>antlr4</goal>
+ </goals>
+ <configuration>
+
<libDirectory>src/main/antlr4/imports/parser/</libDirectory>
+ <listener>false</listener>
+ <visitor>true</visitor>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+</project>
diff --git
a/shardingsphere-distsql/shardingsphere-distsql-statement/src/main/java/org/apache/shardingsphere/distsql/parser/segment/CacheOptionSegment.java
b/shardingsphere-kernel/shardingsphere-parser/shardingsphere-parser-distsql/shardingsphere-parser-distsql-parser/src/main/antlr4/imports/parser/Alphabet.g4
similarity index 56%
copy from
shardingsphere-distsql/shardingsphere-distsql-statement/src/main/java/org/apache/shardingsphere/distsql/parser/segment/CacheOptionSegment.java
copy to
shardingsphere-kernel/shardingsphere-parser/shardingsphere-parser-distsql/shardingsphere-parser-distsql-parser/src/main/antlr4/imports/parser/Alphabet.g4
index 5b8575f0e8f..f7603cc7e63 100644
---
a/shardingsphere-distsql/shardingsphere-distsql-statement/src/main/java/org/apache/shardingsphere/distsql/parser/segment/CacheOptionSegment.java
+++
b/shardingsphere-kernel/shardingsphere-parser/shardingsphere-parser-distsql/shardingsphere-parser-distsql-parser/src/main/antlr4/imports/parser/Alphabet.g4
@@ -15,20 +15,34 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.distsql.parser.segment;
+lexer grammar Alphabet;
-import lombok.Getter;
-import lombok.RequiredArgsConstructor;
-import org.apache.shardingsphere.sql.parser.api.visitor.ASTNode;
+FOR_GENERATOR: 'DO NOT MATCH ANY THING, JUST FOR GENERATOR';
-/**
- * Cache option segment.
- */
-@RequiredArgsConstructor
-@Getter
-public final class CacheOptionSegment implements ASTNode {
-
- private final Integer initialCapacity;
-
- private final Long maximumSize;
-}
+fragment A: [Aa];
+fragment B: [Bb];
+fragment C: [Cc];
+fragment D: [Dd];
+fragment E: [Ee];
+fragment F: [Ff];
+fragment G: [Gg];
+fragment H: [Hh];
+fragment I: [Ii];
+fragment J: [Jj];
+fragment K: [Kk];
+fragment L: [Ll];
+fragment M: [Mm];
+fragment N: [Nn];
+fragment O: [Oo];
+fragment P: [Pp];
+fragment Q: [Qq];
+fragment R: [Rr];
+fragment S: [Ss];
+fragment T: [Tt];
+fragment U: [Uu];
+fragment V: [Vv];
+fragment W: [Ww];
+fragment X: [Xx];
+fragment Y: [Yy];
+fragment Z: [Zz];
+fragment UL_: '_';
diff --git
a/shardingsphere-distsql/shardingsphere-distsql-statement/src/main/java/org/apache/shardingsphere/distsql/parser/segment/CacheOptionSegment.java
b/shardingsphere-kernel/shardingsphere-parser/shardingsphere-parser-distsql/shardingsphere-parser-distsql-parser/src/main/antlr4/imports/parser/Keyword.g4
similarity index 54%
copy from
shardingsphere-distsql/shardingsphere-distsql-statement/src/main/java/org/apache/shardingsphere/distsql/parser/segment/CacheOptionSegment.java
copy to
shardingsphere-kernel/shardingsphere-parser/shardingsphere-parser-distsql/shardingsphere-parser-distsql-parser/src/main/antlr4/imports/parser/Keyword.g4
index 5b8575f0e8f..82a6935c915 100644
---
a/shardingsphere-distsql/shardingsphere-distsql-statement/src/main/java/org/apache/shardingsphere/distsql/parser/segment/CacheOptionSegment.java
+++
b/shardingsphere-kernel/shardingsphere-parser/shardingsphere-parser-distsql/shardingsphere-parser-distsql-parser/src/main/antlr4/imports/parser/Keyword.g4
@@ -15,20 +15,58 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.distsql.parser.segment;
+lexer grammar Keyword;
-import lombok.Getter;
-import lombok.RequiredArgsConstructor;
-import org.apache.shardingsphere.sql.parser.api.visitor.ASTNode;
+import Alphabet;
-/**
- * Cache option segment.
- */
-@RequiredArgsConstructor
-@Getter
-public final class CacheOptionSegment implements ASTNode {
-
- private final Integer initialCapacity;
-
- private final Long maximumSize;
-}
+WS
+ : [ \t\r\n] + ->skip
+ ;
+
+SHOW
+ : S H O W
+ ;
+
+ALTER
+ : A L T E R
+ ;
+
+RULE
+ : R U L E
+ ;
+
+SQL_PARSER
+ : S Q L UL_ P A R S E R
+ ;
+
+SQL_COMMENT_PARSE_ENABLE
+ : S Q L UL_ C O M M E N T UL_ P A R S E UL_ E N A B L E
+ ;
+
+PARSE_TREE_CACHE
+ : P A R S E UL_ T R E E UL_ C A C H E
+ ;
+
+SQL_STATEMENT_CACHE
+ : S Q L UL_ S T A T E M E N T UL_ C A C H E
+ ;
+
+INITIAL_CAPACITY
+ : I N I T I A L UL_ C A P A C I T Y
+ ;
+
+MAXIMUM_SIZE
+ : M A X I M U M UL_ S I Z E
+ ;
+
+CONCURRENCY_LEVEL
+ : C O N C U R R E N C Y UL_ L E V E L
+ ;
+
+TRUE
+ : T R U E
+ ;
+
+FALSE
+ : F A L S E
+ ;
diff --git
a/shardingsphere-distsql/shardingsphere-distsql-statement/src/main/java/org/apache/shardingsphere/distsql/parser/statement/ral/queryable/ShowSQLParserRuleStatement.java
b/shardingsphere-kernel/shardingsphere-parser/shardingsphere-parser-distsql/shardingsphere-parser-distsql-parser/src/main/antlr4/imports/parser/Literals.g4
similarity index 74%
copy from
shardingsphere-distsql/shardingsphere-distsql-statement/src/main/java/org/apache/shardingsphere/distsql/parser/statement/ral/queryable/ShowSQLParserRuleStatement.java
copy to
shardingsphere-kernel/shardingsphere-parser/shardingsphere-parser-distsql/shardingsphere-parser-distsql-parser/src/main/antlr4/imports/parser/Literals.g4
index 80982c07415..d8f6d07f77c 100644
---
a/shardingsphere-distsql/shardingsphere-distsql-statement/src/main/java/org/apache/shardingsphere/distsql/parser/statement/ral/queryable/ShowSQLParserRuleStatement.java
+++
b/shardingsphere-kernel/shardingsphere-parser/shardingsphere-parser-distsql/shardingsphere-parser-distsql-parser/src/main/antlr4/imports/parser/Literals.g4
@@ -15,12 +15,20 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.distsql.parser.statement.ral.queryable;
+lexer grammar Literals;
-import
org.apache.shardingsphere.distsql.parser.statement.ral.QueryableRALStatement;
+import Alphabet, Symbol;
-/**
- * Show SQL parser rule statement.
- */
-public final class ShowSQLParserRuleStatement extends QueryableRALStatement {
-}
+IDENTIFIER
+ : [A-Za-z_$0-9]*?[A-Za-z_$]+?[A-Za-z_$0-9]*
+ | BQ ~'`'+ BQ
+ ;
+
+STRING
+ : (DQ ('\\'. | '""' | ~('"' | '\\'))* DQ)
+ | (SQ ('\\'. | '\'\'' | ~('\'' | '\\'))* SQ)
+ ;
+
+INT
+ : [0-9]+
+ ;
diff --git
a/shardingsphere-distsql/shardingsphere-distsql-statement/src/main/java/org/apache/shardingsphere/distsql/parser/statement/ral/queryable/ShowSQLParserRuleStatement.java
b/shardingsphere-kernel/shardingsphere-parser/shardingsphere-parser-distsql/shardingsphere-parser-distsql-parser/src/main/antlr4/imports/parser/RALStatement.g4
similarity index 53%
copy from
shardingsphere-distsql/shardingsphere-distsql-statement/src/main/java/org/apache/shardingsphere/distsql/parser/statement/ral/queryable/ShowSQLParserRuleStatement.java
copy to
shardingsphere-kernel/shardingsphere-parser/shardingsphere-parser-distsql/shardingsphere-parser-distsql-parser/src/main/antlr4/imports/parser/RALStatement.g4
index 80982c07415..6fe30f9c662 100644
---
a/shardingsphere-distsql/shardingsphere-distsql-statement/src/main/java/org/apache/shardingsphere/distsql/parser/statement/ral/queryable/ShowSQLParserRuleStatement.java
+++
b/shardingsphere-kernel/shardingsphere-parser/shardingsphere-parser-distsql/shardingsphere-parser-distsql-parser/src/main/antlr4/imports/parser/RALStatement.g4
@@ -15,12 +15,46 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.distsql.parser.statement.ral.queryable;
+grammar RALStatement;
-import
org.apache.shardingsphere.distsql.parser.statement.ral.QueryableRALStatement;
+import Keyword, Literals;
-/**
- * Show SQL parser rule statement.
- */
-public final class ShowSQLParserRuleStatement extends QueryableRALStatement {
-}
+showSQLParserRule
+ : SHOW SQL_PARSER RULE
+ ;
+
+alterSQLParserRule
+ : ALTER SQL_PARSER RULE sqlParserRuleDefinition
+ ;
+
+sqlParserRuleDefinition
+ : SQL_COMMENT_PARSE_ENABLE EQ sqlCommentParseEnable (COMMA
PARSE_TREE_CACHE LP parseTreeCache RP)? (COMMA SQL_STATEMENT_CACHE LP
sqlStatementCache RP)?
+ ;
+
+sqlCommentParseEnable
+ : TRUE | FALSE
+ ;
+
+parseTreeCache
+ : cacheOption
+ ;
+
+sqlStatementCache
+ : cacheOption
+ ;
+
+cacheOption
+ : (INITIAL_CAPACITY EQ initialCapacity)? (COMMA? MAXIMUM_SIZE EQ
maximumSize)? (COMMA? CONCURRENCY_LEVEL EQ concurrencyLevel)?
+ ;
+
+initialCapacity
+ : INT
+ ;
+
+maximumSize
+ : INT
+ ;
+
+concurrencyLevel
+ : INT
+ ;
diff --git
a/shardingsphere-kernel/shardingsphere-parser/shardingsphere-parser-distsql/shardingsphere-parser-distsql-parser/src/main/antlr4/imports/parser/Symbol.g4
b/shardingsphere-kernel/shardingsphere-parser/shardingsphere-parser-distsql/shardingsphere-parser-distsql-parser/src/main/antlr4/imports/parser/Symbol.g4
new file mode 100644
index 00000000000..3322b09bb3a
--- /dev/null
+++
b/shardingsphere-kernel/shardingsphere-parser/shardingsphere-parser-distsql/shardingsphere-parser-distsql-parser/src/main/antlr4/imports/parser/Symbol.g4
@@ -0,0 +1,62 @@
+/*
+ * 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: '_';
+DL: '$';
diff --git
a/shardingsphere-distsql/shardingsphere-distsql-statement/src/main/java/org/apache/shardingsphere/distsql/parser/statement/ral/queryable/ShowSQLParserRuleStatement.java
b/shardingsphere-kernel/shardingsphere-parser/shardingsphere-parser-distsql/shardingsphere-parser-distsql-parser/src/main/antlr4/org/apache/shardingsphere/distsql/parser/autogen/SQLParserDistSQLStatement.g4
similarity index 74%
copy from
shardingsphere-distsql/shardingsphere-distsql-statement/src/main/java/org/apache/shardingsphere/distsql/parser/statement/ral/queryable/ShowSQLParserRuleStatement.java
copy to
shardingsphere-kernel/shardingsphere-parser/shardingsphere-parser-distsql/shardingsphere-parser-distsql-parser/src/main/antlr4/org/apache/shardingsphere/distsql/parser/autogen/SQLParserDistSQLStatement.g4
index 80982c07415..64b97ae6841 100644
---
a/shardingsphere-distsql/shardingsphere-distsql-statement/src/main/java/org/apache/shardingsphere/distsql/parser/statement/ral/queryable/ShowSQLParserRuleStatement.java
+++
b/shardingsphere-kernel/shardingsphere-parser/shardingsphere-parser-distsql/shardingsphere-parser-distsql-parser/src/main/antlr4/org/apache/shardingsphere/distsql/parser/autogen/SQLParserDistSQLStatement.g4
@@ -15,12 +15,12 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.distsql.parser.statement.ral.queryable;
+grammar SQLParserDistSQLStatement;
-import
org.apache.shardingsphere.distsql.parser.statement.ral.QueryableRALStatement;
+import Symbol, RALStatement;
-/**
- * Show SQL parser rule statement.
- */
-public final class ShowSQLParserRuleStatement extends QueryableRALStatement {
-}
+execute
+ : (showSQLParserRule
+ | alterSQLParserRule
+ ) SEMI?
+ ;
diff --git
a/shardingsphere-distsql/shardingsphere-distsql-statement/src/main/java/org/apache/shardingsphere/distsql/parser/segment/CacheOptionSegment.java
b/shardingsphere-kernel/shardingsphere-parser/shardingsphere-parser-distsql/shardingsphere-parser-distsql-parser/src/main/java/org/apache/shardingsphere/parser/distsql/parser/core/SQLParserDistSQLLexer.java
similarity index 63%
copy from
shardingsphere-distsql/shardingsphere-distsql-statement/src/main/java/org/apache/shardingsphere/distsql/parser/segment/CacheOptionSegment.java
copy to
shardingsphere-kernel/shardingsphere-parser/shardingsphere-parser-distsql/shardingsphere-parser-distsql-parser/src/main/java/org/apache/shardingsphere/parser/distsql/parser/core/SQLParserDistSQLLexer.java
index 5b8575f0e8f..dbf389ac3d2 100644
---
a/shardingsphere-distsql/shardingsphere-distsql-statement/src/main/java/org/apache/shardingsphere/distsql/parser/segment/CacheOptionSegment.java
+++
b/shardingsphere-kernel/shardingsphere-parser/shardingsphere-parser-distsql/shardingsphere-parser-distsql-parser/src/main/java/org/apache/shardingsphere/parser/distsql/parser/core/SQLParserDistSQLLexer.java
@@ -15,20 +15,18 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.distsql.parser.segment;
+package org.apache.shardingsphere.parser.distsql.parser.core;
-import lombok.Getter;
-import lombok.RequiredArgsConstructor;
-import org.apache.shardingsphere.sql.parser.api.visitor.ASTNode;
+import org.antlr.v4.runtime.CharStream;
+import
org.apache.shardingsphere.distsql.parser.autogen.SQLParserDistSQLStatementLexer;
+import org.apache.shardingsphere.sql.parser.api.parser.SQLLexer;
/**
- * Cache option segment.
+ * SQL lexer for SQL parser dist SQL.
*/
-@RequiredArgsConstructor
-@Getter
-public final class CacheOptionSegment implements ASTNode {
+public final class SQLParserDistSQLLexer extends
SQLParserDistSQLStatementLexer implements SQLLexer {
- private final Integer initialCapacity;
-
- private final Long maximumSize;
+ public SQLParserDistSQLLexer(final CharStream input) {
+ super(input);
+ }
}
diff --git
a/shardingsphere-distsql/shardingsphere-distsql-statement/src/main/java/org/apache/shardingsphere/distsql/parser/segment/CacheOptionSegment.java
b/shardingsphere-kernel/shardingsphere-parser/shardingsphere-parser-distsql/shardingsphere-parser-distsql-parser/src/main/java/org/apache/shardingsphere/parser/distsql/parser/core/SQLParserDistSQLParser.java
similarity index 54%
copy from
shardingsphere-distsql/shardingsphere-distsql-statement/src/main/java/org/apache/shardingsphere/distsql/parser/segment/CacheOptionSegment.java
copy to
shardingsphere-kernel/shardingsphere-parser/shardingsphere-parser-distsql/shardingsphere-parser-distsql-parser/src/main/java/org/apache/shardingsphere/parser/distsql/parser/core/SQLParserDistSQLParser.java
index 5b8575f0e8f..63cae890c9c 100644
---
a/shardingsphere-distsql/shardingsphere-distsql-statement/src/main/java/org/apache/shardingsphere/distsql/parser/segment/CacheOptionSegment.java
+++
b/shardingsphere-kernel/shardingsphere-parser/shardingsphere-parser-distsql/shardingsphere-parser-distsql-parser/src/main/java/org/apache/shardingsphere/parser/distsql/parser/core/SQLParserDistSQLParser.java
@@ -15,20 +15,26 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.distsql.parser.segment;
+package org.apache.shardingsphere.parser.distsql.parser.core;
-import lombok.Getter;
-import lombok.RequiredArgsConstructor;
+import org.antlr.v4.runtime.CommonTokenStream;
+import org.antlr.v4.runtime.TokenStream;
+import
org.apache.shardingsphere.distsql.parser.autogen.SQLParserDistSQLStatementParser;
+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;
/**
- * Cache option segment.
+ * SQL parser for SQL parser dist SQL.
*/
-@RequiredArgsConstructor
-@Getter
-public final class CacheOptionSegment implements ASTNode {
+public final class SQLParserDistSQLParser extends
SQLParserDistSQLStatementParser implements SQLParser {
- private final Integer initialCapacity;
+ public SQLParserDistSQLParser(final TokenStream input) {
+ super(input);
+ }
- private final Long maximumSize;
+ @Override
+ public ASTNode parse() {
+ return new ParseASTNode(execute(), (CommonTokenStream)
getTokenStream());
+ }
}
diff --git
a/shardingsphere-kernel/shardingsphere-parser/shardingsphere-parser-distsql/shardingsphere-parser-distsql-parser/src/main/java/org/apache/shardingsphere/parser/distsql/parser/core/SQLParserDistSQLStatementVisitor.java
b/shardingsphere-kernel/shardingsphere-parser/shardingsphere-parser-distsql/shardingsphere-parser-distsql-parser/src/main/java/org/apache/shardingsphere/parser/distsql/parser/core/SQLParserDistSQLStatementVisitor.java
new file mode 100644
index 00000000000..d0982e6696d
--- /dev/null
+++
b/shardingsphere-kernel/shardingsphere-parser/shardingsphere-parser-distsql/shardingsphere-parser-distsql-parser/src/main/java/org/apache/shardingsphere/parser/distsql/parser/core/SQLParserDistSQLStatementVisitor.java
@@ -0,0 +1,66 @@
+/*
+ * 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.parser.distsql.parser.core;
+
+import org.antlr.v4.runtime.tree.ParseTree;
+import
org.apache.shardingsphere.distsql.parser.autogen.SQLParserDistSQLStatementBaseVisitor;
+import
org.apache.shardingsphere.distsql.parser.autogen.SQLParserDistSQLStatementParser.AlterSQLParserRuleContext;
+import
org.apache.shardingsphere.distsql.parser.autogen.SQLParserDistSQLStatementParser.CacheOptionContext;
+import
org.apache.shardingsphere.distsql.parser.autogen.SQLParserDistSQLStatementParser.ShowSQLParserRuleContext;
+import
org.apache.shardingsphere.distsql.parser.autogen.SQLParserDistSQLStatementParser.SqlParserRuleDefinitionContext;
+import
org.apache.shardingsphere.parser.distsql.parser.segment.CacheOptionSegment;
+import
org.apache.shardingsphere.parser.distsql.parser.statement.queryable.ShowSQLParserRuleStatement;
+import
org.apache.shardingsphere.parser.distsql.parser.statement.updatable.AlterSQLParserRuleStatement;
+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.value.identifier.IdentifierValue;
+
+/**
+ * SQL statement visitor for SQL parser dist SQL.
+ */
+public final class SQLParserDistSQLStatementVisitor extends
SQLParserDistSQLStatementBaseVisitor<ASTNode> implements SQLVisitor {
+
+ @Override
+ public ASTNode visitShowSQLParserRule(final ShowSQLParserRuleContext ctx) {
+ return new ShowSQLParserRuleStatement();
+ }
+
+ @Override
+ public ASTNode visitAlterSQLParserRule(final AlterSQLParserRuleContext
ctx) {
+ return super.visit(ctx.sqlParserRuleDefinition());
+ }
+
+ @Override
+ public ASTNode visitSqlParserRuleDefinition(final
SqlParserRuleDefinitionContext ctx) {
+ Boolean sqlCommentParseEnable = null == ctx.sqlCommentParseEnable() ?
null : Boolean.parseBoolean(getIdentifierValue(ctx.sqlCommentParseEnable()));
+ CacheOptionSegment parseTreeCache = null == ctx.parseTreeCache() ?
null : visitCacheOption(ctx.parseTreeCache().cacheOption());
+ CacheOptionSegment sqlStatementCache = null == ctx.sqlStatementCache()
? null : visitCacheOption(ctx.sqlStatementCache().cacheOption());
+ return new AlterSQLParserRuleStatement(sqlCommentParseEnable,
parseTreeCache, sqlStatementCache);
+ }
+
+ @Override
+ public CacheOptionSegment visitCacheOption(final CacheOptionContext ctx) {
+ return new CacheOptionSegment(
+ null == ctx.initialCapacity() ? null :
Integer.parseInt(getIdentifierValue(ctx.initialCapacity())),
+ null == ctx.maximumSize() ? null :
Long.parseLong(getIdentifierValue(ctx.maximumSize())));
+ }
+
+ private String getIdentifierValue(final ParseTree context) {
+ return null == context ? null : new
IdentifierValue(context.getText()).getValue();
+ }
+}
diff --git
a/shardingsphere-kernel/shardingsphere-parser/shardingsphere-parser-distsql/shardingsphere-parser-distsql-parser/src/main/java/org/apache/shardingsphere/parser/distsql/parser/facade/SQLParserDistSQLStatementParserFacade.java
b/shardingsphere-kernel/shardingsphere-parser/shardingsphere-parser-distsql/shardingsphere-parser-distsql-parser/src/main/java/org/apache/shardingsphere/parser/distsql/parser/facade/SQLParserDistSQLStatementParserFacade.java
new file mode 100644
index 00000000000..3038028ef13
--- /dev/null
+++
b/shardingsphere-kernel/shardingsphere-parser/shardingsphere-parser-distsql/shardingsphere-parser-distsql-parser/src/main/java/org/apache/shardingsphere/parser/distsql/parser/facade/SQLParserDistSQLStatementParserFacade.java
@@ -0,0 +1,52 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.parser.distsql.parser.facade;
+
+import
org.apache.shardingsphere.distsql.parser.engine.spi.FeaturedDistSQLStatementParserFacade;
+import
org.apache.shardingsphere.parser.distsql.parser.core.SQLParserDistSQLLexer;
+import
org.apache.shardingsphere.parser.distsql.parser.core.SQLParserDistSQLParser;
+import
org.apache.shardingsphere.parser.distsql.parser.core.SQLParserDistSQLStatementVisitor;
+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 SQL parser dist SQL statement.
+ */
+public final class SQLParserDistSQLStatementParserFacade implements
FeaturedDistSQLStatementParserFacade {
+
+ @Override
+ public Class<? extends SQLLexer> getLexerClass() {
+ return SQLParserDistSQLLexer.class;
+ }
+
+ @Override
+ public Class<? extends SQLParser> getParserClass() {
+ return SQLParserDistSQLParser.class;
+ }
+
+ @Override
+ public Class<? extends SQLVisitor> getVisitorClass() {
+ return SQLParserDistSQLStatementVisitor.class;
+ }
+
+ @Override
+ public String getType() {
+ return "sql_parser";
+ }
+}
diff --git
a/shardingsphere-kernel/shardingsphere-parser/shardingsphere-parser-distsql/shardingsphere-parser-distsql-parser/src/main/resources/META-INF/services/org.apache.shardingsphere.distsql.parser.engine.spi.FeaturedDistSQLStatementParserFacade
b/shardingsphere-kernel/shardingsphere-parser/shardingsphere-parser-distsql/shardingsphere-parser-distsql-parser/src/main/resources/META-INF/services/org.apache.shardingsphere.distsql.parser.engine.spi.FeaturedDistSQLStatementParserFacade
new file mode 100644
index 00000000000..31fd97ace59
--- /dev/null
+++
b/shardingsphere-kernel/shardingsphere-parser/shardingsphere-parser-distsql/shardingsphere-parser-distsql-parser/src/main/resources/META-INF/services/org.apache.shardingsphere.distsql.parser.engine.spi.FeaturedDistSQLStatementParserFacade
@@ -0,0 +1,18 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+org.apache.shardingsphere.parser.distsql.parser.facade.SQLParserDistSQLStatementParserFacade
diff --git a/shardingsphere-kernel/shardingsphere-parser/pom.xml
b/shardingsphere-kernel/shardingsphere-parser/shardingsphere-parser-distsql/shardingsphere-parser-distsql-statement/pom.xml
similarity index 76%
copy from shardingsphere-kernel/shardingsphere-parser/pom.xml
copy to
shardingsphere-kernel/shardingsphere-parser/shardingsphere-parser-distsql/shardingsphere-parser-distsql-statement/pom.xml
index f4da24627c9..dcd6a531b8a 100644
--- a/shardingsphere-kernel/shardingsphere-parser/pom.xml
+++
b/shardingsphere-kernel/shardingsphere-parser/shardingsphere-parser-distsql/shardingsphere-parser-distsql-statement/pom.xml
@@ -21,17 +21,17 @@
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache.shardingsphere</groupId>
- <artifactId>shardingsphere-kernel</artifactId>
+ <artifactId>shardingsphere-parser-distsql</artifactId>
<version>5.1.3-SNAPSHOT</version>
</parent>
- <artifactId>shardingsphere-parser</artifactId>
- <packaging>pom</packaging>
+ <artifactId>shardingsphere-parser-distsql-statement</artifactId>
<name>${project.artifactId}</name>
- <modules>
- <module>shardingsphere-parser-api</module>
- <module>shardingsphere-parser-core</module>
- <module>shardingsphere-parser-spring</module>
- </modules>
-
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.shardingsphere</groupId>
+ <artifactId>shardingsphere-distsql-statement</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ </dependencies>
</project>
diff --git
a/shardingsphere-distsql/shardingsphere-distsql-statement/src/main/java/org/apache/shardingsphere/distsql/parser/segment/CacheOptionSegment.java
b/shardingsphere-kernel/shardingsphere-parser/shardingsphere-parser-distsql/shardingsphere-parser-distsql-statement/src/main/java/org/apache/shardingsphere/parser/distsql/parser/segment/CacheOptionSegment.java
similarity index 94%
rename from
shardingsphere-distsql/shardingsphere-distsql-statement/src/main/java/org/apache/shardingsphere/distsql/parser/segment/CacheOptionSegment.java
rename to
shardingsphere-kernel/shardingsphere-parser/shardingsphere-parser-distsql/shardingsphere-parser-distsql-statement/src/main/java/org/apache/shardingsphere/parser/distsql/parser/segment/CacheOptionSegment.java
index 5b8575f0e8f..73a1043a0bc 100644
---
a/shardingsphere-distsql/shardingsphere-distsql-statement/src/main/java/org/apache/shardingsphere/distsql/parser/segment/CacheOptionSegment.java
+++
b/shardingsphere-kernel/shardingsphere-parser/shardingsphere-parser-distsql/shardingsphere-parser-distsql-statement/src/main/java/org/apache/shardingsphere/parser/distsql/parser/segment/CacheOptionSegment.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.distsql.parser.segment;
+package org.apache.shardingsphere.parser.distsql.parser.segment;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
diff --git
a/shardingsphere-distsql/shardingsphere-distsql-statement/src/main/java/org/apache/shardingsphere/distsql/parser/statement/ral/queryable/ShowSQLParserRuleStatement.java
b/shardingsphere-kernel/shardingsphere-parser/shardingsphere-parser-distsql/shardingsphere-parser-distsql-statement/src/main/java/org/apache/shardingsphere/parser/distsql/parser/statement/queryable/ShowSQLParserRuleStatement.java
similarity index 82%
rename from
shardingsphere-distsql/shardingsphere-distsql-statement/src/main/java/org/apache/shardingsphere/distsql/parser/statement/ral/queryable/ShowSQLParserRuleStatement.java
rename to
shardingsphere-kernel/shardingsphere-parser/shardingsphere-parser-distsql/shardingsphere-parser-distsql-statement/src/main/java/org/apache/shardingsphere/parser/distsql/parser/statement/queryable/ShowSQLParserRuleStatement.java
index 80982c07415..2697a33b498 100644
---
a/shardingsphere-distsql/shardingsphere-distsql-statement/src/main/java/org/apache/shardingsphere/distsql/parser/statement/ral/queryable/ShowSQLParserRuleStatement.java
+++
b/shardingsphere-kernel/shardingsphere-parser/shardingsphere-parser-distsql/shardingsphere-parser-distsql-statement/src/main/java/org/apache/shardingsphere/parser/distsql/parser/statement/queryable/ShowSQLParserRuleStatement.java
@@ -15,12 +15,12 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.distsql.parser.statement.ral.queryable;
+package org.apache.shardingsphere.parser.distsql.parser.statement.queryable;
-import
org.apache.shardingsphere.distsql.parser.statement.ral.QueryableRALStatement;
+import
org.apache.shardingsphere.distsql.parser.statement.ral.QueryableGlobalRuleRALStatement;
/**
* Show SQL parser rule statement.
*/
-public final class ShowSQLParserRuleStatement extends QueryableRALStatement {
+public final class ShowSQLParserRuleStatement extends
QueryableGlobalRuleRALStatement {
}
diff --git
a/shardingsphere-distsql/shardingsphere-distsql-statement/src/main/java/org/apache/shardingsphere/distsql/parser/statement/ral/updatable/AlterSQLParserRuleStatement.java
b/shardingsphere-kernel/shardingsphere-parser/shardingsphere-parser-distsql/shardingsphere-parser-distsql-statement/src/main/java/org/apache/shardingsphere/parser/distsql/parser/statement/updatable/AlterSQLParserRuleStatement.java
similarity index 85%
rename from
shardingsphere-distsql/shardingsphere-distsql-statement/src/main/java/org/apache/shardingsphere/distsql/parser/statement/ral/updatable/AlterSQLParserRuleStatement.java
rename to
shardingsphere-kernel/shardingsphere-parser/shardingsphere-parser-distsql/shardingsphere-parser-distsql-statement/src/main/java/org/apache/shardingsphere/parser/distsql/parser/statement/updatable/AlterSQLParserRuleStatement.java
index 6c49990d5db..e38040564a3 100644
---
a/shardingsphere-distsql/shardingsphere-distsql-statement/src/main/java/org/apache/shardingsphere/distsql/parser/statement/ral/updatable/AlterSQLParserRuleStatement.java
+++
b/shardingsphere-kernel/shardingsphere-parser/shardingsphere-parser-distsql/shardingsphere-parser-distsql-statement/src/main/java/org/apache/shardingsphere/parser/distsql/parser/statement/updatable/AlterSQLParserRuleStatement.java
@@ -15,19 +15,19 @@
* limitations under the License.
*/
-package org.apache.shardingsphere.distsql.parser.statement.ral.updatable;
+package org.apache.shardingsphere.parser.distsql.parser.statement.updatable;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
-import org.apache.shardingsphere.distsql.parser.segment.CacheOptionSegment;
-import
org.apache.shardingsphere.distsql.parser.statement.ral.UpdatableRALStatement;
+import
org.apache.shardingsphere.distsql.parser.statement.ral.UpdatableGlobalRuleRALStatement;
+import
org.apache.shardingsphere.parser.distsql.parser.segment.CacheOptionSegment;
/**
* Alter SQL parser rule statement.
*/
@RequiredArgsConstructor
@Getter
-public final class AlterSQLParserRuleStatement extends UpdatableRALStatement {
+public final class AlterSQLParserRuleStatement extends
UpdatableGlobalRuleRALStatement {
private final Boolean sqlCommentParseEnable;
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/pom.xml
b/shardingsphere-proxy/shardingsphere-proxy-backend/pom.xml
index ab4d0762c2f..5b97a3e4e78 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/pom.xml
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/pom.xml
@@ -143,6 +143,11 @@
<artifactId>shardingsphere-transaction-distsql-handler</artifactId>
<version>${project.version}</version>
</dependency>
+ <dependency>
+ <groupId>org.apache.shardingsphere</groupId>
+ <artifactId>shardingsphere-parser-distsql-handler</artifactId>
+ <version>${project.version}</version>
+ </dependency>
<dependency>
<groupId>org.apache.shardingsphere</groupId>
<artifactId>shardingsphere-authority-core</artifactId>
diff --git
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/RALBackendHandlerFactory.java
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/RALBackendHandlerFactory.java
index 21160b25e99..161cacebad7 100644
---
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/RALBackendHandlerFactory.java
+++
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/RALBackendHandlerFactory.java
@@ -29,13 +29,11 @@ import
org.apache.shardingsphere.distsql.parser.statement.ral.queryable.ShowAllV
import
org.apache.shardingsphere.distsql.parser.statement.ral.queryable.ShowInstanceInfoStatement;
import
org.apache.shardingsphere.distsql.parser.statement.ral.queryable.ShowInstanceListStatement;
import
org.apache.shardingsphere.distsql.parser.statement.ral.queryable.ShowModeInfoStatement;
-import
org.apache.shardingsphere.distsql.parser.statement.ral.queryable.ShowSQLParserRuleStatement;
import
org.apache.shardingsphere.distsql.parser.statement.ral.queryable.ShowSQLTranslatorRuleStatement;
import
org.apache.shardingsphere.distsql.parser.statement.ral.queryable.ShowTableMetadataStatement;
import
org.apache.shardingsphere.distsql.parser.statement.ral.queryable.ShowVariableStatement;
import
org.apache.shardingsphere.distsql.parser.statement.ral.scaling.QueryableScalingRALStatement;
import
org.apache.shardingsphere.distsql.parser.statement.ral.scaling.UpdatableScalingRALStatement;
-import
org.apache.shardingsphere.distsql.parser.statement.ral.updatable.AlterSQLParserRuleStatement;
import
org.apache.shardingsphere.distsql.parser.statement.ral.updatable.ApplyDistSQLStatement;
import
org.apache.shardingsphere.distsql.parser.statement.ral.updatable.DiscardDistSQLStatement;
import
org.apache.shardingsphere.distsql.parser.statement.ral.updatable.ImportDatabaseConfigurationStatement;
@@ -59,11 +57,9 @@ import
org.apache.shardingsphere.proxy.backend.handler.distsql.ral.queryable.Sho
import
org.apache.shardingsphere.proxy.backend.handler.distsql.ral.queryable.ShowInstanceListHandler;
import
org.apache.shardingsphere.proxy.backend.handler.distsql.ral.queryable.ShowModeInfoHandler;
import
org.apache.shardingsphere.proxy.backend.handler.distsql.ral.queryable.ShowReadwriteSplittingReadResourcesHandler;
-import
org.apache.shardingsphere.proxy.backend.handler.distsql.ral.queryable.ShowSQLParserRuleHandler;
import
org.apache.shardingsphere.proxy.backend.handler.distsql.ral.queryable.ShowSQLTranslatorRuleHandler;
import
org.apache.shardingsphere.proxy.backend.handler.distsql.ral.queryable.ShowTableMetadataHandler;
import
org.apache.shardingsphere.proxy.backend.handler.distsql.ral.queryable.ShowVariableHandler;
-import
org.apache.shardingsphere.proxy.backend.handler.distsql.ral.updatable.AlterSQLParserRuleHandler;
import
org.apache.shardingsphere.proxy.backend.handler.distsql.ral.updatable.ApplyDistSQLHandler;
import
org.apache.shardingsphere.proxy.backend.handler.distsql.ral.updatable.DiscardDistSQLHandler;
import
org.apache.shardingsphere.proxy.backend.handler.distsql.ral.updatable.ImportDatabaseConfigurationHandler;
@@ -97,7 +93,6 @@ public final class RALBackendHandlerFactory {
HANDLERS.put(SetVariableStatement.class, SetVariableHandler.class);
HANDLERS.put(SetReadwriteSplittingStatusStatement.class,
SetReadwriteSplittingStatusHandler.class);
HANDLERS.put(RefreshTableMetadataStatement.class,
RefreshTableMetadataHandler.class);
- HANDLERS.put(AlterSQLParserRuleStatement.class,
AlterSQLParserRuleHandler.class);
HANDLERS.put(PrepareDistSQLStatement.class,
PrepareDistSQLHandler.class);
HANDLERS.put(ApplyDistSQLStatement.class, ApplyDistSQLHandler.class);
HANDLERS.put(DiscardDistSQLStatement.class,
DiscardDistSQLHandler.class);
@@ -106,7 +101,6 @@ public final class RALBackendHandlerFactory {
HANDLERS.put(ShowVariableStatement.class, ShowVariableHandler.class);
HANDLERS.put(ShowAllVariablesStatement.class,
ShowAllVariablesHandler.class);
HANDLERS.put(ShowReadwriteSplittingReadResourcesStatement.class,
ShowReadwriteSplittingReadResourcesHandler.class);
- HANDLERS.put(ShowSQLParserRuleStatement.class,
ShowSQLParserRuleHandler.class);
HANDLERS.put(ShowTableMetadataStatement.class,
ShowTableMetadataHandler.class);
HANDLERS.put(ExportDatabaseConfigurationStatement.class,
ExportDatabaseConfigurationHandler.class);
HANDLERS.put(ConvertYamlConfigurationStatement.class,
ConvertYamlConfigurationHandler.class);
diff --git
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowSQLParserRuleHandler.java
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowSQLParserRuleHandler.java
deleted file mode 100644
index e2c2b4706ae..00000000000
---
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/queryable/ShowSQLParserRuleHandler.java
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * 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.proxy.backend.handler.distsql.ral.queryable;
-
-import com.google.gson.Gson;
-import
org.apache.shardingsphere.distsql.parser.statement.ral.queryable.ShowSQLParserRuleStatement;
-import
org.apache.shardingsphere.infra.merge.result.impl.local.LocalDataQueryResultRow;
-import org.apache.shardingsphere.mode.manager.ContextManager;
-import org.apache.shardingsphere.parser.rule.SQLParserRule;
-import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
-import
org.apache.shardingsphere.proxy.backend.handler.distsql.ral.QueryableRALBackendHandler;
-
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-
-/**
- * Show SQL parser rule handler.
- */
-public final class ShowSQLParserRuleHandler extends
QueryableRALBackendHandler<ShowSQLParserRuleStatement> {
-
- private static final Gson GSON = new Gson();
-
- private static final String SQL_COMMENT_PARSE_ENABLE =
"sql_comment_parse_enable";
-
- private static final String PARSE_TREE_CACHE = "parse_tree_cache";
-
- private static final String SQL_STATEMENT_CACHE = "sql_statement_cache";
-
- @Override
- protected Collection<String> getColumnNames() {
- return Arrays.asList(SQL_COMMENT_PARSE_ENABLE, PARSE_TREE_CACHE,
SQL_STATEMENT_CACHE);
- }
-
- @Override
- protected Collection<LocalDataQueryResultRow> getRows(final ContextManager
contextManager) {
- SQLParserRule sqlParserRule =
ProxyContext.getInstance().getContextManager().getMetaDataContexts().getMetaData().getGlobalRuleMetaData().getSingleRule(SQLParserRule.class);
- return Collections.singleton(getRow(sqlParserRule));
- }
-
- private LocalDataQueryResultRow getRow(final SQLParserRule sqlParserRule) {
- return new LocalDataQueryResultRow(
- String.valueOf(sqlParserRule.isSqlCommentParseEnabled()),
GSON.toJson(sqlParserRule.getParseTreeCache()),
GSON.toJson(sqlParserRule.getSqlStatementCache()));
- }
-}
diff --git
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/AlterSQLParserRuleHandler.java
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/AlterSQLParserRuleHandler.java
deleted file mode 100644
index 308dd52da4d..00000000000
---
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/handler/distsql/ral/updatable/AlterSQLParserRuleHandler.java
+++ /dev/null
@@ -1,73 +0,0 @@
-/*
- * 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.proxy.backend.handler.distsql.ral.updatable;
-
-import org.apache.shardingsphere.distsql.parser.segment.CacheOptionSegment;
-import
org.apache.shardingsphere.distsql.parser.statement.ral.updatable.AlterSQLParserRuleStatement;
-import org.apache.shardingsphere.infra.rule.ShardingSphereRule;
-import org.apache.shardingsphere.mode.manager.ContextManager;
-import org.apache.shardingsphere.mode.metadata.MetaDataContexts;
-import org.apache.shardingsphere.parser.config.SQLParserRuleConfiguration;
-import org.apache.shardingsphere.parser.rule.SQLParserRule;
-import org.apache.shardingsphere.proxy.backend.context.ProxyContext;
-import
org.apache.shardingsphere.proxy.backend.handler.distsql.ral.UpdatableRALBackendHandler;
-import org.apache.shardingsphere.sql.parser.api.CacheOption;
-
-import java.util.Collection;
-
-/**
- * Alter SQL parser rule statement handler.
- */
-public final class AlterSQLParserRuleHandler extends
UpdatableRALBackendHandler<AlterSQLParserRuleStatement> {
-
- @Override
- protected void update(final ContextManager contextManager) {
- replaceNewRule();
- persistNewRuleConfigurations();
- }
-
- private void replaceNewRule() {
- SQLParserRuleConfiguration toBeAlteredRuleConfig =
createToBeAlteredRuleConfiguration();
- Collection<ShardingSphereRule> globalRules =
ProxyContext.getInstance().getContextManager().getMetaDataContexts().getMetaData().getGlobalRuleMetaData().getRules();
- globalRules.removeIf(each -> each instanceof SQLParserRule);
- globalRules.add(new SQLParserRule(toBeAlteredRuleConfig));
- }
-
- private SQLParserRuleConfiguration createToBeAlteredRuleConfiguration() {
- AlterSQLParserRuleStatement sqlStatement = getSqlStatement();
- SQLParserRuleConfiguration currentConfig = ProxyContext
-
.getInstance().getContextManager().getMetaDataContexts().getMetaData().getGlobalRuleMetaData().getSingleRule(SQLParserRule.class).getConfiguration();
- boolean sqlCommentParseEnabled = null ==
sqlStatement.getSqlCommentParseEnable() ?
currentConfig.isSqlCommentParseEnabled() :
sqlStatement.getSqlCommentParseEnable();
- CacheOption parseTreeCache =
- null == sqlStatement.getParseTreeCache() ?
currentConfig.getParseTreeCache() :
createCacheOption(currentConfig.getParseTreeCache(),
sqlStatement.getParseTreeCache());
- CacheOption sqlStatementCache =
- null == sqlStatement.getSqlStatementCache() ?
currentConfig.getSqlStatementCache() :
createCacheOption(currentConfig.getSqlStatementCache(),
sqlStatement.getSqlStatementCache());
- return new SQLParserRuleConfiguration(sqlCommentParseEnabled,
parseTreeCache, sqlStatementCache);
- }
-
- private CacheOption createCacheOption(final CacheOption cacheOption, final
CacheOptionSegment segment) {
- int initialCapacity = null == segment.getInitialCapacity() ?
cacheOption.getInitialCapacity() : segment.getInitialCapacity();
- long maximumSize = null == segment.getMaximumSize() ?
cacheOption.getMaximumSize() : segment.getMaximumSize();
- return new CacheOption(initialCapacity, maximumSize);
- }
-
- private void persistNewRuleConfigurations() {
- MetaDataContexts metaDataContexts =
ProxyContext.getInstance().getContextManager().getMetaDataContexts();
-
metaDataContexts.getPersistService().getGlobalRuleService().persist(metaDataContexts.getMetaData().getGlobalRuleMetaData().getConfigurations(),
true);
- }
-}
diff --git
a/shardingsphere-sql-parser/shardingsphere-sql-parser-engine/src/main/java/org/apache/shardingsphere/sql/parser/api/CacheOption.java
b/shardingsphere-sql-parser/shardingsphere-sql-parser-engine/src/main/java/org/apache/shardingsphere/sql/parser/api/CacheOption.java
index a52fada4ae6..07038235229 100644
---
a/shardingsphere-sql-parser/shardingsphere-sql-parser-engine/src/main/java/org/apache/shardingsphere/sql/parser/api/CacheOption.java
+++
b/shardingsphere-sql-parser/shardingsphere-sql-parser-engine/src/main/java/org/apache/shardingsphere/sql/parser/api/CacheOption.java
@@ -30,4 +30,9 @@ public final class CacheOption {
private final int initialCapacity;
private final long maximumSize;
+
+ @Override
+ public String toString() {
+ return String.format("initialCapacity: %d, maximumSize: %d",
initialCapacity, maximumSize);
+ }
}
diff --git a/shardingsphere-test/shardingsphere-parser-test/pom.xml
b/shardingsphere-test/shardingsphere-parser-test/pom.xml
index acde39f165c..f5b7c760f88 100644
--- a/shardingsphere-test/shardingsphere-parser-test/pom.xml
+++ b/shardingsphere-test/shardingsphere-parser-test/pom.xml
@@ -87,6 +87,11 @@
<artifactId>shardingsphere-transaction-distsql-parser</artifactId>
<version>${project.version}</version>
</dependency>
+ <dependency>
+ <groupId>org.apache.shardingsphere</groupId>
+ <artifactId>shardingsphere-parser-distsql-parser</artifactId>
+ <version>${project.version}</version>
+ </dependency>
<dependency>
<groupId>org.apache.shardingsphere</groupId>
<artifactId>shardingsphere-shadow-distsql-parser</artifactId>
diff --git
a/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/statement/distsql/ral/impl/QueryableRALStatementAssert.java
b/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/statement/distsql/ral/impl/QueryableRALStatementAssert.java
index 5c94ae24567..978f584d5eb 100644
---
a/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/statement/distsql/ral/impl/QueryableRALStatementAssert.java
+++
b/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/statement/distsql/ral/impl/QueryableRALStatementAssert.java
@@ -27,10 +27,10 @@ import
org.apache.shardingsphere.distsql.parser.statement.ral.queryable.ShowAllV
import
org.apache.shardingsphere.distsql.parser.statement.ral.queryable.ShowInstanceInfoStatement;
import
org.apache.shardingsphere.distsql.parser.statement.ral.queryable.ShowInstanceListStatement;
import
org.apache.shardingsphere.distsql.parser.statement.ral.queryable.ShowModeInfoStatement;
-import
org.apache.shardingsphere.distsql.parser.statement.ral.queryable.ShowSQLParserRuleStatement;
import
org.apache.shardingsphere.distsql.parser.statement.ral.queryable.ShowSQLTranslatorRuleStatement;
import
org.apache.shardingsphere.distsql.parser.statement.ral.queryable.ShowTableMetadataStatement;
import
org.apache.shardingsphere.distsql.parser.statement.ral.queryable.ShowVariableStatement;
+import
org.apache.shardingsphere.parser.distsql.parser.statement.queryable.ShowSQLParserRuleStatement;
import
org.apache.shardingsphere.readwritesplitting.distsql.parser.statement.ShowReadwriteSplittingReadResourcesStatement;
import
org.apache.shardingsphere.test.sql.parser.parameterized.asserts.SQLCaseAssertContext;
import
org.apache.shardingsphere.test.sql.parser.parameterized.asserts.statement.distsql.ral.impl.queryable.ConvertYamlConfigurationStatementAssert;
diff --git
a/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/statement/distsql/ral/impl/UpdatableRALStatementAssert.java
b/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/statement/distsql/ral/impl/UpdatableRALStatementAssert.java
index 344c8fd4ef0..8605b009702 100644
---
a/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/statement/distsql/ral/impl/UpdatableRALStatementAssert.java
+++
b/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/statement/distsql/ral/impl/UpdatableRALStatementAssert.java
@@ -21,12 +21,12 @@ import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import
org.apache.shardingsphere.distsql.parser.statement.ral.UpdatableRALStatement;
import
org.apache.shardingsphere.distsql.parser.statement.ral.updatable.AlterInstanceStatement;
-import
org.apache.shardingsphere.distsql.parser.statement.ral.updatable.AlterSQLParserRuleStatement;
import
org.apache.shardingsphere.distsql.parser.statement.ral.updatable.ImportDatabaseConfigurationStatement;
import
org.apache.shardingsphere.distsql.parser.statement.ral.updatable.LabelInstanceStatement;
import
org.apache.shardingsphere.distsql.parser.statement.ral.updatable.RefreshTableMetadataStatement;
import
org.apache.shardingsphere.distsql.parser.statement.ral.updatable.SetVariableStatement;
import
org.apache.shardingsphere.distsql.parser.statement.ral.updatable.UnlabelInstanceStatement;
+import
org.apache.shardingsphere.parser.distsql.parser.statement.updatable.AlterSQLParserRuleStatement;
import
org.apache.shardingsphere.test.sql.parser.parameterized.asserts.SQLCaseAssertContext;
import
org.apache.shardingsphere.test.sql.parser.parameterized.asserts.statement.distsql.ral.impl.updatable.AlterInstanceStatementAssert;
import
org.apache.shardingsphere.test.sql.parser.parameterized.asserts.statement.distsql.ral.impl.updatable.AlterSQLParserRuleStatementAssert;
diff --git
a/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/statement/distsql/ral/impl/queryable/ShowSQLParserRuleStatementAssert.java
b/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/statement/distsql/ral/impl/queryable/ShowSQLParserRuleStatementAssert.java
index 1c1e4da5677..23701739b34 100644
---
a/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/statement/distsql/ral/impl/queryable/ShowSQLParserRuleStatementAssert.java
+++
b/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/statement/distsql/ral/impl/queryable/ShowSQLParserRuleStatementAssert.java
@@ -17,10 +17,13 @@
package
org.apache.shardingsphere.test.sql.parser.parameterized.asserts.statement.distsql.ral.impl.queryable;
-import
org.apache.shardingsphere.distsql.parser.statement.ral.queryable.ShowSQLParserRuleStatement;
+import
org.apache.shardingsphere.parser.distsql.parser.statement.queryable.ShowSQLParserRuleStatement;
import
org.apache.shardingsphere.test.sql.parser.parameterized.asserts.SQLCaseAssertContext;
import
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.distsql.ral.ShowSQLParserRuleStatementTestCase;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+
/**
* Show SQL parser rule statement assert.
*/
@@ -34,5 +37,10 @@ public final class ShowSQLParserRuleStatementAssert {
* @param expected expected show SQL parser rule statement test case
*/
public static void assertIs(final SQLCaseAssertContext assertContext,
final ShowSQLParserRuleStatement actual, final
ShowSQLParserRuleStatementTestCase expected) {
+ if (null == expected) {
+ assertNull(assertContext.getText("Actual statement should not
exist."), actual);
+ } else {
+ assertNotNull(assertContext.getText("Actual statement should
exist."), actual);
+ }
}
}
diff --git
a/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/statement/distsql/ral/impl/updatable/AlterSQLParserRuleStatementAssert.java
b/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/statement/distsql/ral/impl/updatable/AlterSQLParserRuleStatementAssert.java
index bba6b84820c..4c10b21618b 100644
---
a/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/statement/distsql/ral/impl/updatable/AlterSQLParserRuleStatementAssert.java
+++
b/shardingsphere-test/shardingsphere-parser-test/src/main/java/org/apache/shardingsphere/test/sql/parser/parameterized/asserts/statement/distsql/ral/impl/updatable/AlterSQLParserRuleStatementAssert.java
@@ -17,8 +17,8 @@
package
org.apache.shardingsphere.test.sql.parser.parameterized.asserts.statement.distsql.ral.impl.updatable;
-import org.apache.shardingsphere.distsql.parser.segment.CacheOptionSegment;
-import
org.apache.shardingsphere.distsql.parser.statement.ral.updatable.AlterSQLParserRuleStatement;
+import
org.apache.shardingsphere.parser.distsql.parser.segment.CacheOptionSegment;
+import
org.apache.shardingsphere.parser.distsql.parser.statement.updatable.AlterSQLParserRuleStatement;
import
org.apache.shardingsphere.test.sql.parser.parameterized.asserts.SQLCaseAssertContext;
import
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.segment.impl.distsql.ExpectedCacheOption;
import
org.apache.shardingsphere.test.sql.parser.parameterized.jaxb.cases.domain.statement.distsql.ral.AlterSQLParserRuleStatementTestCase;