diff --git a/shardingsphere-distsql-parser/shardingsphere-distsql-parser-engine/src/main/java/org/apache/shardingsphere/distsql/parser/core/common/CommonDistSQLStatementVisitor.java b/shardingsphere-distsql-parser/shardingsphere-distsql-parser-engine/src/main/java/org/apache/shardingsphere/distsql/parser/core/common/CommonDistSQLStatementVisitor.java index 656faa44fd9ad..214bdd917c912 100644 --- a/shardingsphere-distsql-parser/shardingsphere-distsql-parser-engine/src/main/java/org/apache/shardingsphere/distsql/parser/core/common/CommonDistSQLStatementVisitor.java +++ b/shardingsphere-distsql-parser/shardingsphere-distsql-parser-engine/src/main/java/org/apache/shardingsphere/distsql/parser/core/common/CommonDistSQLStatementVisitor.java @@ -80,7 +80,7 @@ public ASTNode visitDataSource(final DataSourceContext ctx) { port = ctx.simpleSource().port().getText(); dbName = ctx.simpleSource().dbName().getText(); } - return new DataSourceSegment(ctx.dataSourceName().getText(), url, hostName, port, dbName, + return new DataSourceSegment(getIdentifierValue(ctx.dataSourceName()), url, hostName, port, dbName, ctx.user().getText(), null == ctx.password() ? "" : getPassword(ctx.password()), null == ctx.poolProperties() ? new Properties() : getPoolProperties(ctx.poolProperties())); } @@ -110,7 +110,7 @@ private Properties getPoolProperties(final PoolPropertiesContext ctx) { @Override public ASTNode visitDropResource(final DropResourceContext ctx) { boolean ignoreSingleTables = null != ctx.ignoreSingleTables(); - return new DropResourceStatement(ctx.IDENTIFIER().stream().map(ParseTree::getText).collect(Collectors.toList()), ignoreSingleTables); + return new DropResourceStatement(ctx.IDENTIFIER().stream().map(ParseTree::getText).map(each -> new IdentifierValue(each).getValue()).collect(Collectors.toList()), ignoreSingleTables); } @Override @@ -125,12 +125,19 @@ public ASTNode visitSchemaName(final SchemaNameContext ctx) { @Override public ASTNode visitSetVariable(final SetVariableContext ctx) { - return new SetVariableStatement(ctx.variableName().getText(), ctx.variableValue().getText()); + return new SetVariableStatement(getIdentifierValue(ctx.variableName()), getIdentifierValue(ctx.variableValue())); } @Override public ASTNode visitShowVariable(final ShowVariableContext ctx) { - return new ShowVariableStatement(ctx.variableName().getText()); + return new ShowVariableStatement(getIdentifierValue(ctx.variableName())); + } + + private String getIdentifierValue(final ParseTree context) { + if (null == context) { + return null; + } + return new IdentifierValue(context.getText()).getValue(); } @Override diff --git a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-parser/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/parser/core/DatabaseDiscoveryDistSQLStatementVisitor.java b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-parser/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/parser/core/DatabaseDiscoveryDistSQLStatementVisitor.java index 501c791826e58..71560844bf565 100644 --- a/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-parser/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/parser/core/DatabaseDiscoveryDistSQLStatementVisitor.java +++ b/shardingsphere-features/shardingsphere-db-discovery/shardingsphere-db-discovery-distsql/shardingsphere-db-discovery-distsql-parser/src/main/java/org/apache/shardingsphere/dbdiscovery/distsql/parser/core/DatabaseDiscoveryDistSQLStatementVisitor.java @@ -17,6 +17,7 @@ package org.apache.shardingsphere.dbdiscovery.distsql.parser.core; +import org.antlr.v4.runtime.tree.ParseTree; import org.apache.shardingsphere.dbdiscovery.distsql.parser.segment.DatabaseDiscoveryRuleSegment; import org.apache.shardingsphere.dbdiscovery.distsql.parser.statement.AlterDatabaseDiscoveryRuleStatement; import org.apache.shardingsphere.dbdiscovery.distsql.parser.statement.CreateDatabaseDiscoveryRuleStatement; @@ -30,7 +31,6 @@ import org.apache.shardingsphere.distsql.parser.autogen.DatabaseDiscoveryDistSQLStatementParser.CreateDatabaseDiscoveryRuleContext; import org.apache.shardingsphere.distsql.parser.autogen.DatabaseDiscoveryDistSQLStatementParser.DatabaseDiscoveryRuleDefinitionContext; import org.apache.shardingsphere.distsql.parser.autogen.DatabaseDiscoveryDistSQLStatementParser.DropDatabaseDiscoveryRuleContext; -import org.apache.shardingsphere.distsql.parser.autogen.DatabaseDiscoveryDistSQLStatementParser.RuleNameContext; import org.apache.shardingsphere.distsql.parser.autogen.DatabaseDiscoveryDistSQLStatementParser.SchemaNameContext; import org.apache.shardingsphere.distsql.parser.autogen.DatabaseDiscoveryDistSQLStatementParser.ShowDatabaseDiscoveryRulesContext; import org.apache.shardingsphere.distsql.parser.segment.AlgorithmSegment; @@ -60,7 +60,7 @@ public ASTNode visitAlterDatabaseDiscoveryRule(final AlterDatabaseDiscoveryRuleC @Override public ASTNode visitDropDatabaseDiscoveryRule(final DropDatabaseDiscoveryRuleContext ctx) { - return new DropDatabaseDiscoveryRuleStatement(ctx.ruleName().stream().map(RuleNameContext::getText).collect(Collectors.toList())); + return new DropDatabaseDiscoveryRuleStatement(ctx.ruleName().stream().map(each -> getIdentifierValue(each)).collect(Collectors.toList())); } @Override @@ -71,8 +71,15 @@ public ASTNode visitShowDatabaseDiscoveryRules(final ShowDatabaseDiscoveryRulesC @Override public ASTNode visitDatabaseDiscoveryRuleDefinition(final DatabaseDiscoveryRuleDefinitionContext ctx) { Collection dataSources = ctx.resources().resourceName().stream().map(each -> new IdentifierValue(each.getText()).getValue()).collect(Collectors.toList()); - return new DatabaseDiscoveryRuleSegment(ctx.ruleName().getText(), - dataSources, ctx.algorithmDefinition().algorithmName().getText(), getAlgorithmProperties(ctx.algorithmDefinition().algorithmProperties())); + return new DatabaseDiscoveryRuleSegment(getIdentifierValue(ctx.ruleName()), + dataSources, getIdentifierValue(ctx.algorithmDefinition().algorithmName()), getAlgorithmProperties(ctx.algorithmDefinition().algorithmProperties())); + } + + private String getIdentifierValue(final ParseTree context) { + if (null == context) { + return null; + } + return new IdentifierValue(context.getText()).getValue(); } @Override @@ -82,7 +89,7 @@ public ASTNode visitSchemaName(final SchemaNameContext ctx) { @Override public ASTNode visitAlgorithmDefinition(final AlgorithmDefinitionContext ctx) { - return new AlgorithmSegment(ctx.algorithmName().getText(), null == ctx.algorithmProperties() ? new Properties() : getAlgorithmProperties(ctx.algorithmProperties())); + return new AlgorithmSegment(getIdentifierValue(ctx.algorithmName()), null == ctx.algorithmProperties() ? new Properties() : getAlgorithmProperties(ctx.algorithmProperties())); } private Properties getAlgorithmProperties(final AlgorithmPropertiesContext ctx) { diff --git a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-distsql/shardingsphere-encrypt-distsql-parser/src/main/java/org/apache/shardingsphere/encrypt/distsql/parser/core/EncryptDistSQLStatementVisitor.java b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-distsql/shardingsphere-encrypt-distsql-parser/src/main/java/org/apache/shardingsphere/encrypt/distsql/parser/core/EncryptDistSQLStatementVisitor.java index 5a6f6b45d3091..3db96804a6986 100644 --- a/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-distsql/shardingsphere-encrypt-distsql-parser/src/main/java/org/apache/shardingsphere/encrypt/distsql/parser/core/EncryptDistSQLStatementVisitor.java +++ b/shardingsphere-features/shardingsphere-encrypt/shardingsphere-encrypt-distsql/shardingsphere-encrypt-distsql-parser/src/main/java/org/apache/shardingsphere/encrypt/distsql/parser/core/EncryptDistSQLStatementVisitor.java @@ -17,6 +17,7 @@ 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; @@ -61,30 +62,37 @@ public ASTNode visitAlterEncryptRule(final AlterEncryptRuleContext ctx) { @Override public ASTNode visitDropEncryptRule(final DropEncryptRuleContext ctx) { - return new DropEncryptRuleStatement(ctx.tableName().stream().map(TableNameContext::getText).collect(Collectors.toList())); + return new DropEncryptRuleStatement(ctx.tableName().stream().map(each -> getIdentifierValue(each)).collect(Collectors.toList())); } @Override public ASTNode visitShowEncryptRules(final ShowEncryptRulesContext ctx) { - return new ShowEncryptRulesStatement(null == ctx.tableRule() ? null : ctx.tableRule().tableName().getText(), + return new ShowEncryptRulesStatement(null == ctx.tableRule() ? null : getIdentifierValue(ctx.tableRule().tableName()), null == ctx.schemaName() ? null : (SchemaSegment) visit(ctx.schemaName())); } @Override public ASTNode visitEncryptRuleDefinition(final EncryptRuleDefinitionContext ctx) { - return new EncryptRuleSegment(ctx.tableName().getText(), ctx.columnDefinition().stream().map(each -> (EncryptColumnSegment) visit(each)).collect(Collectors.toList())); + return new EncryptRuleSegment(getIdentifierValue(ctx.tableName()), ctx.columnDefinition().stream().map(each -> (EncryptColumnSegment) visit(each)).collect(Collectors.toList())); } @Override public ASTNode visitColumnDefinition(final ColumnDefinitionContext ctx) { - return new EncryptColumnSegment(ctx.columnName().getText(), - ctx.cipherColumnName().getText(), null == ctx.plainColumnName() ? null : ctx.plainColumnName().getText(), - null == ctx.assistedQueryColumnName() ? null : ctx.assistedQueryColumnName().getText(), (AlgorithmSegment) visit(ctx.algorithmDefinition())); + return new EncryptColumnSegment(getIdentifierValue(ctx.columnName()), + getIdentifierValue(ctx.cipherColumnName()), null == ctx.plainColumnName() ? null : getIdentifierValue(ctx.plainColumnName()), + null == ctx.assistedQueryColumnName() ? null : getIdentifierValue(ctx.assistedQueryColumnName()), (AlgorithmSegment) visit(ctx.algorithmDefinition())); } @Override public ASTNode visitAlgorithmDefinition(final AlgorithmDefinitionContext ctx) { - return new AlgorithmSegment(ctx.algorithmName().getText(), getAlgorithmProperties(ctx)); + return new AlgorithmSegment(getIdentifierValue(ctx.algorithmName()), getAlgorithmProperties(ctx)); + } + + private String getIdentifierValue(final ParseTree context) { + if (null == context) { + return null; + } + return new IdentifierValue(context.getText()).getValue(); } private Properties getAlgorithmProperties(final AlgorithmDefinitionContext ctx) { diff --git a/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-distsql/shardingsphere-readwrite-splitting-distsql-parser/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/parser/core/ReadwriteSplittingDistSQLStatementVisitor.java b/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-distsql/shardingsphere-readwrite-splitting-distsql-parser/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/parser/core/ReadwriteSplittingDistSQLStatementVisitor.java index deafd1c1510f7..10150109fcbce 100644 --- a/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-distsql/shardingsphere-readwrite-splitting-distsql-parser/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/parser/core/ReadwriteSplittingDistSQLStatementVisitor.java +++ b/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-distsql/shardingsphere-readwrite-splitting-distsql-parser/src/main/java/org/apache/shardingsphere/readwritesplitting/distsql/parser/core/ReadwriteSplittingDistSQLStatementVisitor.java @@ -17,7 +17,7 @@ package org.apache.shardingsphere.readwritesplitting.distsql.parser.core; -import org.antlr.v4.runtime.RuleContext; +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; @@ -28,7 +28,6 @@ import org.apache.shardingsphere.distsql.parser.autogen.ReadwriteSplittingDistSQLStatementParser.DropReadwriteSplittingRuleContext; import org.apache.shardingsphere.distsql.parser.autogen.ReadwriteSplittingDistSQLStatementParser.EnableReadDataSourceContext; import org.apache.shardingsphere.distsql.parser.autogen.ReadwriteSplittingDistSQLStatementParser.ReadwriteSplittingRuleDefinitionContext; -import org.apache.shardingsphere.distsql.parser.autogen.ReadwriteSplittingDistSQLStatementParser.RuleNameContext; import org.apache.shardingsphere.distsql.parser.autogen.ReadwriteSplittingDistSQLStatementParser.SchemaNameContext; import org.apache.shardingsphere.distsql.parser.autogen.ReadwriteSplittingDistSQLStatementParser.SetReadwriteSplittingHintSourceContext; import org.apache.shardingsphere.distsql.parser.autogen.ReadwriteSplittingDistSQLStatementParser.ShowReadwriteSplittingHintStatusContext; @@ -70,19 +69,19 @@ public ASTNode visitAlterReadwriteSplittingRule(final AlterReadwriteSplittingRul @Override public ASTNode visitDropReadwriteSplittingRule(final DropReadwriteSplittingRuleContext ctx) { - return new DropReadwriteSplittingRuleStatement(ctx.ruleName().stream().map(RuleNameContext::getText).collect(Collectors.toList())); + return new DropReadwriteSplittingRuleStatement(ctx.ruleName().stream().map(each -> getIdentifierValue(each)).collect(Collectors.toList())); } @Override public ASTNode visitEnableReadDataSource(final EnableReadDataSourceContext ctx) { SchemaSegment schemaSegment = Objects.nonNull(ctx.schemaName()) ? (SchemaSegment) visit(ctx.schemaName()) : null; - return new SetReadwriteSplittingStatusStatement(ctx.ENABLE().getText().toUpperCase(), new IdentifierValue(ctx.resourceName().getText()).getValue(), schemaSegment); + return new SetReadwriteSplittingStatusStatement(ctx.ENABLE().getText().toUpperCase(), getIdentifierValue(ctx.resourceName()), schemaSegment); } @Override public ASTNode visitDisableReadDataSource(final DisableReadDataSourceContext ctx) { SchemaSegment schemaSegment = Objects.nonNull(ctx.schemaName()) ? (SchemaSegment) visit(ctx.schemaName()) : null; - return new SetReadwriteSplittingStatusStatement(ctx.DISABLE().getText().toUpperCase(), new IdentifierValue(ctx.resourceName().getText()).getValue(), schemaSegment); + return new SetReadwriteSplittingStatusStatement(ctx.DISABLE().getText().toUpperCase(), getIdentifierValue(ctx.resourceName()), schemaSegment); } @Override @@ -97,13 +96,14 @@ public ASTNode visitReadwriteSplittingRuleDefinition(final ReadwriteSplittingRul ctx.algorithmDefinition().algorithmProperties().algorithmProperty().forEach(each -> props.setProperty(each.key.getText(), each.value.getText())); } if (null == ctx.staticReadwriteSplittingRuleDefinition()) { - return new ReadwriteSplittingRuleSegment( - ctx.ruleName().getText(), ctx.dynamicReadwriteSplittingRuleDefinition().resourceName().getText(), ctx.algorithmDefinition().algorithmName().getText(), props); + return new ReadwriteSplittingRuleSegment(getIdentifierValue(ctx.ruleName()), getIdentifierValue(ctx.dynamicReadwriteSplittingRuleDefinition().resourceName()), + getIdentifierValue(ctx.algorithmDefinition().algorithmName()), props); } StaticReadwriteSplittingRuleDefinitionContext staticRuleDefinitionCtx = ctx.staticReadwriteSplittingRuleDefinition(); - return new ReadwriteSplittingRuleSegment(ctx.ruleName().getText(), - staticRuleDefinitionCtx.writeResourceName().getText(), staticRuleDefinitionCtx.readResourceNames().resourceName().stream().map(RuleContext::getText).collect(Collectors.toList()), - ctx.algorithmDefinition().algorithmName().getText(), props); + return new ReadwriteSplittingRuleSegment(getIdentifierValue(ctx.ruleName()), + getIdentifierValue(staticRuleDefinitionCtx.writeResourceName()), + staticRuleDefinitionCtx.readResourceNames().resourceName().stream().map(each -> getIdentifierValue(each)).collect(Collectors.toList()), + getIdentifierValue(ctx.algorithmDefinition().algorithmName()), props); } @Override @@ -113,12 +113,19 @@ public ASTNode visitSchemaName(final SchemaNameContext ctx) { @Override public ASTNode visitAlgorithmDefinition(final AlgorithmDefinitionContext ctx) { - return new AlgorithmSegment(ctx.algorithmName().getText(), getAlgorithmProperties(ctx)); + return new AlgorithmSegment(getIdentifierValue(ctx.algorithmName()), getAlgorithmProperties(ctx)); } @Override public ASTNode visitSetReadwriteSplittingHintSource(final SetReadwriteSplittingHintSourceContext ctx) { - return new SetReadwriteSplittingHintStatement(ctx.sourceValue().getText()); + return new SetReadwriteSplittingHintStatement(getIdentifierValue(ctx.sourceValue())); + } + + private String getIdentifierValue(final ParseTree context) { + if (null == context) { + return null; + } + return new IdentifierValue(context.getText()).getValue(); } @Override diff --git a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-parser/src/main/java/org/apache/shardingsphere/shadow/distsql/parser/core/ShadowDistSQLStatementVisitor.java b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-parser/src/main/java/org/apache/shardingsphere/shadow/distsql/parser/core/ShadowDistSQLStatementVisitor.java index 7e62a190899f0..74415f0e1ca32 100644 --- a/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-parser/src/main/java/org/apache/shardingsphere/shadow/distsql/parser/core/ShadowDistSQLStatementVisitor.java +++ b/shardingsphere-features/shardingsphere-shadow/shardingsphere-shadow-distsql/shardingsphere-shadow-distsql-parser/src/main/java/org/apache/shardingsphere/shadow/distsql/parser/core/ShadowDistSQLStatementVisitor.java @@ -70,8 +70,8 @@ public ASTNode visitCreateShadowRule(final CreateShadowRuleContext ctx) { @Override public ASTNode visitShadowRuleDefinition(final ShadowRuleDefinitionContext ctx) { Map> shadowAlgorithms = ctx.shadowTableRule().stream() - .collect(Collectors.toMap(each -> getText(each.tableName()), each -> visitShadowAlgorithms(each.shadowAlgorithmDefinition()), (oldValue, newValue) -> newValue)); - return new ShadowRuleSegment(getText(ctx.ruleName()), getText(ctx.source()), getText(ctx.shadow()), shadowAlgorithms); + .collect(Collectors.toMap(each -> getIdentifierValue(each.tableName()), each -> visitShadowAlgorithms(each.shadowAlgorithmDefinition()), (oldValue, newValue) -> newValue)); + return new ShadowRuleSegment(getIdentifierValue(ctx.ruleName()), getIdentifierValue(ctx.source()), getIdentifierValue(ctx.shadow()), shadowAlgorithms); } @Override @@ -81,9 +81,10 @@ public ASTNode visitShowShadowAlgorithms(final ShowShadowAlgorithmsContext ctx) @Override public ASTNode visitShadowAlgorithmDefinition(final ShadowAlgorithmDefinitionContext ctx) { - AlgorithmSegment segment = new AlgorithmSegment(getText(ctx.shadowAlgorithmType()), getAlgorithmProperties(ctx.algorithmProperties())); - String algorithmName = null != ctx.algorithmName() ? getText(ctx.algorithmName()) - : createAlgorithmName(getText(((ShadowRuleDefinitionContext) ctx.getParent().getParent()).ruleName()), getText(((ShadowTableRuleContext) ctx.getParent()).tableName()), segment); + AlgorithmSegment segment = new AlgorithmSegment(getIdentifierValue(ctx.shadowAlgorithmType()), getAlgorithmProperties(ctx.algorithmProperties())); + String algorithmName = null != ctx.algorithmName() ? getIdentifierValue(ctx.algorithmName()) + : createAlgorithmName(getIdentifierValue(((ShadowRuleDefinitionContext) ctx.getParent().getParent()).ruleName()), + getIdentifierValue(((ShadowTableRuleContext) ctx.getParent()).tableName()), segment); return new ShadowAlgorithmSegment(algorithmName, segment); } @@ -112,12 +113,12 @@ public ASTNode visitAlterShadowAlgorithm(final AlterShadowAlgorithmContext ctx) @Override public ASTNode visitDropShadowAlgorithm(final DropShadowAlgorithmContext ctx) { return new DropShadowAlgorithmStatement(null == ctx.algorithmName() ? Collections.emptyList() - : ctx.algorithmName().stream().map(ShadowDistSQLStatementVisitor::getText).collect(Collectors.toSet())); + : ctx.algorithmName().stream().map(each -> getIdentifierValue(each)).collect(Collectors.toSet())); } @Override public ASTNode visitShowShadowRules(final ShowShadowRulesContext ctx) { - String ruleName = null == ctx.shadowRule() ? null : getText(ctx.shadowRule().ruleName()); + String ruleName = null == ctx.shadowRule() ? null : getIdentifierValue(ctx.shadowRule().ruleName()); SchemaSegment schemaSegment = null == ctx.schemaName() ? null : (SchemaSegment) visit(ctx.schemaName()); return new ShowShadowRulesStatement(ruleName, null == ctx.schemaName() ? null : schemaSegment); } @@ -127,7 +128,7 @@ public ASTNode visitShowShadowTableRules(final ShowShadowTableRulesContext ctx) return new ShowShadowTableRulesStatement(null != ctx.schemaName() ? (SchemaSegment) visit(ctx.schemaName()) : null); } - private static String getText(final ParserRuleContext ctx) { + private String getIdentifierValue(final ParserRuleContext ctx) { if (null == ctx || ctx.isEmpty()) { return null; } diff --git a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-parser/src/main/java/org/apache/shardingsphere/sharding/distsql/parser/core/ShardingDistSQLStatementVisitor.java b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-parser/src/main/java/org/apache/shardingsphere/sharding/distsql/parser/core/ShardingDistSQLStatementVisitor.java index 6b7cd265a6703..74474c48c7509 100644 --- a/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-parser/src/main/java/org/apache/shardingsphere/sharding/distsql/parser/core/ShardingDistSQLStatementVisitor.java +++ b/shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-distsql/shardingsphere-sharding-distsql-parser/src/main/java/org/apache/shardingsphere/sharding/distsql/parser/core/ShardingDistSQLStatementVisitor.java @@ -101,7 +101,7 @@ public ASTNode visitCreateShardingBindingTableRules(final CreateShardingBindingT @Override public ASTNode visitCreateShardingBroadcastTableRules(final CreateShardingBroadcastTableRulesContext ctx) { - return new CreateShardingBroadcastTableRulesStatement(ctx.tableName().stream().map(ParseTree::getText).collect(Collectors.toList())); + return new CreateShardingBroadcastTableRulesStatement(ctx.tableName().stream().map(each -> getIdentifierValue(each)).collect(Collectors.toList())); } @Override @@ -125,7 +125,7 @@ public ASTNode visitAlterShardingBindingTableRules(final AlterShardingBindingTab @Override public ASTNode visitAlterShardingBroadcastTableRules(final AlterShardingBroadcastTableRulesContext ctx) { - return new AlterShardingBroadcastTableRulesStatement(ctx.tableName().stream().map(ParseTree::getText).collect(Collectors.toList())); + return new AlterShardingBroadcastTableRulesStatement(ctx.tableName().stream().map(each -> getIdentifierValue(each)).collect(Collectors.toList())); } @Override @@ -140,17 +140,17 @@ public ASTNode visitDropShardingBindingTableRules(final DropShardingBindingTable @Override public ASTNode visitSetShardingHintDatabaseValue(final SetShardingHintDatabaseValueContext ctx) { - return new SetShardingHintDatabaseValueStatement(new IdentifierValue(ctx.shardingValue().getText()).getValue()); + return new SetShardingHintDatabaseValueStatement(getIdentifierValue(ctx.shardingValue())); } @Override public ASTNode visitAddShardingHintDatabaseValue(final AddShardingHintDatabaseValueContext ctx) { - return new AddShardingHintDatabaseValueStatement(ctx.tableName().getText(), new IdentifierValue(ctx.shardingValue().getText()).getValue()); + return new AddShardingHintDatabaseValueStatement(getIdentifierValue(ctx.tableName()), getIdentifierValue(ctx.shardingValue())); } @Override public ASTNode visitAddShardingHintTableValue(final AddShardingHintTableValueContext ctx) { - return new AddShardingHintTableValueStatement(ctx.tableName().getText(), new IdentifierValue(ctx.shardingValue().getText()).getValue()); + return new AddShardingHintTableValueStatement(getIdentifierValue(ctx.tableName()), getIdentifierValue(ctx.shardingValue())); } @Override @@ -170,12 +170,13 @@ public ASTNode visitDropShardingBroadcastTableRules(final DropShardingBroadcastT @Override public ASTNode visitDropShardingAlgorithm(final DropShardingAlgorithmContext ctx) { - return new DropShardingAlgorithmStatement(ctx.algorithmName().stream().map(each -> each.getText()).collect(Collectors.toList())); + return new DropShardingAlgorithmStatement(ctx.algorithmName().stream().map(each -> getIdentifierValue(each)).collect(Collectors.toList())); } @Override public ASTNode visitShowShardingTableRules(final ShowShardingTableRulesContext ctx) { - return new ShowShardingTableRulesStatement(null == ctx.tableRule() ? null : ctx.tableRule().tableName().getText(), null == ctx.schemaName() ? null : (SchemaSegment) visit(ctx.schemaName())); + return new ShowShardingTableRulesStatement(null == ctx.tableRule() ? null : getIdentifierValue(ctx.tableRule().tableName()), + null == ctx.schemaName() ? null : (SchemaSegment) visit(ctx.schemaName())); } @Override @@ -189,25 +190,32 @@ public ASTNode visitShardingTableRuleDefinition(final ShardingTableRuleDefinitio String tableStrategyColumn = null; AlgorithmSegment tableStrategy = null; if (null != ctx.algorithmDefinition()) { - tableStrategyColumn = ctx.shardingColumn().columnName().getText(); + tableStrategyColumn = getIdentifierValue(ctx.shardingColumn().columnName()); tableStrategy = (AlgorithmSegment) visit(ctx.algorithmDefinition()); } String keyGenerateStrategyColumn = null; AlgorithmSegment keyGenerateStrategy = null; if (null != ctx.keyGenerateStrategy()) { - keyGenerateStrategyColumn = ctx.keyGenerateStrategy().columnName().getText(); + keyGenerateStrategyColumn = getIdentifierValue(ctx.keyGenerateStrategy().columnName()); keyGenerateStrategy = (AlgorithmSegment) visit(ctx.keyGenerateStrategy().algorithmDefinition()); } - return new TableRuleSegment(ctx.tableName().getText(), dataSources, tableStrategyColumn, tableStrategy, keyGenerateStrategyColumn, keyGenerateStrategy); + return new TableRuleSegment(getIdentifierValue(ctx.tableName()), dataSources, tableStrategyColumn, tableStrategy, keyGenerateStrategyColumn, keyGenerateStrategy); } private Collection getResources(final ResourcesContext ctx) { - return ctx.resource().stream().map(each -> new IdentifierValue(each.getText()).getValue()).collect(Collectors.toSet()); + return ctx.resource().stream().map(each -> getIdentifierValue(each)).collect(Collectors.toSet()); } @Override public ASTNode visitAlgorithmDefinition(final AlgorithmDefinitionContext ctx) { - return new AlgorithmSegment(ctx.algorithmName().getText(), getAlgorithmProperties(ctx)); + return new AlgorithmSegment(getIdentifierValue(ctx.algorithmName()), getAlgorithmProperties(ctx)); + } + + private String getIdentifierValue(final ParseTree context) { + if (null == context) { + return null; + } + return new IdentifierValue(context.getText()).getValue(); } private Properties getAlgorithmProperties(final AlgorithmDefinitionContext ctx) { diff --git a/shardingsphere-test/shardingsphere-parser-test/src/main/resources/case/rdl/create.xml b/shardingsphere-test/shardingsphere-parser-test/src/main/resources/case/rdl/create.xml index 9ff65a7d69cc6..f3cd8fd6ea601 100644 --- a/shardingsphere-test/shardingsphere-parser-test/src/main/resources/case/rdl/create.xml +++ b/shardingsphere-test/shardingsphere-parser-test/src/main/resources/case/rdl/create.xml @@ -29,6 +29,10 @@ + + + + @@ -80,6 +84,23 @@ + + + ms_group_0 + ms_group_1 + + + + + + + + + + + + + ms_group_${0..1} @@ -100,11 +121,21 @@ + + + + + t_1
t_2
+ + + t_1
+ t_2
+
@@ -112,6 +143,13 @@ replica_ds_1 + + + + replica_ds_0 + replica_ds_1 + + @@ -139,6 +177,25 @@ + + + + resource0 + resource1 + + + + + + + resource2 + resource3 + + + + + + @@ -155,7 +212,22 @@ - + + + + + + + + + + + + + + + + @@ -192,4 +264,29 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/shardingsphere-test/shardingsphere-parser-test/src/main/resources/sql/supported/rdl/create.xml b/shardingsphere-test/shardingsphere-parser-test/src/main/resources/sql/supported/rdl/create.xml index eafa5296ac07c..c62e0d9efc2a8 100644 --- a/shardingsphere-test/shardingsphere-parser-test/src/main/resources/sql/supported/rdl/create.xml +++ b/shardingsphere-test/shardingsphere-parser-test/src/main/resources/sql/supported/rdl/create.xml @@ -34,6 +34,15 @@ - + + + + + + + + + +