You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by pa...@apache.org on 2021/01/28 11:23:23 UTC

[shardingsphere] branch master updated: fix RDL function parse (#9205)

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

panjuan 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 479449a  fix RDL function parse (#9205)
479449a is described below

commit 479449a301ad9f43927e17cb2393dd4141aa9ef8
Author: JingShang Lu <lu...@apache.org>
AuthorDate: Thu Jan 28 19:23:01 2021 +0800

    fix RDL function parse (#9205)
---
 .../src/main/antlr4/imports/RDLStatement.g4            |  2 +-
 .../distsql/parser/core/DistSQLVisitor.java            | 18 ++++++++++++------
 2 files changed, 13 insertions(+), 7 deletions(-)

diff --git a/shardingsphere-distsql-parser/shardingsphere-distsql-parser-engine/src/main/antlr4/imports/RDLStatement.g4 b/shardingsphere-distsql-parser/shardingsphere-distsql-parser-engine/src/main/antlr4/imports/RDLStatement.g4
index 71e1176..03ed091 100644
--- a/shardingsphere-distsql-parser/shardingsphere-distsql-parser-engine/src/main/antlr4/imports/RDLStatement.g4
+++ b/shardingsphere-distsql-parser/shardingsphere-distsql-parser-engine/src/main/antlr4/imports/RDLStatement.g4
@@ -152,7 +152,7 @@ schemaName
     ;
 
 functionDefinition
-    : functionName=IDENTIFIER LP algorithmProperties RP
+    : functionName=IDENTIFIER LP algorithmProperties? RP
     ;
 
 algorithmProperties
diff --git a/shardingsphere-distsql-parser/shardingsphere-distsql-parser-engine/src/main/java/org/apache/shardingsphere/distsql/parser/core/DistSQLVisitor.java b/shardingsphere-distsql-parser/shardingsphere-distsql-parser-engine/src/main/java/org/apache/shardingsphere/distsql/parser/core/DistSQLVisitor.java
index 483719e..4ce04b5 100644
--- a/shardingsphere-distsql-parser/shardingsphere-distsql-parser-engine/src/main/java/org/apache/shardingsphere/distsql/parser/core/DistSQLVisitor.java
+++ b/shardingsphere-distsql-parser/shardingsphere-distsql-parser-engine/src/main/java/org/apache/shardingsphere/distsql/parser/core/DistSQLVisitor.java
@@ -180,8 +180,10 @@ public final class DistSQLVisitor extends DistSQLStatementBaseVisitor<ASTNode> {
             replicaDatasources.add(each.getText());
         }
         Properties props = new Properties();
-        for (AlgorithmPropertyContext each : ctx.functionDefinition().algorithmProperties().algorithmProperty()) {
-            props.setProperty(each.key.getText(), each.value.getText());
+        if (null != ctx.functionDefinition().algorithmProperties()) {
+            for (AlgorithmPropertyContext each : ctx.functionDefinition().algorithmProperties().algorithmProperty()) {
+                props.setProperty(each.key.getText(), each.value.getText());
+            }
         }
         result.setName(ctx.ruleName.getText());
         result.setPrimaryDataSource(ctx.primary.getText());
@@ -226,8 +228,10 @@ public final class DistSQLVisitor extends DistSQLStatementBaseVisitor<ASTNode> {
         result.setReplicaDataSources(replicaDatasources);
         if (null != ctx.functionDefinition()) {
             Properties props = new Properties();
-            for (AlgorithmPropertyContext each : ctx.functionDefinition().algorithmProperties().algorithmProperty()) {
-                props.setProperty(each.key.getText(), each.value.getText());
+            if (null != ctx.functionDefinition().algorithmProperties()) {
+                for (AlgorithmPropertyContext each : ctx.functionDefinition().algorithmProperties().algorithmProperty()) {
+                    props.setProperty(each.key.getText(), each.value.getText());
+                }
             }
             result.setLoadBalancer(ctx.functionDefinition().functionName.getText());
             result.setProps(props);
@@ -262,8 +266,10 @@ public final class DistSQLVisitor extends DistSQLStatementBaseVisitor<ASTNode> {
         FunctionSegment result = new FunctionSegment();
         result.setAlgorithmName(ctx.functionName.getText());
         Properties algorithmProps = new Properties();
-        for (AlgorithmPropertyContext each : ctx.algorithmProperties().algorithmProperty()) {
-            algorithmProps.setProperty(new IdentifierValue(each.key.getText()).getValue(), new IdentifierValue(each.value.getText()).getValue());
+        if (null != ctx.algorithmProperties()) {
+            for (AlgorithmPropertyContext each : ctx.algorithmProperties().algorithmProperty()) {
+                algorithmProps.setProperty(new IdentifierValue(each.key.getText()).getValue(), new IdentifierValue(each.value.getText()).getValue());
+            }
         }
         result.setAlgorithmProps(algorithmProps);
         return result;