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

[shardingsphere] branch master updated: Optimize shadow-DistSQL (#22482)

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

jianglongtao 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 9f4df210d74 Optimize shadow-DistSQL (#22482)
9f4df210d74 is described below

commit 9f4df210d7400232047661161a804cbfb6d07742
Author: Zichao <57...@users.noreply.github.com>
AuthorDate: Mon Nov 28 22:01:34 2022 +1300

    Optimize shadow-DistSQL (#22482)
---
 .../parser/src/main/antlr4/imports/shadow/BaseRule.g4       |  8 +++++++-
 .../parser/src/main/antlr4/imports/shadow/Keyword.g4        | 12 ++++++++++++
 test/parser/src/main/resources/case/rdl/create.xml          | 13 +++++++++++++
 test/parser/src/main/resources/sql/supported/rdl/create.xml |  1 +
 4 files changed, 33 insertions(+), 1 deletion(-)

diff --git a/features/shadow/distsql/parser/src/main/antlr4/imports/shadow/BaseRule.g4 b/features/shadow/distsql/parser/src/main/antlr4/imports/shadow/BaseRule.g4
index 349780d722d..951243e7a5e 100644
--- a/features/shadow/distsql/parser/src/main/antlr4/imports/shadow/BaseRule.g4
+++ b/features/shadow/distsql/parser/src/main/antlr4/imports/shadow/BaseRule.g4
@@ -28,7 +28,13 @@ algorithmDefinition
     ;
 
 algorithmTypeName
-    : STRING
+    : STRING | buildInAlgorithmTypeName
+    ;
+
+buildInAlgorithmTypeName
+    : VALUE_MATCH
+    | REGEX_MATCH
+    | SIMPLE_HINT
     ;
 
 propertiesDefinition
diff --git a/features/shadow/distsql/parser/src/main/antlr4/imports/shadow/Keyword.g4 b/features/shadow/distsql/parser/src/main/antlr4/imports/shadow/Keyword.g4
index eecd5e3544a..8a6852a05ee 100644
--- a/features/shadow/distsql/parser/src/main/antlr4/imports/shadow/Keyword.g4
+++ b/features/shadow/distsql/parser/src/main/antlr4/imports/shadow/Keyword.g4
@@ -134,3 +134,15 @@ EXISTS
 COUNT
     : C O U N T
     ;
+
+VALUE_MATCH
+    : V A L U E UL_ M A T C H
+    ;
+
+REGEX_MATCH
+    : R E G E X UL_ M A T C H
+    ;
+
+SIMPLE_HINT
+    : S I M P L E UL_ H I N T
+    ;
diff --git a/test/parser/src/main/resources/case/rdl/create.xml b/test/parser/src/main/resources/case/rdl/create.xml
index ab0175f6f13..9ca5c891b36 100644
--- a/test/parser/src/main/resources/case/rdl/create.xml
+++ b/test/parser/src/main/resources/case/rdl/create.xml
@@ -521,4 +521,17 @@
             <property key="keep-alive-cron" value="0/5 * * * * ?" />
         </rule>
     </create-database-discovery-definition-rule>
+
+    <create-shadow-rule sql-case-id="create-shadow-rule-without-quote-on-build-in-shadow-algorithm-name">
+        <rule rule-name="shadow_rule" source="demo_ds" shadow="demo_ds_shadow">
+            <table-rule table-name="t_order">
+                <shadow-algorithm algorithm-id="shadow_rule_t_order_simple_hint_0">
+                    <algorithm algorithm-name="SIMPLE_HINT">
+                        <property key="shadow" value="true" />
+                        <property key="foo" value="bar" />
+                    </algorithm>
+                </shadow-algorithm>
+            </table-rule>
+        </rule>
+    </create-shadow-rule>
 </sql-parser-test-cases>
diff --git a/test/parser/src/main/resources/sql/supported/rdl/create.xml b/test/parser/src/main/resources/sql/supported/rdl/create.xml
index 5f8a461a56f..ff1a44fa530 100644
--- a/test/parser/src/main/resources/sql/supported/rdl/create.xml
+++ b/test/parser/src/main/resources/sql/supported/rdl/create.xml
@@ -64,4 +64,5 @@
     <sql-case id="create-encrypt-rule-without-quote-on-build-in-algorithm-type-name" value="CREATE ENCRYPT RULE t_encrypt (COLUMNS((NAME=user_id,PLAIN=user_plain,CIPHER=user_cipher,TYPE(NAME=AES,PROPERTIES('aes-key-value'='123456abc'))), (NAME=order_id, CIPHER =order_cipher,TYPE(NAME=MD5))),QUERY_WITH_CIPHER_COLUMN=true);" db-types="ShardingSphere" />
     <sql-case id="create-readwrite-splitting-rule-without-quote-on-build-in-algorithm-type-name" value="CREATE READWRITE_SPLITTING RULE ms_group_0 (WRITE_STORAGE_UNIT=write_ds, READ_STORAGE_UNITS(read_ds_0,read_ds_1), TYPE(NAME=RANDOM));" db-types="ShardingSphere" />
     <sql-case id="create-db-discovery-rule-without-quote-on-build-in-db-discovery-type-name" value="CREATE DB_DISCOVERY RULE db_discovery_group_0 (STORAGE_UNITS(ds_0, ds_1), TYPE(NAME=MYSQL.MGR,PROPERTIES('group-name'='92504d5b-6dec')),HEARTBEAT(PROPERTIES('keep-alive-cron'='0/5 * * * * ?')));" db-types="ShardingSphere" />
+    <sql-case id="create-shadow-rule-without-quote-on-build-in-shadow-algorithm-name" value="CREATE SHADOW RULE shadow_rule(SOURCE=demo_ds, SHADOW=demo_ds_shadow, t_order(TYPE(NAME=SIMPLE_HINT, PROPERTIES('shadow'='true', 'foo'='bar'))));" db-types="ShardingSphere" />
 </sql-cases>