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

zhangliang 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 01da2ae44a4 Parsing scope of variable prefixed with @@ in MySQL SET 
statement (#18771)
01da2ae44a4 is described below

commit 01da2ae44a409200010d93e141a035c6040f8d0e
Author: 吴伟杰 <[email protected]>
AuthorDate: Sat Jul 2 13:00:55 2022 +0800

    Parsing scope of variable prefixed with @@ in MySQL SET statement (#18771)
    
    * Parsing scope of variable prefixed with @@ in MySQL SET statement
    
    * Add test cases for MySQL SET statement
    
    * Make default scope to upper case
---
 .../statement/impl/MySQLDALStatementSQLVisitor.java       |  7 +++++--
 .../src/main/resources/case/dal/set.xml                   | 15 +++++++++++++++
 .../src/main/resources/sql/supported/dal/set.xml          |  3 +++
 3 files changed, 23 insertions(+), 2 deletions(-)

diff --git 
a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-mysql/src/main/java/org/apache/shardingsphere/sql/parser/mysql/visitor/statement/impl/MySQLDALStatementSQLVisitor.java
 
b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-mysql/src/main/java/org/apache/shardingsphere/sql/parser/mysql/visitor/statement/impl/MySQLDALStatementSQLVisitor.java
index 861064bf608..63185b4cc38 100644
--- 
a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-mysql/src/main/java/org/apache/shardingsphere/sql/parser/mysql/visitor/statement/impl/MySQLDALStatementSQLVisitor.java
+++ 
b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-mysql/src/main/java/org/apache/shardingsphere/sql/parser/mysql/visitor/statement/impl/MySQLDALStatementSQLVisitor.java
@@ -21,7 +21,6 @@ import lombok.NoArgsConstructor;
 import org.apache.shardingsphere.sql.parser.api.visitor.ASTNode;
 import 
org.apache.shardingsphere.sql.parser.api.visitor.operation.SQLStatementVisitor;
 import org.apache.shardingsphere.sql.parser.api.visitor.type.DALSQLVisitor;
-import 
org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.ShowProfilesContext;
 import 
org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.AlterResourceGroupContext;
 import 
org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.AnalyzeTableContext;
 import 
org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.BinaryLogFileIndexNumberContext;
@@ -52,6 +51,7 @@ import 
org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.KillCon
 import 
org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.LoadIndexInfoContext;
 import 
org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.LoadTableIndexListContext;
 import 
org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.OptimizeTableContext;
+import 
org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.OptionTypeContext;
 import 
org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.OptionValueContext;
 import 
org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.OptionValueListContext;
 import 
org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.OptionValueNoOptionTypeContext;
@@ -98,6 +98,7 @@ import 
org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.ShowPro
 import 
org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.ShowProcedureStatusContext;
 import 
org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.ShowProcesslistContext;
 import 
org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.ShowProfileContext;
+import 
org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.ShowProfilesContext;
 import 
org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.ShowRelaylogEventContext;
 import 
org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.ShowReplicaStatusContext;
 import 
org.apache.shardingsphere.sql.parser.autogen.MySQLStatementParser.ShowReplicasContext;
@@ -955,9 +956,11 @@ public final class MySQLDALStatementSQLVisitor extends 
MySQLStatementSQLVisitor
             result.setVariable(variable);
             result.setAssignValue(ctx.expr().getText());
         } else if (null != ctx.setSystemVariable()) {
-            variable.setVariable(ctx.setSystemVariable().getText());
+            
variable.setVariable(ctx.setSystemVariable().internalVariableName().getText());
             result.setVariable(variable);
             result.setAssignValue(ctx.setExprOrDefault().getText());
+            OptionTypeContext optionType = 
ctx.setSystemVariable().optionType();
+            variable.setScope(null != optionType ? optionType.getText() : 
"SESSION");
         }
         return result;
     }
diff --git 
a/shardingsphere-test/shardingsphere-parser-test/src/main/resources/case/dal/set.xml
 
b/shardingsphere-test/shardingsphere-parser-test/src/main/resources/case/dal/set.xml
index 98ce443a24f..bb8b242dd5f 100644
--- 
a/shardingsphere-test/shardingsphere-parser-test/src/main/resources/case/dal/set.xml
+++ 
b/shardingsphere-test/shardingsphere-parser-test/src/main/resources/case/dal/set.xml
@@ -32,6 +32,21 @@
             <parameter name="configuration_parameter" scope="SESSION" />
         </parameter-assign>
     </set-parameter>
+    <set-parameter sql-case-id="set_parameter_equal_at_at_session_mysql">
+        <parameter-assign value="'value'">
+            <parameter name="configuration_parameter" scope="SESSION" />
+        </parameter-assign>
+    </set-parameter>
+    <set-parameter sql-case-id="set_parameter_equal_at_at_without_scope_mysql">
+        <parameter-assign value="'value'">
+            <parameter name="configuration_parameter" scope="SESSION" />
+        </parameter-assign>
+    </set-parameter>
+    <set-parameter sql-case-id="set_parameter_equal_at_at_global_mysql">
+        <parameter-assign value="'value'">
+            <parameter name="configuration_parameter" scope="GLOBAL" />
+        </parameter-assign>
+    </set-parameter>
     <set-parameter sql-case-id="set_parameter_to">
         <parameter-assign value="'value'">
             <parameter name="configuration_parameter" />
diff --git 
a/shardingsphere-test/shardingsphere-parser-test/src/main/resources/sql/supported/dal/set.xml
 
b/shardingsphere-test/shardingsphere-parser-test/src/main/resources/sql/supported/dal/set.xml
index ff2007ba856..c3ac53b3aba 100644
--- 
a/shardingsphere-test/shardingsphere-parser-test/src/main/resources/sql/supported/dal/set.xml
+++ 
b/shardingsphere-test/shardingsphere-parser-test/src/main/resources/sql/supported/dal/set.xml
@@ -20,6 +20,9 @@
     <sql-case id="set_parameter_equal" value="SET configuration_parameter = 
'value'" db-types="PostgreSQL,openGauss, MySQL" />
     <sql-case id="set_parameter_equal_number" value="SET extra_float_digits = 
3" db-types="PostgreSQL,openGauss, MySQL" />
     <sql-case id="set_parameter_equal_session_mysql" value="SET SESSION 
configuration_parameter = 'value'" db-types="MySQL" />
+    <sql-case id="set_parameter_equal_at_at_session_mysql" value="SET 
@@SESSION.configuration_parameter = 'value'" db-types="MySQL" />
+    <sql-case id="set_parameter_equal_at_at_without_scope_mysql" value="SET 
@@configuration_parameter = 'value'" db-types="MySQL" />
+    <sql-case id="set_parameter_equal_at_at_global_mysql" value="SET 
@@GLOBAL.configuration_parameter = 'value'" db-types="MySQL" />
     <sql-case id="set_parameter_to" value="SET configuration_parameter TO 
'value'" db-types="PostgreSQL,openGauss" />
     <sql-case id="set_parameter_for_session_scope" value="SET SESSION 
configuration_parameter TO 'value'" db-types="PostgreSQL,openGauss" />
     <sql-case id="set_parameter_for_local_scope" value="SET LOCAL 
configuration_parameter TO 'value'" db-types="PostgreSQL,openGauss" />

Reply via email to