You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by du...@apache.org on 2022/10/31 00:35:14 UTC
[shardingsphere] branch master updated: For #21543, improve properties definition in DistSQL. (#21855)
This is an automated email from the ASF dual-hosted git repository.
duanzhengqiang 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 2670362fa06 For #21543, improve properties definition in DistSQL. (#21855)
2670362fa06 is described below
commit 2670362fa061a43d963fe0ac716927db9553c63f
Author: Raigor <ra...@gmail.com>
AuthorDate: Mon Oct 31 08:35:04 2022 +0800
For #21543, improve properties definition in DistSQL. (#21855)
---
distsql/parser/src/main/antlr4/imports/BaseRule.g4 | 6 ++++-
.../parser/src/main/antlr4/imports/RALStatement.g4 | 2 +-
.../main/antlr4/imports/db-discovery/BaseRule.g4 | 24 +++++++++++++++++++
.../main/antlr4/imports/db-discovery/Keyword.g4 | 8 +++++++
.../antlr4/imports/db-discovery/RDLStatement.g4 | 28 ++--------------------
.../DatabaseDiscoveryDistSQLStatementVisitor.java | 26 +++++++++-----------
.../src/main/antlr4/imports/encrypt/BaseRule.g4 | 24 +++++++++++++++++++
.../main/antlr4/imports/encrypt/RDLStatement.g4 | 16 -------------
.../core/EncryptDistSQLStatementVisitor.java | 11 +++++----
.../antlr4/imports/readwrite-splitting/BaseRule.g4 | 24 +++++++++++++++++++
.../imports/readwrite-splitting/RDLStatement.g4 | 16 -------------
.../ReadwriteSplittingDistSQLStatementVisitor.java | 21 ++++++++--------
.../src/main/antlr4/imports/shadow/BaseRule.g4 | 24 +++++++++++++++++++
.../src/main/antlr4/imports/shadow/Keyword.g4 | 8 +++++++
.../src/main/antlr4/imports/shadow/RDLStatement.g4 | 26 ++++----------------
.../parser/core/ShadowDistSQLStatementVisitor.java | 26 ++++++++++++--------
.../src/main/antlr4/imports/migration/BaseRule.g4 | 16 +++++--------
.../src/main/antlr4/imports/migration/Keyword.g4 | 8 +++++++
.../src/main/antlr4/imports/sharding/BaseRule.g4 | 26 +++++++++++++++++++-
.../main/antlr4/imports/sharding/RDLStatement.g4 | 18 +-------------
.../core/MigrationDistSQLStatementVisitor.java | 13 +---------
.../core/ShardingDistSQLStatementVisitor.java | 12 ++++++----
test/parser/src/main/resources/case/rdl/create.xml | 1 +
.../main/resources/sql/supported/rdl/create.xml | 4 ++--
24 files changed, 220 insertions(+), 168 deletions(-)
diff --git a/distsql/parser/src/main/antlr4/imports/BaseRule.g4 b/distsql/parser/src/main/antlr4/imports/BaseRule.g4
index 9f4e84f9bbc..21c65abbf09 100644
--- a/distsql/parser/src/main/antlr4/imports/BaseRule.g4
+++ b/distsql/parser/src/main/antlr4/imports/BaseRule.g4
@@ -19,6 +19,10 @@ grammar BaseRule;
import Symbol, Keyword, Literals;
+literal
+ : STRING | (MINUS)? INT | TRUE | FALSE
+ ;
+
algorithmDefinition
: TYPE LP NAME EQ algorithmTypeName (COMMA propertiesDefinition)? RP
;
@@ -36,7 +40,7 @@ properties
;
property
- : key=STRING EQ value=STRING
+ : key=STRING EQ value=literal
;
databaseName
diff --git a/distsql/parser/src/main/antlr4/imports/RALStatement.g4 b/distsql/parser/src/main/antlr4/imports/RALStatement.g4
index cbd27d20b10..6f203eb1e92 100644
--- a/distsql/parser/src/main/antlr4/imports/RALStatement.g4
+++ b/distsql/parser/src/main/antlr4/imports/RALStatement.g4
@@ -144,7 +144,7 @@ variableValues
;
variableValue
- : STRING | (MINUS)? INT | TRUE | FALSE
+ : literal
;
instanceId
diff --git a/features/db-discovery/distsql/parser/src/main/antlr4/imports/db-discovery/BaseRule.g4 b/features/db-discovery/distsql/parser/src/main/antlr4/imports/db-discovery/BaseRule.g4
index 1b9abbea6f5..086ee332f93 100644
--- a/features/db-discovery/distsql/parser/src/main/antlr4/imports/db-discovery/BaseRule.g4
+++ b/features/db-discovery/distsql/parser/src/main/antlr4/imports/db-discovery/BaseRule.g4
@@ -18,3 +18,27 @@
grammar BaseRule;
import Symbol, Keyword, Literals;
+
+literal
+ : STRING | (MINUS)? INT | TRUE | FALSE
+ ;
+
+algorithmDefinition
+ : TYPE LP NAME EQ algorithmTypeName (COMMA propertiesDefinition)? RP
+ ;
+
+algorithmTypeName
+ : STRING
+ ;
+
+propertiesDefinition
+ : PROPERTIES LP properties? RP
+ ;
+
+properties
+ : property (COMMA property)*
+ ;
+
+property
+ : key=STRING EQ value=literal
+ ;
diff --git a/features/db-discovery/distsql/parser/src/main/antlr4/imports/db-discovery/Keyword.g4 b/features/db-discovery/distsql/parser/src/main/antlr4/imports/db-discovery/Keyword.g4
index 0d2279ee477..1fbaa303620 100644
--- a/features/db-discovery/distsql/parser/src/main/antlr4/imports/db-discovery/Keyword.g4
+++ b/features/db-discovery/distsql/parser/src/main/antlr4/imports/db-discovery/Keyword.g4
@@ -23,6 +23,14 @@ WS
: [ \t\r\n] + ->skip
;
+TRUE
+ : T R U E
+ ;
+
+FALSE
+ : F A L S E
+ ;
+
CREATE
: C R E A T E
;
diff --git a/features/db-discovery/distsql/parser/src/main/antlr4/imports/db-discovery/RDLStatement.g4 b/features/db-discovery/distsql/parser/src/main/antlr4/imports/db-discovery/RDLStatement.g4
index 9228a8e186c..2df43a1eb04 100644
--- a/features/db-discovery/distsql/parser/src/main/antlr4/imports/db-discovery/RDLStatement.g4
+++ b/features/db-discovery/distsql/parser/src/main/antlr4/imports/db-discovery/RDLStatement.g4
@@ -40,15 +40,7 @@ dropDatabaseDiscoveryHeartbeat
;
databaseDiscoveryRule
- : ruleName LP storageUnits COMMA typeDefinition COMMA discoveryHeartbeat RP
- ;
-
-databaseDiscoveryTypeDefinition
- : discoveryTypeName LP typeDefinition RP
- ;
-
-heartbeatDefinition
- : discoveryHeartbeatName LP PROPERTIES LP properties RP RP
+ : ruleName LP storageUnits COMMA algorithmDefinition COMMA discoveryHeartbeat RP
;
ruleName
@@ -63,24 +55,8 @@ storageUnitName
: IDENTIFIER
;
-typeDefinition
- : TYPE LP NAME EQ discoveryType (COMMA PROPERTIES LP properties RP)? RP
- ;
-
discoveryHeartbeat
- : HEARTBEAT LP PROPERTIES LP properties RP RP
- ;
-
-properties
- : property (COMMA property)*
- ;
-
-property
- : key=STRING EQ value=(NUMBER | INT | STRING)
- ;
-
-discoveryType
- : STRING
+ : HEARTBEAT LP propertiesDefinition RP
;
discoveryTypeName
diff --git a/features/db-discovery/distsql/parser/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/parser/core/DatabaseDiscoveryDistSQLStatementVisitor.java b/features/db-discovery/distsql/parser/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/parser/core/DatabaseDiscoveryDistSQLStatementVisitor.java
index 791680d3978..64445fc161c 100644
--- a/features/db-discovery/distsql/parser/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/parser/core/DatabaseDiscoveryDistSQLStatementVisitor.java
+++ b/features/db-discovery/distsql/parser/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/parser/core/DatabaseDiscoveryDistSQLStatementVisitor.java
@@ -20,7 +20,6 @@ package org.apache.shardingsphere.dbdiscovery.distsql.parser.core;
import org.antlr.v4.runtime.tree.ParseTree;
import org.apache.shardingsphere.dbdiscovery.distsql.parser.segment.AbstractDatabaseDiscoverySegment;
import org.apache.shardingsphere.dbdiscovery.distsql.parser.segment.DatabaseDiscoveryDefinitionSegment;
-import org.apache.shardingsphere.dbdiscovery.distsql.parser.segment.DatabaseDiscoveryProviderAlgorithmSegment;
import org.apache.shardingsphere.dbdiscovery.distsql.parser.statement.AlterDatabaseDiscoveryRuleStatement;
import org.apache.shardingsphere.dbdiscovery.distsql.parser.statement.CountDatabaseDiscoveryRuleStatement;
import org.apache.shardingsphere.dbdiscovery.distsql.parser.statement.CreateDatabaseDiscoveryRuleStatement;
@@ -32,21 +31,20 @@ import org.apache.shardingsphere.dbdiscovery.distsql.parser.statement.ShowDataba
import org.apache.shardingsphere.dbdiscovery.distsql.parser.statement.ShowDatabaseDiscoveryTypesStatement;
import org.apache.shardingsphere.distsql.parser.autogen.DatabaseDiscoveryDistSQLStatementBaseVisitor;
import org.apache.shardingsphere.distsql.parser.autogen.DatabaseDiscoveryDistSQLStatementParser;
+import org.apache.shardingsphere.distsql.parser.autogen.DatabaseDiscoveryDistSQLStatementParser.AlgorithmDefinitionContext;
import org.apache.shardingsphere.distsql.parser.autogen.DatabaseDiscoveryDistSQLStatementParser.AlterDatabaseDiscoveryRuleContext;
import org.apache.shardingsphere.distsql.parser.autogen.DatabaseDiscoveryDistSQLStatementParser.CreateDatabaseDiscoveryRuleContext;
import org.apache.shardingsphere.distsql.parser.autogen.DatabaseDiscoveryDistSQLStatementParser.DatabaseDiscoveryRuleContext;
-import org.apache.shardingsphere.distsql.parser.autogen.DatabaseDiscoveryDistSQLStatementParser.DatabaseDiscoveryTypeDefinitionContext;
import org.apache.shardingsphere.distsql.parser.autogen.DatabaseDiscoveryDistSQLStatementParser.DatabaseNameContext;
import org.apache.shardingsphere.distsql.parser.autogen.DatabaseDiscoveryDistSQLStatementParser.DropDatabaseDiscoveryHeartbeatContext;
import org.apache.shardingsphere.distsql.parser.autogen.DatabaseDiscoveryDistSQLStatementParser.DropDatabaseDiscoveryRuleContext;
import org.apache.shardingsphere.distsql.parser.autogen.DatabaseDiscoveryDistSQLStatementParser.DropDatabaseDiscoveryTypeContext;
-import org.apache.shardingsphere.distsql.parser.autogen.DatabaseDiscoveryDistSQLStatementParser.PropertiesContext;
+import org.apache.shardingsphere.distsql.parser.autogen.DatabaseDiscoveryDistSQLStatementParser.PropertiesDefinitionContext;
import org.apache.shardingsphere.distsql.parser.autogen.DatabaseDiscoveryDistSQLStatementParser.PropertyContext;
import org.apache.shardingsphere.distsql.parser.autogen.DatabaseDiscoveryDistSQLStatementParser.ShowDatabaseDiscoveryHeartbeatsContext;
import org.apache.shardingsphere.distsql.parser.autogen.DatabaseDiscoveryDistSQLStatementParser.ShowDatabaseDiscoveryRulesContext;
import org.apache.shardingsphere.distsql.parser.autogen.DatabaseDiscoveryDistSQLStatementParser.ShowDatabaseDiscoveryTypesContext;
import org.apache.shardingsphere.distsql.parser.autogen.DatabaseDiscoveryDistSQLStatementParser.StorageUnitsContext;
-import org.apache.shardingsphere.distsql.parser.autogen.DatabaseDiscoveryDistSQLStatementParser.TypeDefinitionContext;
import org.apache.shardingsphere.distsql.parser.segment.AlgorithmSegment;
import org.apache.shardingsphere.sql.parser.api.visitor.ASTNode;
import org.apache.shardingsphere.sql.parser.api.visitor.SQLVisitor;
@@ -75,8 +73,8 @@ public final class DatabaseDiscoveryDistSQLStatementVisitor extends DatabaseDisc
@Override
public ASTNode visitDatabaseDiscoveryRule(final DatabaseDiscoveryRuleContext ctx) {
- return new DatabaseDiscoveryDefinitionSegment(
- getIdentifierValue(ctx.ruleName()), buildResources(ctx.storageUnits()), (AlgorithmSegment) visit(ctx.typeDefinition()), getProperties(ctx.discoveryHeartbeat().properties()));
+ return new DatabaseDiscoveryDefinitionSegment(getIdentifierValue(ctx.ruleName()), buildResources(ctx.storageUnits()), (AlgorithmSegment) visit(ctx.algorithmDefinition()),
+ getProperties(ctx.discoveryHeartbeat().propertiesDefinition()));
}
private List<String> buildResources(final StorageUnitsContext ctx) {
@@ -94,8 +92,8 @@ public final class DatabaseDiscoveryDistSQLStatementVisitor extends DatabaseDisc
}
@Override
- public ASTNode visitDatabaseDiscoveryTypeDefinition(final DatabaseDiscoveryTypeDefinitionContext ctx) {
- return new DatabaseDiscoveryProviderAlgorithmSegment(getIdentifierValue(ctx.discoveryTypeName()), (AlgorithmSegment) visit(ctx.typeDefinition()));
+ public ASTNode visitAlgorithmDefinition(final AlgorithmDefinitionContext ctx) {
+ return new AlgorithmSegment(getIdentifierValue(ctx.algorithmTypeName()), getProperties(ctx.propertiesDefinition()));
}
@Override
@@ -117,11 +115,6 @@ public final class DatabaseDiscoveryDistSQLStatementVisitor extends DatabaseDisc
return new DatabaseSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(), new IdentifierValue(ctx.getText()));
}
- @Override
- public ASTNode visitTypeDefinition(final TypeDefinitionContext ctx) {
- return new AlgorithmSegment(getIdentifierValue(ctx.discoveryType()), null == ctx.properties() ? new Properties() : getProperties(ctx.properties()));
- }
-
@Override
public ASTNode visitDropDatabaseDiscoveryType(final DropDatabaseDiscoveryTypeContext ctx) {
return new DropDatabaseDiscoveryTypeStatement(null != ctx.ifExists(), ctx.discoveryTypeName().stream().map(this::getIdentifierValue).collect(Collectors.toList()));
@@ -137,9 +130,12 @@ public final class DatabaseDiscoveryDistSQLStatementVisitor extends DatabaseDisc
return new CountDatabaseDiscoveryRuleStatement(Objects.nonNull(ctx.databaseName()) ? (DatabaseSegment) visit(ctx.databaseName()) : null);
}
- private Properties getProperties(final PropertiesContext ctx) {
+ private Properties getProperties(final PropertiesDefinitionContext ctx) {
Properties result = new Properties();
- for (PropertyContext each : ctx.property()) {
+ if (null == ctx || null == ctx.properties()) {
+ return result;
+ }
+ for (PropertyContext each : ctx.properties().property()) {
result.setProperty(IdentifierValue.getQuotedContent(each.key.getText()), IdentifierValue.getQuotedContent(each.value.getText()));
}
return result;
diff --git a/features/encrypt/distsql/parser/src/main/antlr4/imports/encrypt/BaseRule.g4 b/features/encrypt/distsql/parser/src/main/antlr4/imports/encrypt/BaseRule.g4
index b27323ec13b..f3bd1e0d4dd 100644
--- a/features/encrypt/distsql/parser/src/main/antlr4/imports/encrypt/BaseRule.g4
+++ b/features/encrypt/distsql/parser/src/main/antlr4/imports/encrypt/BaseRule.g4
@@ -19,6 +19,30 @@ grammar BaseRule;
import Symbol, Keyword, Literals;
+literal
+ : STRING | (MINUS)? INT | TRUE | FALSE
+ ;
+
+algorithmDefinition
+ : TYPE LP NAME EQ algorithmTypeName (COMMA propertiesDefinition)? RP
+ ;
+
+algorithmTypeName
+ : STRING
+ ;
+
+propertiesDefinition
+ : PROPERTIES LP properties? RP
+ ;
+
+properties
+ : property (COMMA property)*
+ ;
+
+property
+ : key=STRING EQ value=literal
+ ;
+
tableName
: IDENTIFIER
;
diff --git a/features/encrypt/distsql/parser/src/main/antlr4/imports/encrypt/RDLStatement.g4 b/features/encrypt/distsql/parser/src/main/antlr4/imports/encrypt/RDLStatement.g4
index d251ae3ec27..11b364953dc 100644
--- a/features/encrypt/distsql/parser/src/main/antlr4/imports/encrypt/RDLStatement.g4
+++ b/features/encrypt/distsql/parser/src/main/antlr4/imports/encrypt/RDLStatement.g4
@@ -82,22 +82,6 @@ assistedQueryColumnDefinition
assistedQueryColumnName
: IDENTIFIER
;
-
-algorithmDefinition
- : TYPE LP NAME EQ algorithmName (COMMA PROPERTIES LP algorithmProperties? RP)? RP
- ;
-
-algorithmName
- : STRING
- ;
-
-algorithmProperties
- : algorithmProperty (COMMA algorithmProperty)*
- ;
-
-algorithmProperty
- : key=(IDENTIFIER | STRING) EQ value=(NUMBER | INT | STRING)
- ;
queryWithCipherColumn
: TRUE | FALSE
diff --git a/features/encrypt/distsql/parser/src/main/java/org/apache/shardingsphere/encrypt/distsql/parser/core/EncryptDistSQLStatementVisitor.java b/features/encrypt/distsql/parser/src/main/java/org/apache/shardingsphere/encrypt/distsql/parser/core/EncryptDistSQLStatementVisitor.java
index 94e9d028e14..a264c3d8ce4 100644
--- a/features/encrypt/distsql/parser/src/main/java/org/apache/shardingsphere/encrypt/distsql/parser/core/EncryptDistSQLStatementVisitor.java
+++ b/features/encrypt/distsql/parser/src/main/java/org/apache/shardingsphere/encrypt/distsql/parser/core/EncryptDistSQLStatementVisitor.java
@@ -20,7 +20,6 @@ package org.apache.shardingsphere.encrypt.distsql.parser.core;
import org.antlr.v4.runtime.tree.ParseTree;
import org.apache.shardingsphere.distsql.parser.autogen.EncryptDistSQLStatementBaseVisitor;
import org.apache.shardingsphere.distsql.parser.autogen.EncryptDistSQLStatementParser.AlgorithmDefinitionContext;
-import org.apache.shardingsphere.distsql.parser.autogen.EncryptDistSQLStatementParser.AlgorithmPropertyContext;
import org.apache.shardingsphere.distsql.parser.autogen.EncryptDistSQLStatementParser.AlterEncryptRuleContext;
import org.apache.shardingsphere.distsql.parser.autogen.EncryptDistSQLStatementParser.CountEncryptRuleContext;
import org.apache.shardingsphere.distsql.parser.autogen.EncryptDistSQLStatementParser.CreateEncryptRuleContext;
@@ -28,6 +27,8 @@ import org.apache.shardingsphere.distsql.parser.autogen.EncryptDistSQLStatementP
import org.apache.shardingsphere.distsql.parser.autogen.EncryptDistSQLStatementParser.DropEncryptRuleContext;
import org.apache.shardingsphere.distsql.parser.autogen.EncryptDistSQLStatementParser.EncryptColumnDefinitionContext;
import org.apache.shardingsphere.distsql.parser.autogen.EncryptDistSQLStatementParser.EncryptRuleDefinitionContext;
+import org.apache.shardingsphere.distsql.parser.autogen.EncryptDistSQLStatementParser.PropertiesDefinitionContext;
+import org.apache.shardingsphere.distsql.parser.autogen.EncryptDistSQLStatementParser.PropertyContext;
import org.apache.shardingsphere.distsql.parser.autogen.EncryptDistSQLStatementParser.ShowEncryptRulesContext;
import org.apache.shardingsphere.distsql.parser.autogen.EncryptDistSQLStatementParser.TableNameContext;
import org.apache.shardingsphere.distsql.parser.segment.AlgorithmSegment;
@@ -103,19 +104,19 @@ public final class EncryptDistSQLStatementVisitor extends EncryptDistSQLStatemen
@Override
public ASTNode visitAlgorithmDefinition(final AlgorithmDefinitionContext ctx) {
- return new AlgorithmSegment(getIdentifierValue(ctx.algorithmName()), getAlgorithmProperties(ctx));
+ return new AlgorithmSegment(getIdentifierValue(ctx.algorithmTypeName()), getProperties(ctx.propertiesDefinition()));
}
private String getIdentifierValue(final ParseTree context) {
return null == context ? null : new IdentifierValue(context.getText()).getValue();
}
- private Properties getAlgorithmProperties(final AlgorithmDefinitionContext ctx) {
+ private Properties getProperties(final PropertiesDefinitionContext ctx) {
Properties result = new Properties();
- if (null == ctx.algorithmProperties()) {
+ if (null == ctx || null == ctx.properties()) {
return result;
}
- for (AlgorithmPropertyContext each : ctx.algorithmProperties().algorithmProperty()) {
+ for (PropertyContext each : ctx.properties().property()) {
result.setProperty(IdentifierValue.getQuotedContent(each.key.getText()), IdentifierValue.getQuotedContent(each.value.getText()));
}
return result;
diff --git a/features/readwrite-splitting/distsql/parser/src/main/antlr4/imports/readwrite-splitting/BaseRule.g4 b/features/readwrite-splitting/distsql/parser/src/main/antlr4/imports/readwrite-splitting/BaseRule.g4
index 4cde3a28bfb..6fb0fee5215 100644
--- a/features/readwrite-splitting/distsql/parser/src/main/antlr4/imports/readwrite-splitting/BaseRule.g4
+++ b/features/readwrite-splitting/distsql/parser/src/main/antlr4/imports/readwrite-splitting/BaseRule.g4
@@ -19,6 +19,30 @@ grammar BaseRule;
import Symbol, Keyword, Literals;
+literal
+ : STRING | (MINUS)? INT | TRUE | FALSE
+ ;
+
+algorithmDefinition
+ : TYPE LP NAME EQ algorithmTypeName (COMMA propertiesDefinition)? RP
+ ;
+
+algorithmTypeName
+ : STRING
+ ;
+
+propertiesDefinition
+ : PROPERTIES LP properties? RP
+ ;
+
+properties
+ : property (COMMA property)*
+ ;
+
+property
+ : key=STRING EQ value=literal
+ ;
+
databaseName
: IDENTIFIER
;
diff --git a/features/readwrite-splitting/distsql/parser/src/main/antlr4/imports/readwrite-splitting/RDLStatement.g4 b/features/readwrite-splitting/distsql/parser/src/main/antlr4/imports/readwrite-splitting/RDLStatement.g4
index 8bd7ebfd959..049838931ab 100644
--- a/features/readwrite-splitting/distsql/parser/src/main/antlr4/imports/readwrite-splitting/RDLStatement.g4
+++ b/features/readwrite-splitting/distsql/parser/src/main/antlr4/imports/readwrite-splitting/RDLStatement.g4
@@ -55,22 +55,6 @@ readStorageUnitsNames
: storageUnitName (COMMA storageUnitName)*
;
-algorithmDefinition
- : TYPE LP NAME EQ algorithmName (COMMA PROPERTIES LP algorithmProperties? RP)? RP
- ;
-
-algorithmName
- : STRING
- ;
-
-algorithmProperties
- : algorithmProperty (COMMA algorithmProperty)*
- ;
-
-algorithmProperty
- : key=STRING EQ value=(NUMBER | INT | STRING)
- ;
-
ifExists
: IF EXISTS
;
diff --git a/features/readwrite-splitting/distsql/parser/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/parser/core/ReadwriteSplittingDistSQLStatementVisitor.java b/features/readwrite-splitting/distsql/parser/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/parser/core/ReadwriteSplittingDistSQLStatementVisitor.java
index 243977b30ad..07dcc406e67 100644
--- a/features/readwrite-splitting/distsql/parser/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/parser/core/ReadwriteSplittingDistSQLStatementVisitor.java
+++ b/features/readwrite-splitting/distsql/parser/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/parser/core/ReadwriteSplittingDistSQLStatementVisitor.java
@@ -20,7 +20,6 @@ package org.apache.shardingsphere.readwritesplitting.distsql.parser.core;
import org.antlr.v4.runtime.tree.ParseTree;
import org.apache.shardingsphere.distsql.parser.autogen.ReadwriteSplittingDistSQLStatementBaseVisitor;
import org.apache.shardingsphere.distsql.parser.autogen.ReadwriteSplittingDistSQLStatementParser.AlgorithmDefinitionContext;
-import org.apache.shardingsphere.distsql.parser.autogen.ReadwriteSplittingDistSQLStatementParser.AlgorithmPropertyContext;
import org.apache.shardingsphere.distsql.parser.autogen.ReadwriteSplittingDistSQLStatementParser.AlterReadwriteSplittingRuleContext;
import org.apache.shardingsphere.distsql.parser.autogen.ReadwriteSplittingDistSQLStatementParser.AlterReadwriteSplittingRuleStatusContext;
import org.apache.shardingsphere.distsql.parser.autogen.ReadwriteSplittingDistSQLStatementParser.ClearReadwriteSplittingHintContext;
@@ -28,6 +27,8 @@ import org.apache.shardingsphere.distsql.parser.autogen.ReadwriteSplittingDistSQ
import org.apache.shardingsphere.distsql.parser.autogen.ReadwriteSplittingDistSQLStatementParser.CreateReadwriteSplittingRuleContext;
import org.apache.shardingsphere.distsql.parser.autogen.ReadwriteSplittingDistSQLStatementParser.DatabaseNameContext;
import org.apache.shardingsphere.distsql.parser.autogen.ReadwriteSplittingDistSQLStatementParser.DropReadwriteSplittingRuleContext;
+import org.apache.shardingsphere.distsql.parser.autogen.ReadwriteSplittingDistSQLStatementParser.PropertiesDefinitionContext;
+import org.apache.shardingsphere.distsql.parser.autogen.ReadwriteSplittingDistSQLStatementParser.PropertyContext;
import org.apache.shardingsphere.distsql.parser.autogen.ReadwriteSplittingDistSQLStatementParser.ReadwriteSplittingRuleDefinitionContext;
import org.apache.shardingsphere.distsql.parser.autogen.ReadwriteSplittingDistSQLStatementParser.SetReadwriteSplittingHintSourceContext;
import org.apache.shardingsphere.distsql.parser.autogen.ReadwriteSplittingDistSQLStatementParser.ShowReadwriteSplittingHintStatusContext;
@@ -92,20 +93,20 @@ public final class ReadwriteSplittingDistSQLStatementVisitor extends ReadwriteSp
@Override
public ASTNode visitReadwriteSplittingRuleDefinition(final ReadwriteSplittingRuleDefinitionContext ctx) {
Properties props = new Properties();
- String algorithmName = null;
+ String algorithmTypeName = null;
if (null != ctx.algorithmDefinition()) {
- algorithmName = getIdentifierValue(ctx.algorithmDefinition().algorithmName());
- props = getAlgorithmProperties(ctx.algorithmDefinition());
+ algorithmTypeName = getIdentifierValue(ctx.algorithmDefinition().algorithmTypeName());
+ props = getProperties(ctx.algorithmDefinition().propertiesDefinition());
}
if (null == ctx.staticReadwriteSplittingRuleDefinition()) {
return new ReadwriteSplittingRuleSegment(getIdentifierValue(ctx.ruleName()), getIdentifierValue(ctx.dynamicReadwriteSplittingRuleDefinition().resourceName()),
- getIdentifierValue(ctx.dynamicReadwriteSplittingRuleDefinition().writeDataSourceQueryEnabled()), algorithmName, props);
+ getIdentifierValue(ctx.dynamicReadwriteSplittingRuleDefinition().writeDataSourceQueryEnabled()), algorithmTypeName, props);
}
StaticReadwriteSplittingRuleDefinitionContext staticRuleDefinitionCtx = ctx.staticReadwriteSplittingRuleDefinition();
return new ReadwriteSplittingRuleSegment(getIdentifierValue(ctx.ruleName()),
getIdentifierValue(staticRuleDefinitionCtx.writeStorageUnitName()),
staticRuleDefinitionCtx.readStorageUnitsNames().storageUnitName().stream().map(this::getIdentifierValue).collect(Collectors.toList()),
- algorithmName, props);
+ algorithmTypeName, props);
}
@Override
@@ -115,7 +116,7 @@ public final class ReadwriteSplittingDistSQLStatementVisitor extends ReadwriteSp
@Override
public ASTNode visitAlgorithmDefinition(final AlgorithmDefinitionContext ctx) {
- return new AlgorithmSegment(getIdentifierValue(ctx.algorithmName()), getAlgorithmProperties(ctx));
+ return new AlgorithmSegment(getIdentifierValue(ctx.algorithmTypeName()), getProperties(ctx.propertiesDefinition()));
}
@Override
@@ -149,12 +150,12 @@ public final class ReadwriteSplittingDistSQLStatementVisitor extends ReadwriteSp
return new CountReadwriteSplittingRuleStatement(Objects.nonNull(ctx.databaseName()) ? (DatabaseSegment) visit(ctx.databaseName()) : null);
}
- private Properties getAlgorithmProperties(final AlgorithmDefinitionContext ctx) {
+ private Properties getProperties(final PropertiesDefinitionContext ctx) {
Properties result = new Properties();
- if (null == ctx.algorithmProperties()) {
+ if (null == ctx || null == ctx.properties()) {
return result;
}
- for (AlgorithmPropertyContext each : ctx.algorithmProperties().algorithmProperty()) {
+ for (PropertyContext each : ctx.properties().property()) {
result.setProperty(IdentifierValue.getQuotedContent(each.key.getText()), IdentifierValue.getQuotedContent(each.value.getText()));
}
return result;
diff --git a/features/shadow/distsql/parser/src/main/antlr4/imports/shadow/BaseRule.g4 b/features/shadow/distsql/parser/src/main/antlr4/imports/shadow/BaseRule.g4
index e30ff4fb987..349780d722d 100644
--- a/features/shadow/distsql/parser/src/main/antlr4/imports/shadow/BaseRule.g4
+++ b/features/shadow/distsql/parser/src/main/antlr4/imports/shadow/BaseRule.g4
@@ -19,6 +19,30 @@ grammar BaseRule;
import Symbol, Keyword, Literals;
+literal
+ : STRING | (MINUS)? INT | TRUE | FALSE
+ ;
+
+algorithmDefinition
+ : TYPE LP NAME EQ algorithmTypeName (COMMA propertiesDefinition)? RP
+ ;
+
+algorithmTypeName
+ : STRING
+ ;
+
+propertiesDefinition
+ : PROPERTIES LP properties? RP
+ ;
+
+properties
+ : property (COMMA property)*
+ ;
+
+property
+ : key=STRING EQ value=literal
+ ;
+
ruleName
: IDENTIFIER
;
diff --git a/features/shadow/distsql/parser/src/main/antlr4/imports/shadow/Keyword.g4 b/features/shadow/distsql/parser/src/main/antlr4/imports/shadow/Keyword.g4
index ae58cf7c14d..eecd5e3544a 100644
--- a/features/shadow/distsql/parser/src/main/antlr4/imports/shadow/Keyword.g4
+++ b/features/shadow/distsql/parser/src/main/antlr4/imports/shadow/Keyword.g4
@@ -23,6 +23,14 @@ WS
: [ \t\r\n] + ->skip
;
+TRUE
+ : T R U E
+ ;
+
+FALSE
+ : F A L S E
+ ;
+
CREATE
: C R E A T E
;
diff --git a/features/shadow/distsql/parser/src/main/antlr4/imports/shadow/RDLStatement.g4 b/features/shadow/distsql/parser/src/main/antlr4/imports/shadow/RDLStatement.g4
index 660c9921eab..e0089065572 100644
--- a/features/shadow/distsql/parser/src/main/antlr4/imports/shadow/RDLStatement.g4
+++ b/features/shadow/distsql/parser/src/main/antlr4/imports/shadow/RDLStatement.g4
@@ -36,7 +36,7 @@ dropShadowAlgorithm
;
createDefaultShadowAlgorithm
- : CREATE DEFAULT SHADOW ALGORITHM shadowAlgorithmDefinition
+ : CREATE DEFAULT SHADOW ALGORITHM algorithmDefinition
;
dropDefaultShadowAlgorithm
@@ -44,7 +44,7 @@ dropDefaultShadowAlgorithm
;
alterDefaultShadowAlgorithm
- : ALTER DEFAULT SHADOW ALGORITHM shadowAlgorithmDefinition
+ : ALTER DEFAULT SHADOW ALGORITHM algorithmDefinition
;
shadowRuleDefinition
@@ -52,41 +52,25 @@ shadowRuleDefinition
;
shadowTableRule
- : tableName LP shadowAlgorithmDefinition (COMMA shadowAlgorithmDefinition)* RP
+ : tableName LP algorithmDefinition (COMMA algorithmDefinition)* RP
;
source
- : IDENTIFIER | STRING
+ : IDENTIFIER
;
shadow
- : IDENTIFIER | STRING
+ : IDENTIFIER
;
tableName
: IDENTIFIER
;
-shadowAlgorithmDefinition
- : TYPE LP NAME EQ shadowAlgorithmType COMMA PROPERTIES LP algorithmProperties RP RP
- ;
-
algorithmName
: IDENTIFIER
;
-shadowAlgorithmType
- : STRING
- ;
-
-algorithmProperties
- : algorithmProperty (COMMA algorithmProperty)*
- ;
-
-algorithmProperty
- : key = STRING EQ value = (NUMBER | INT | STRING)
- ;
-
ifExists
: IF EXISTS
;
diff --git a/features/shadow/distsql/parser/src/main/java/org/apache/shardingsphere/shadow/distsql/parser/core/ShadowDistSQLStatementVisitor.java b/features/shadow/distsql/parser/src/main/java/org/apache/shardingsphere/shadow/distsql/parser/core/ShadowDistSQLStatementVisitor.java
index a6d11423262..fd7923bc060 100644
--- a/features/shadow/distsql/parser/src/main/java/org/apache/shardingsphere/shadow/distsql/parser/core/ShadowDistSQLStatementVisitor.java
+++ b/features/shadow/distsql/parser/src/main/java/org/apache/shardingsphere/shadow/distsql/parser/core/ShadowDistSQLStatementVisitor.java
@@ -19,7 +19,7 @@ package org.apache.shardingsphere.shadow.distsql.parser.core;
import org.antlr.v4.runtime.ParserRuleContext;
import org.apache.shardingsphere.distsql.parser.autogen.ShadowDistSQLStatementBaseVisitor;
-import org.apache.shardingsphere.distsql.parser.autogen.ShadowDistSQLStatementParser.AlgorithmPropertiesContext;
+import org.apache.shardingsphere.distsql.parser.autogen.ShadowDistSQLStatementParser.AlgorithmDefinitionContext;
import org.apache.shardingsphere.distsql.parser.autogen.ShadowDistSQLStatementParser.AlterDefaultShadowAlgorithmContext;
import org.apache.shardingsphere.distsql.parser.autogen.ShadowDistSQLStatementParser.AlterShadowRuleContext;
import org.apache.shardingsphere.distsql.parser.autogen.ShadowDistSQLStatementParser.CountShadowRuleContext;
@@ -29,7 +29,8 @@ import org.apache.shardingsphere.distsql.parser.autogen.ShadowDistSQLStatementPa
import org.apache.shardingsphere.distsql.parser.autogen.ShadowDistSQLStatementParser.DropDefaultShadowAlgorithmContext;
import org.apache.shardingsphere.distsql.parser.autogen.ShadowDistSQLStatementParser.DropShadowAlgorithmContext;
import org.apache.shardingsphere.distsql.parser.autogen.ShadowDistSQLStatementParser.DropShadowRuleContext;
-import org.apache.shardingsphere.distsql.parser.autogen.ShadowDistSQLStatementParser.ShadowAlgorithmDefinitionContext;
+import org.apache.shardingsphere.distsql.parser.autogen.ShadowDistSQLStatementParser.PropertiesDefinitionContext;
+import org.apache.shardingsphere.distsql.parser.autogen.ShadowDistSQLStatementParser.PropertyContext;
import org.apache.shardingsphere.distsql.parser.autogen.ShadowDistSQLStatementParser.ShadowRuleDefinitionContext;
import org.apache.shardingsphere.distsql.parser.autogen.ShadowDistSQLStatementParser.ShowDefaultShadowAlgorithmContext;
import org.apache.shardingsphere.distsql.parser.autogen.ShadowDistSQLStatementParser.ShowShadowAlgorithmsContext;
@@ -78,18 +79,18 @@ public final class ShadowDistSQLStatementVisitor extends ShadowDistSQLStatementB
@Override
public ASTNode visitCreateDefaultShadowAlgorithm(final CreateDefaultShadowAlgorithmContext ctx) {
- return new CreateDefaultShadowAlgorithmStatement((ShadowAlgorithmSegment) visit(ctx.shadowAlgorithmDefinition()));
+ return new CreateDefaultShadowAlgorithmStatement((ShadowAlgorithmSegment) visit(ctx.algorithmDefinition()));
}
@Override
public ASTNode visitAlterDefaultShadowAlgorithm(final AlterDefaultShadowAlgorithmContext ctx) {
- return new AlterDefaultShadowAlgorithmStatement((ShadowAlgorithmSegment) visit(ctx.shadowAlgorithmDefinition()));
+ return new AlterDefaultShadowAlgorithmStatement((ShadowAlgorithmSegment) visit(ctx.algorithmDefinition()));
}
@Override
public ASTNode visitShadowRuleDefinition(final ShadowRuleDefinitionContext ctx) {
Map<String, Collection<ShadowAlgorithmSegment>> shadowAlgorithms = ctx.shadowTableRule().stream()
- .collect(Collectors.toMap(each -> getIdentifierValue(each.tableName()), each -> visitShadowAlgorithms(each.shadowAlgorithmDefinition())));
+ .collect(Collectors.toMap(each -> getIdentifierValue(each.tableName()), each -> visitShadowAlgorithms(each.algorithmDefinition())));
return new ShadowRuleSegment(getIdentifierValue(ctx.ruleName()), getIdentifierValue(ctx.source()), getIdentifierValue(ctx.shadow()), shadowAlgorithms);
}
@@ -104,14 +105,19 @@ public final class ShadowDistSQLStatementVisitor extends ShadowDistSQLStatementB
}
@Override
- public ASTNode visitShadowAlgorithmDefinition(final ShadowAlgorithmDefinitionContext ctx) {
- AlgorithmSegment segment = new AlgorithmSegment(getIdentifierValue(ctx.shadowAlgorithmType()), getAlgorithmProperties(ctx.algorithmProperties()));
+ public ASTNode visitAlgorithmDefinition(final AlgorithmDefinitionContext ctx) {
+ AlgorithmSegment segment = new AlgorithmSegment(getIdentifierValue(ctx.algorithmTypeName()), getProperties(ctx.propertiesDefinition()));
return new ShadowAlgorithmSegment(null, segment);
}
- private Properties getAlgorithmProperties(final AlgorithmPropertiesContext ctx) {
+ private Properties getProperties(final PropertiesDefinitionContext ctx) {
Properties result = new Properties();
- ctx.algorithmProperty().forEach(each -> result.put(IdentifierValue.getQuotedContent(each.key.getText()), IdentifierValue.getQuotedContent(each.value.getText())));
+ if (null == ctx || null == ctx.properties()) {
+ return result;
+ }
+ for (PropertyContext each : ctx.properties().property()) {
+ result.setProperty(IdentifierValue.getQuotedContent(each.key.getText()), IdentifierValue.getQuotedContent(each.value.getText()));
+ }
return result;
}
@@ -154,7 +160,7 @@ public final class ShadowDistSQLStatementVisitor extends ShadowDistSQLStatementB
return null == ctx || ctx.isEmpty() ? null : new IdentifierValue(ctx.getText()).getValue();
}
- private Collection<ShadowAlgorithmSegment> visitShadowAlgorithms(final List<ShadowAlgorithmDefinitionContext> ctxs) {
+ private Collection<ShadowAlgorithmSegment> visitShadowAlgorithms(final List<AlgorithmDefinitionContext> ctxs) {
return ctxs.stream().map(this::visit).map(each -> (ShadowAlgorithmSegment) each).collect(Collectors.toList());
}
diff --git a/features/sharding/distsql/parser/src/main/antlr4/imports/migration/BaseRule.g4 b/features/sharding/distsql/parser/src/main/antlr4/imports/migration/BaseRule.g4
index ed09e54c051..f02d0cf5ac9 100644
--- a/features/sharding/distsql/parser/src/main/antlr4/imports/migration/BaseRule.g4
+++ b/features/sharding/distsql/parser/src/main/antlr4/imports/migration/BaseRule.g4
@@ -19,22 +19,18 @@ grammar BaseRule;
import Symbol, Keyword, Literals;
+literal
+ : STRING | (MINUS)? INT | TRUE | FALSE
+ ;
+
algorithmDefinition
- : TYPE LP NAME EQ algorithmTypeName (COMMA PROPERTIES LP algorithmProperties? RP)? RP
+ : TYPE LP NAME EQ algorithmTypeName (COMMA propertiesDefinition)? RP
;
algorithmTypeName
: STRING
;
-algorithmProperties
- : algorithmProperty (COMMA algorithmProperty)*
- ;
-
-algorithmProperty
- : key=STRING EQ value=STRING
- ;
-
propertiesDefinition
: PROPERTIES LP properties? RP
;
@@ -44,5 +40,5 @@ properties
;
property
- : key=STRING EQ value=STRING
+ : key=STRING EQ value=literal
;
diff --git a/features/sharding/distsql/parser/src/main/antlr4/imports/migration/Keyword.g4 b/features/sharding/distsql/parser/src/main/antlr4/imports/migration/Keyword.g4
index f058f01f2d0..ad501f9cabe 100644
--- a/features/sharding/distsql/parser/src/main/antlr4/imports/migration/Keyword.g4
+++ b/features/sharding/distsql/parser/src/main/antlr4/imports/migration/Keyword.g4
@@ -23,6 +23,14 @@ WS
: [ \t\r\n] + ->skip
;
+TRUE
+ : T R U E
+ ;
+
+FALSE
+ : F A L S E
+ ;
+
CREATE
: C R E A T E
;
diff --git a/features/sharding/distsql/parser/src/main/antlr4/imports/sharding/BaseRule.g4 b/features/sharding/distsql/parser/src/main/antlr4/imports/sharding/BaseRule.g4
index d7f5ca301bc..b040d5495a2 100644
--- a/features/sharding/distsql/parser/src/main/antlr4/imports/sharding/BaseRule.g4
+++ b/features/sharding/distsql/parser/src/main/antlr4/imports/sharding/BaseRule.g4
@@ -14,11 +14,35 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
+
grammar BaseRule;
import Symbol, Keyword, Literals;
+literal
+ : STRING | (MINUS)? INT | TRUE | FALSE
+ ;
+
+algorithmDefinition
+ : TYPE LP NAME EQ algorithmTypeName (COMMA propertiesDefinition)? RP
+ ;
+
+algorithmTypeName
+ : STRING
+ ;
+
+propertiesDefinition
+ : PROPERTIES LP properties? RP
+ ;
+
+properties
+ : property (COMMA property)*
+ ;
+
+property
+ : key=STRING EQ value=literal
+ ;
+
tableName
: IDENTIFIER
;
diff --git a/features/sharding/distsql/parser/src/main/antlr4/imports/sharding/RDLStatement.g4 b/features/sharding/distsql/parser/src/main/antlr4/imports/sharding/RDLStatement.g4
index 5b6f1c7fb7b..a541b2aeefd 100644
--- a/features/sharding/distsql/parser/src/main/antlr4/imports/sharding/RDLStatement.g4
+++ b/features/sharding/distsql/parser/src/main/antlr4/imports/sharding/RDLStatement.g4
@@ -88,7 +88,7 @@ shardingTableRuleDefinition
;
shardingAutoTableRule
- : tableName LP storageUnits COMMA autoShardingColumnDefinition COMMA algorithmDefinition (COMMA keyGenerateDefinition)? RP
+ : tableName LP storageUnits COMMA autoShardingColumnDefinition COMMA algorithmDefinition (COMMA keyGenerateDefinition)? (COMMA auditDeclaration)? RP
;
shardingTableRule
@@ -191,10 +191,6 @@ auditAllowHintDisable
: TRUE | FALSE
;
-algorithmDefinition
- : TYPE LP NAME EQ algorithmTypeName (COMMA PROPERTIES LP algorithmProperties? RP)? RP
- ;
-
columnName
: IDENTIFIER
;
@@ -207,22 +203,10 @@ shardingAlgorithmDefinition
: shardingAlgorithmName LP algorithmDefinition RP
;
-algorithmTypeName
- : STRING
- ;
-
strategyType
: STRING
;
-algorithmProperties
- : algorithmProperty (COMMA algorithmProperty)*
- ;
-
-algorithmProperty
- : key=STRING EQ value=STRING
- ;
-
ifExists
: IF EXISTS
;
diff --git a/features/sharding/distsql/parser/src/main/java/org/apache/shardingsphere/migration/distsql/parser/core/MigrationDistSQLStatementVisitor.java b/features/sharding/distsql/parser/src/main/java/org/apache/shardingsphere/migration/distsql/parser/core/MigrationDistSQLStatementVisitor.java
index 9807d765d08..0f41e7f5a86 100644
--- a/features/sharding/distsql/parser/src/main/java/org/apache/shardingsphere/migration/distsql/parser/core/MigrationDistSQLStatementVisitor.java
+++ b/features/sharding/distsql/parser/src/main/java/org/apache/shardingsphere/migration/distsql/parser/core/MigrationDistSQLStatementVisitor.java
@@ -129,18 +129,7 @@ public final class MigrationDistSQLStatementVisitor extends MigrationDistSQLStat
@Override
public ASTNode visitAlgorithmDefinition(final AlgorithmDefinitionContext ctx) {
- return new AlgorithmSegment(getIdentifierValue(ctx.algorithmTypeName()), getAlgorithmProperties(ctx));
- }
-
- private Properties getAlgorithmProperties(final AlgorithmDefinitionContext ctx) {
- Properties result = new Properties();
- if (null == ctx.algorithmProperties()) {
- return result;
- }
- for (MigrationDistSQLStatementParser.AlgorithmPropertyContext each : ctx.algorithmProperties().algorithmProperty()) {
- result.setProperty(IdentifierValue.getQuotedContent(each.key.getText()), IdentifierValue.getQuotedContent(each.value.getText()));
- }
- return result;
+ return new AlgorithmSegment(getIdentifierValue(ctx.algorithmTypeName()), getProperties(ctx.propertiesDefinition()));
}
private String getIdentifierValue(final ParseTree context) {
diff --git a/features/sharding/distsql/parser/src/main/java/org/apache/shardingsphere/sharding/distsql/parser/core/ShardingDistSQLStatementVisitor.java b/features/sharding/distsql/parser/src/main/java/org/apache/shardingsphere/sharding/distsql/parser/core/ShardingDistSQLStatementVisitor.java
index 8e4eac995af..c1a5a66a53d 100644
--- a/features/sharding/distsql/parser/src/main/java/org/apache/shardingsphere/sharding/distsql/parser/core/ShardingDistSQLStatementVisitor.java
+++ b/features/sharding/distsql/parser/src/main/java/org/apache/shardingsphere/sharding/distsql/parser/core/ShardingDistSQLStatementVisitor.java
@@ -22,7 +22,6 @@ import org.apache.shardingsphere.distsql.parser.autogen.ShardingDistSQLStatement
import org.apache.shardingsphere.distsql.parser.autogen.ShardingDistSQLStatementParser.AddShardingHintDatabaseValueContext;
import org.apache.shardingsphere.distsql.parser.autogen.ShardingDistSQLStatementParser.AddShardingHintTableValueContext;
import org.apache.shardingsphere.distsql.parser.autogen.ShardingDistSQLStatementParser.AlgorithmDefinitionContext;
-import org.apache.shardingsphere.distsql.parser.autogen.ShardingDistSQLStatementParser.AlgorithmPropertyContext;
import org.apache.shardingsphere.distsql.parser.autogen.ShardingDistSQLStatementParser.AlterDefaultShardingStrategyContext;
import org.apache.shardingsphere.distsql.parser.autogen.ShardingDistSQLStatementParser.AlterShardingAuditorContext;
import org.apache.shardingsphere.distsql.parser.autogen.ShardingDistSQLStatementParser.AlterShardingTableReferenceRuleContext;
@@ -49,6 +48,8 @@ import org.apache.shardingsphere.distsql.parser.autogen.ShardingDistSQLStatement
import org.apache.shardingsphere.distsql.parser.autogen.ShardingDistSQLStatementParser.DropShardingTableReferenceRuleContext;
import org.apache.shardingsphere.distsql.parser.autogen.ShardingDistSQLStatementParser.DropShardingTableRuleContext;
import org.apache.shardingsphere.distsql.parser.autogen.ShardingDistSQLStatementParser.KeyGenerateDefinitionContext;
+import org.apache.shardingsphere.distsql.parser.autogen.ShardingDistSQLStatementParser.PropertiesDefinitionContext;
+import org.apache.shardingsphere.distsql.parser.autogen.ShardingDistSQLStatementParser.PropertyContext;
import org.apache.shardingsphere.distsql.parser.autogen.ShardingDistSQLStatementParser.SetShardingHintDatabaseValueContext;
import org.apache.shardingsphere.distsql.parser.autogen.ShardingDistSQLStatementParser.ShardingAutoTableRuleContext;
import org.apache.shardingsphere.distsql.parser.autogen.ShardingDistSQLStatementParser.ShardingColumnDefinitionContext;
@@ -309,6 +310,7 @@ public final class ShardingDistSQLStatementVisitor extends ShardingDistSQLStatem
public ASTNode visitShardingAutoTableRule(final ShardingAutoTableRuleContext ctx) {
AutoTableRuleSegment result = new AutoTableRuleSegment(getIdentifierValue(ctx.tableName()), getResources(ctx.storageUnits()));
Optional.ofNullable(ctx.keyGenerateDefinition()).ifPresent(optional -> result.setKeyGenerateStrategySegment((KeyGenerateStrategySegment) visit(ctx.keyGenerateDefinition())));
+ Optional.ofNullable(ctx.auditDeclaration()).ifPresent(optional -> result.setAuditStrategySegment((AuditStrategySegment) visit(ctx.auditDeclaration())));
Optional.ofNullable(ctx.autoShardingColumnDefinition()).ifPresent(optional -> result.setShardingColumn(buildShardingColumn(ctx.autoShardingColumnDefinition())));
Optional.ofNullable(ctx.algorithmDefinition()).ifPresent(optional -> result.setShardingAlgorithmSegment((AlgorithmSegment) visit(ctx.algorithmDefinition())));
return result;
@@ -368,7 +370,7 @@ public final class ShardingDistSQLStatementVisitor extends ShardingDistSQLStatem
@Override
public ASTNode visitAlgorithmDefinition(final AlgorithmDefinitionContext ctx) {
- return new AlgorithmSegment(getIdentifierValue(ctx.algorithmTypeName()), getAlgorithmProperties(ctx));
+ return new AlgorithmSegment(getIdentifierValue(ctx.algorithmTypeName()), getProperties(ctx.propertiesDefinition()));
}
private String getIdentifierValue(final ParseTree context) {
@@ -386,12 +388,12 @@ public final class ShardingDistSQLStatementVisitor extends ShardingDistSQLStatem
return value.trim();
}
- private Properties getAlgorithmProperties(final AlgorithmDefinitionContext ctx) {
+ private Properties getProperties(final PropertiesDefinitionContext ctx) {
Properties result = new Properties();
- if (null == ctx.algorithmProperties()) {
+ if (null == ctx || null == ctx.properties()) {
return result;
}
- for (AlgorithmPropertyContext each : ctx.algorithmProperties().algorithmProperty()) {
+ for (PropertyContext each : ctx.properties().property()) {
result.setProperty(IdentifierValue.getQuotedContent(each.key.getText()), IdentifierValue.getQuotedContent(each.value.getText()));
}
return result;
diff --git a/test/parser/src/main/resources/case/rdl/create.xml b/test/parser/src/main/resources/case/rdl/create.xml
index 1dcf0e09ee8..8d06fca9341 100644
--- a/test/parser/src/main/resources/case/rdl/create.xml
+++ b/test/parser/src/main/resources/case/rdl/create.xml
@@ -55,6 +55,7 @@
<data-source name="ds_0" hostname="127.0.0.1" port="3306" db="test0" user="ROOT" password="123456">
<properties>
<property key="maxPoolSize" value="30" />
+ <property key="idleTimeout" value="30000" />
</properties>
</data-source>
</add-resource>
diff --git a/test/parser/src/main/resources/sql/supported/rdl/create.xml b/test/parser/src/main/resources/sql/supported/rdl/create.xml
index 78167fc1589..7eeee949f97 100644
--- a/test/parser/src/main/resources/sql/supported/rdl/create.xml
+++ b/test/parser/src/main/resources/sql/supported/rdl/create.xml
@@ -23,11 +23,11 @@
<distsql-case id="add-resource-url-single-without-password" value="REGISTER STORAGE UNIT ds_0(URL='jdbc:mysql://127.0.0.1:3306/test0',USER='ROOT');" />
<distsql-case id="add-resource-url-single-with-password" value="REGISTER STORAGE UNIT ds_0(URL='jdbc:mysql://127.0.0.1:3306/test0',USER='ROOT',PASSWORD='123456');" />
<distsql-case id="add-resource-url-multiple" value="REGISTER STORAGE UNIT ds_0(URL='jdbc:mysql://127.0.0.1:3306/test0',USER='ROOT',PASSWORD='123456'), ds_1(URL='jdbc:mysql://127.0.0.1:3306/test1',USER='ROOT',PASSWORD='123456');" />
- <distsql-case id="add-resource-single-with-properties" value="REGISTER STORAGE UNIT ds_0(HOST='127.0.0.1',PORT=3306,DB='test0',USER='ROOT',PASSWORD='123456',PROPERTIES('maxPoolSize'='30'));" />
+ <distsql-case id="add-resource-single-with-properties" value="REGISTER STORAGE UNIT ds_0(HOST='127.0.0.1',PORT=3306,DB='test0',USER='ROOT',PASSWORD='123456',PROPERTIES('maxPoolSize'='30','idleTimeout'=30000));" />
<distsql-case id="add-resource-url-single-with-empty-properties" value="REGISTER STORAGE UNIT ds_0(URL='jdbc:mysql://127.0.0.1:3306/test0',USER='ROOT',PROPERTIES())" />
<distsql-case id="add-resource-url-single-with-properties" value="REGISTER STORAGE UNIT ds_0(URL='jdbc:mysql://127.0.0.1:3306/test0',USER='ROOT',PASSWORD='123456',PROPERTIES('maxPoolSize'='30'))" />
<distsql-case id="create-sharding-auto-table-rule" value="CREATE SHARDING TABLE RULE t_order (STORAGE_UNITS(ms_group_0,ms_group_1), SHARDING_COLUMN=order_id,TYPE(NAME='hash_mod',PROPERTIES('sharding-count'='4')), KEY_GENERATE_STRATEGY(COLUMN=another_id,TYPE(NAME='snowflake')))" />
- <distsql-case id="create-sharding-auto-table-rule-with-inline-expression" value="CREATE SHARDING TABLE RULE t_order (STORAGE_UNITS('ms_group_${0..1}'), SHARDING_COLUMN=order_id,TYPE(NAME='hash_mod',PROPERTIES('sharding-count'='4')), KEY_GENERATE_STRATEGY(COLUMN=another_id,TYPE(NAME='snowflake')))" />
+ <distsql-case id="create-sharding-auto-table-rule-with-inline-expression" value="CREATE SHARDING TABLE RULE t_order (STORAGE_UNITS('ms_group_${0..1}'), SHARDING_COLUMN=order_id,TYPE(NAME='hash_mod',PROPERTIES('sharding-count'=4)), KEY_GENERATE_STRATEGY(COLUMN=another_id,TYPE(NAME='snowflake')))" />
<distsql-case id="create-sharding-table-reference-rule" value="CREATE SHARDING TABLE REFERENCE RULE (t_order,t_order_item), (t_1,t_2)" />
<distsql-case id="create-sharding-table-reference-rule-with-quota" value="CREATE SHARDING TABLE REFERENCE RULE (`t_order`,`t_order_item`), (t_1,t_2)" />
<distsql-case id="create-broadcast-table-rule" value="CREATE BROADCAST TABLE RULE t_1,t_2" />