terrymanu commented on a change in pull request #8713:
URL: https://github.com/apache/shardingsphere/pull/8713#discussion_r547914172
##########
File path:
shardingsphere-distsql-parser/shardingsphere-distsql-parser-engine/src/main/java/org/apache/shardingsphere/distsql/parser/core/DistSQLVisitor.java
##########
@@ -86,29 +91,57 @@ public ASTNode visitCreateShardingRule(final
CreateShardingRuleContext ctx) {
}
return new CreateShardingRuleStatement(tables);
}
-
+
+ @Override
+ public ASTNode visitCreateReplicaQueryRule(final
CreateReplicaQueryRuleContext ctx) {
+ Collection<ReplicaQueryRuleSegment> replicaQueryRules = new
LinkedList<>();
+ for (ReplicaQueryRuleDefinitionContext each :
ctx.replicaQueryRuleDefinition()) {
+ replicaQueryRules.add((ReplicaQueryRuleSegment) visit(each));
+ }
+ return new CreateReplicaQueryRuleStatement(replicaQueryRules);
+ }
+
+ @Override
+ public ASTNode visitReplicaQueryRuleDefinition(final
ReplicaQueryRuleDefinitionContext ctx) {
+ ReplicaQueryRuleSegment result = new ReplicaQueryRuleSegment();
+ Collection<String> replicaDatasources = new LinkedList<>();
+ for (SchemaNameContext each : ctx.schemaNames().schemaName()) {
+ replicaDatasources.add(each.getText());
+ }
+ Properties props = new Properties();
+ for (AlgorithmPropertyContext each :
ctx.algorithmProperties().algorithmProperty()) {
+ props.setProperty(each.key.getText(), each.value.getText());
+ }
+ result.setName(ctx.ruleName.getText());
+ result.setPrimaryDatasource(ctx.primary.getText());
+ result.setReplicaDatasources(replicaDatasources);
+ result.setLoadBalancer(ctx.loadBalancer.getText());
+ result.setProps(props);
+ return result;
+ }
+
@Override
public ASTNode visitShardingTableRuleDefinition(final
ShardingTableRuleDefinitionContext ctx) {
TableRuleSegment result = new TableRuleSegment();
result.setLogicTable(ctx.tableName().getText());
- result.setShardingColumn(ctx.columName().getText());
-
result.setAlgorithmType(ctx.shardingAlgorithmDefinition().shardingAlgorithmType().getText());
+ result.setShardingColumn(ctx.columnName().getText());
+ result.setAlgorithmType(ctx.shardingAlgorithmType.getText());
// TODO Future feature.
result.setDataSources(new LinkedList<>());
- PropertiesValue propertiesValue = (PropertiesValue)
visit(ctx.shardingAlgorithmDefinition().shardingAlgorithmProperties());
+ PropertiesValue propertiesValue = (PropertiesValue)
visit(ctx.algorithmProperties());
result.setAlgorithmProps(propertiesValue.getValue());
return result;
}
@Override
- public ASTNode visitShardingAlgorithmProperties(final
ShardingAlgorithmPropertiesContext ctx) {
+ public ASTNode visitAlgorithmProperties(final AlgorithmPropertiesContext
ctx) {
PropertiesValue result = new PropertiesValue();
- for (ShardingAlgorithmPropertyContext each :
ctx.shardingAlgorithmProperty()) {
-
result.getValue().setProperty(each.shardingAlgorithmPropertyKey().getText(),
each.shardingAlgorithmPropertyValue().getText());
+ for (AlgorithmPropertyContext each : ctx.algorithmProperty()) {
+ result.getValue().setProperty(each.key.getText(),
each.value.getText());
}
return result;
}
-
+
Review comment:
Please keep the original indent
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]