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 9074c559f45 Enhance user variable lexical rules (#26889)
9074c559f45 is described below

commit 9074c559f455193b3f13e88ea5ec00e048129f23
Author: niu niu <[email protected]>
AuthorDate: Fri Jul 14 08:52:03 2023 +0800

    Enhance user variable lexical rules (#26889)
    
    * Add user variable test
    
    * Add AES_DECRYPT AES_ENCRYPT function test
    
    * Format xml
---
 .../src/main/antlr4/imports/mysql/BaseRule.g4      |  2 +
 .../parser/src/main/resources/case/dml/select.xml  | 59 ++++++++++++++++++++++
 .../main/resources/sql/supported/dml/select.xml    |  2 +
 3 files changed, 63 insertions(+)

diff --git a/parser/sql/dialect/mysql/src/main/antlr4/imports/mysql/BaseRule.g4 
b/parser/sql/dialect/mysql/src/main/antlr4/imports/mysql/BaseRule.g4
index a0984357c00..80aeac479ea 100644
--- a/parser/sql/dialect/mysql/src/main/antlr4/imports/mysql/BaseRule.g4
+++ b/parser/sql/dialect/mysql/src/main/antlr4/imports/mysql/BaseRule.g4
@@ -147,6 +147,7 @@ identifierKeywordsUnambiguous
     | AVG_ROW_LENGTH
     | AVG
     | BACKUP
+    | BEFORE
     | BINLOG
     | BIT
     | BLOCK
@@ -266,6 +267,7 @@ identifierKeywordsUnambiguous
     | JSON
     | JSON_VALUE
     | KEY
+    | KEYS
     | KEY_BLOCK_SIZE
     | LAST
     | LEAVES
diff --git a/test/it/parser/src/main/resources/case/dml/select.xml 
b/test/it/parser/src/main/resources/case/dml/select.xml
index d76f2710697..ad684eaf3ee 100644
--- a/test/it/parser/src/main/resources/case/dml/select.xml
+++ b/test/it/parser/src/main/resources/case/dml/select.xml
@@ -111,6 +111,65 @@
         </projections>
     </select>
 
+    <select sql-case-id="select_function_aes_decrypt_and_aes_encrypt">
+        <from>
+            <simple-table name="t1" start-index="78" stop-index="79" />
+        </from>
+        <projections start-index="7" stop-index="71">
+            <expression-projection text="AES_DECRYPT(AES_ENCRYPT(@ENCSTR, 
@keys, @Iv), @keys, @Iv)=@ENCSTR" start-index="7" stop-index="71">
+                <expr>
+                    <binary-operation-expression 
text="AES_DECRYPT(AES_ENCRYPT(@ENCSTR, @keys, @Iv), @keys, @Iv)=@ENCSTR" 
start-index="7" stop-index="71">
+                        <left>
+                            <function start-index="7" stop-index="63" 
text="AES_DECRYPT(AES_ENCRYPT(@ENCSTR, @keys, @Iv), @keys, @Iv)" 
function-name="AES_DECRYPT">
+                                <parameter>
+                                    <function start-index="19" stop-index="50" 
text="AES_ENCRYPT(@ENCSTR, @keys, @Iv)" function-name="AES_ENCRYPT">
+                                        <parameter>
+                                            <variable-segment start-index="31" 
stop-index="37" variable="ENCSTR" />
+                                        </parameter>
+                                        <parameter>
+                                            <variable-segment start-index="40" 
stop-index="44" variable="keys" />
+                                        </parameter>
+                                        <parameter>
+                                            <variable-segment start-index="47" 
stop-index="49" variable="Iv" />
+                                        </parameter>
+                                    </function>
+                                </parameter>
+                                <parameter>
+                                    <variable-segment start-index="53" 
stop-index="57" variable="keys" />
+                                </parameter>
+                                <parameter>
+                                    <variable-segment start-index="60" 
stop-index="62" variable="Iv" />
+                                </parameter>
+                            </function>
+                        </left>
+                        <operator>=</operator>
+                        <right>
+                            <variable-segment start-index="65" stop-index="71" 
variable="ENCSTR" />
+                        </right>
+                    </binary-operation-expression>
+                </expr>
+            </expression-projection>
+        </projections>
+    </select>
+
+    <select sql-case-id="select_user_variable_before_after">
+        <projections start-index="7" stop-index="20">
+            <expression-projection text="@before=@after" start-index="7" 
stop-index="20">
+                <expr>
+                    <binary-operation-expression start-index="7" 
stop-index="20">
+                        <left>
+                            <variable-segment start-index="7" stop-index="13" 
variable="before" />
+                        </left>
+                        <operator>=</operator>
+                        <right>
+                            <variable-segment start-index="15" stop-index="20" 
variable="after" />
+                        </right>
+                    </binary-operation-expression>
+                </expr>
+            </expression-projection>
+        </projections>
+    </select>
+    
     <select sql-case-id="select_with_exist_in">
         <projections start-index="7" stop-index="93">
             <expression-projection text="+0 
IN(0b111111111111111111111111111111111111111111111111111,rpad(1.0,2048,1),32767.1)"
 start-index="7" stop-index="93">
diff --git a/test/it/parser/src/main/resources/sql/supported/dml/select.xml 
b/test/it/parser/src/main/resources/sql/supported/dml/select.xml
index c61a112481e..edc573f2865 100644
--- a/test/it/parser/src/main/resources/sql/supported/dml/select.xml
+++ b/test/it/parser/src/main/resources/sql/supported/dml/select.xml
@@ -23,6 +23,8 @@
     <sql-case id="select_convert_function2" value="SELECT CONVERT(TIMESTAMP 
&quot;2004-01-22 21:45:33&quot;, BINARY(4))" db-types="MySQL" />
     <sql-case id="select_convert_function3" value="SELECT CONVERT(TIMESTAMP 
&quot;2004-01-22 21:45:33&quot;, CHAR(4))" db-types="MySQL" />
     <sql-case id="select_convert_function4" value="SELECT CONVERT(TIMESTAMP 
&quot;2004-01-22 21:45:33&quot;, CHAR)" db-types="MySQL" />
+    <sql-case id="select_function_aes_decrypt_and_aes_encrypt" value="SELECT 
AES_DECRYPT(AES_ENCRYPT(@ENCSTR, @keys, @Iv), @keys, @Iv)=@ENCSTR FROM t1" 
db-types="MySQL" />
+    <sql-case id="select_user_variable_before_after" value="SELECT 
@before=@after" db-types="MySQL" />
     <sql-case id="select_with_exist_in" value="SELECT (+0 
IN(0b111111111111111111111111111111111111111111111111111,rpad(1.0,2048,1),32767.1))"
 db-types="MySQL" />
     <sql-case id="select_constant_without_table" value="SELECT 1 as a" 
db-types="MySQL, PostgreSQL,openGauss, SQLServer" />
     <sql-case id="select_with_operator_ilike" value="SELECT id from t_order 
where name !~ '^pg_toast'" db-types="PostgreSQL,openGauss" />

Reply via email to