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

[shardingsphere] branch master updated: add rewrite test for view (#18113)

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 a325e996720 add rewrite test for view (#18113)
a325e996720 is described below

commit a325e99672051f3650056f2fb403156fd68cdadd
Author: Chuxin Chen <ch...@qq.com>
AuthorDate: Wed Jun 1 14:12:03 2022 +0800

    add rewrite test for view (#18113)
---
 .../src/test/resources/scenario/sharding/case/alter.xml      |  5 +++++
 .../src/test/resources/scenario/sharding/case/create.xml     |  5 +++++
 .../src/test/resources/scenario/sharding/case/drop.xml       |  5 +++++
 .../src/test/resources/scenario/sharding/case/select.xml     |  5 +++++
 .../resources/scenario/sharding/config/sharding-rule.yaml    | 12 +++++++++++-
 5 files changed, 31 insertions(+), 1 deletion(-)

diff --git a/shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/sharding/case/alter.xml b/shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/sharding/case/alter.xml
index add94371ed5..8c85b289280 100644
--- a/shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/sharding/case/alter.xml
+++ b/shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/sharding/case/alter.xml
@@ -96,4 +96,9 @@
         <output sql="ALTER TABLE t_account_0 DROP CONSTRAINT t_account_fk_t_account_0 CASCADE" />
         <output sql="ALTER TABLE t_account_1 DROP CONSTRAINT t_account_fk_t_account_1 CASCADE" />
     </rewrite-assertion>
+    <rewrite-assertion id="alter_view_with_sharding_table" db-types="PostgreSQL,openGauss">
+        <input sql="ALTER VIEW t_account_view ALTER COLUMN status SET DEFAULT 'OK'" />
+        <output sql="ALTER VIEW t_account_view_0 ALTER COLUMN status SET DEFAULT 'OK'" />
+        <output sql="ALTER VIEW t_account_view_1 ALTER COLUMN status SET DEFAULT 'OK'" />
+    </rewrite-assertion>
 </rewrite-assertions>
diff --git a/shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/sharding/case/create.xml b/shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/sharding/case/create.xml
index 077bbf2d343..635adc101ba 100644
--- a/shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/sharding/case/create.xml
+++ b/shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/sharding/case/create.xml
@@ -82,4 +82,9 @@
         <output sql="CREATE TABLE t_account_detail_0 (order_id INT,account_id INT) WITH (FILLFACTOR = 80, ORIENTATION=ROW)" />
         <output sql="CREATE TABLE t_account_detail_1 (order_id INT,account_id INT) WITH (FILLFACTOR = 80, ORIENTATION=ROW)" />
     </rewrite-assertion>
+    <rewrite-assertion id="create_view_with_sharding_table" db-types="MySQL,PostgreSQL,openGauss">
+        <input sql="CREATE VIEW t_account_view AS SELECT account_id, amount FROM t_account WHERE status = 'OK'" />
+        <output sql="CREATE VIEW t_account_view_0 AS SELECT account_id, amount FROM t_account_0 WHERE status = 'OK'" />
+        <output sql="CREATE VIEW t_account_view_1 AS SELECT account_id, amount FROM t_account_1 WHERE status = 'OK'" />
+    </rewrite-assertion>
 </rewrite-assertions>
diff --git a/shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/sharding/case/drop.xml b/shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/sharding/case/drop.xml
index 5156b87f1cf..29c27a3f691 100644
--- a/shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/sharding/case/drop.xml
+++ b/shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/sharding/case/drop.xml
@@ -62,4 +62,9 @@
         <input sql="DROP TABLE IF EXISTS t_single, t_single_extend" />
         <output sql="DROP TABLE IF EXISTS t_single, t_single_extend" />
     </rewrite-assertion>
+    <rewrite-assertion id="drop_view_with_sharding_table" db-types="MySQL,PostgreSQL,openGauss">
+        <input sql="DROP VIEW t_account_view" />
+        <output sql="DROP VIEW t_account_view_0" />
+        <output sql="DROP VIEW t_account_view_1" />
+    </rewrite-assertion>
 </rewrite-assertions>
diff --git a/shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/sharding/case/select.xml b/shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/sharding/case/select.xml
index cca216ca31f..22af4a5479c 100644
--- a/shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/sharding/case/select.xml
+++ b/shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/sharding/case/select.xml
@@ -592,4 +592,9 @@
         <input sql="SELECT account_id FROM public.public.t_account WHERE account_id = ?" parameters="100" />
         <output sql="SELECT account_id FROM public.t_account_0 WHERE account_id = ?" parameters="100" />
     </rewrite-assertion>
+
+    <rewrite-assertion id="select_view_with_sharding">
+        <input sql="SELECT COUNT(*) FROM t_account_view WHERE account_id = 1" />
+        <output sql="SELECT COUNT(*) FROM t_account_view_1 WHERE account_id = 1" />
+    </rewrite-assertion>
 </rewrite-assertions>
diff --git a/shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/sharding/config/sharding-rule.yaml b/shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/sharding/config/sharding-rule.yaml
index 5ea9faaff9f..ec6d8deb34f 100644
--- a/shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/sharding/config/sharding-rule.yaml
+++ b/shardingsphere-test/shardingsphere-rewrite-test/src/test/resources/scenario/sharding/config/sharding-rule.yaml
@@ -59,8 +59,14 @@ rules:
       actualDataNodes: db.T_ROLE
     T_ROLE_ADMIN:
       actualDataNodes: db.T_ROLE_ADMIN
+    t_account_view:
+      actualDataNodes: db.t_account_view_${0..1}
+      tableStrategy:
+        standard:
+          shardingColumn: account_id
+          shardingAlgorithmName: t_account_view_inline
   bindingTables:
-    - t_account, t_account_detail
+    - t_account, t_account_detail, t_account_view
     - t_order, t_order_item
     - t_user, t_user_extend
     - T_ROLE, T_ROLE_ADMIN
@@ -84,6 +90,10 @@ rules:
       type: INLINE
       props:
         algorithm-expression: t_user_extend_${user_id % 2}
+    t_account_view_inline:
+      type: INLINE
+      props:
+        algorithm-expression: t_account_view_${account_id % 2}
   
   keyGenerators:
     rewrite_keygen_fixture: