From 1f9450e0f7f28c1f2e8fc9086efcaa67d6472629 Mon Sep 17 00:00:00 2001 From: Pxl Date: Mon, 24 Apr 2023 11:36:56 +0800 Subject: [PATCH] [Chore](case) add some regression-test case about materialized-view #18946 --- regression-test/certificate.p12 | Bin 0 -> 2613 bytes .../sum_divede_count/sum_devide_count.out | 29 +++++++ .../testBitmapUnionInQuery.out | 9 +++ .../testIncorrectRewriteCountDistinct.out | 10 +++ .../testOrderByQueryOnProjectView.out | 13 ++++ .../sum_divede_count/sum_devide_count.groovy | 73 ++++++++++++++++++ .../testBitmapUnionInQuery.groovy | 49 ++++++++++++ .../testIncorrectRewriteCountDistinct.groovy | 49 ++++++++++++ .../testOrderByQueryOnProjectView.groovy | 56 ++++++++++++++ 9 files changed, 288 insertions(+) create mode 100644 regression-test/certificate.p12 create mode 100644 regression-test/data/mv_p0/sum_divede_count/sum_devide_count.out create mode 100644 regression-test/data/mv_p0/ut/testBitmapUnionInQuery/testBitmapUnionInQuery.out create mode 100644 regression-test/data/mv_p0/ut/testIncorrectRewriteCountDistinct/testIncorrectRewriteCountDistinct.out create mode 100644 regression-test/data/mv_p0/ut/testOrderByQueryOnProjectView/testOrderByQueryOnProjectView.out create mode 100644 regression-test/suites/mv_p0/sum_divede_count/sum_devide_count.groovy create mode 100644 regression-test/suites/mv_p0/ut/testBitmapUnionInQuery/testBitmapUnionInQuery.groovy create mode 100644 regression-test/suites/mv_p0/ut/testIncorrectRewriteCountDistinct/testIncorrectRewriteCountDistinct.groovy create mode 100644 regression-test/suites/mv_p0/ut/testOrderByQueryOnProjectView/testOrderByQueryOnProjectView.groovy diff --git a/regression-test/certificate.p12 b/regression-test/certificate.p12 new file mode 100644 index 0000000000000000000000000000000000000000..3098460e8b3c7b533226f923d47ccbbed003e6a5 GIT binary patch literal 2613 zcmXqL;xc4nWHxBx{LaRy)#lOmotKfFaX}O33zjC%Ck9QN4-A@ErX!@-7BsPR7&Ni8 zFflS1G_lkoWEc%(*tno3@G!C&@Ud`kav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hVozhmV*_bO@b?_2cW zY{pcs+4Zk4Mk!a#W4GRDwe!K^sk5{>)vlj;_v6HCk0qJ8I_J%lg1me~{o2i&B31sF zNqPG3iI$o-%}~`q8D2VaiW-Wsh#0w^>vcZa`$XaS&)BPhX4X^LtJMt*4HOMH*;uvt tn3<$l8CXPIn-o)7)HY8jaSagS?vD*xaD9>=3rG1sIm<;WJ%T}{Bmf^<(Wd|a literal 0 HcmV?d00001 diff --git a/regression-test/data/mv_p0/sum_divede_count/sum_devide_count.out b/regression-test/data/mv_p0/sum_divede_count/sum_devide_count.out new file mode 100644 index 0000000000..67df77e0cc --- /dev/null +++ b/regression-test/data/mv_p0/sum_divede_count/sum_devide_count.out @@ -0,0 +1,29 @@ +-- This file is automatically generated. You should know what you did if you want to edit this +-- !select_star -- +-4 -4 -4 d +1 1 1 a +2 2 2 b +3 -3 \N c +3 2 \N c + +-- !select_mv -- +-4 d -4.0 +1 a 1.0 +2 b 2.0 +3 c -0.5 + +-- !select_mv -- +-4 -4.0 +1 1.0 +2 2.0 +3 -0.5 + +-- !select_mv -- +a 1.0 +b 2.0 +c -0.5 +d -4.0 + +-- !select_mv -- +-0.4 + diff --git a/regression-test/data/mv_p0/ut/testBitmapUnionInQuery/testBitmapUnionInQuery.out b/regression-test/data/mv_p0/ut/testBitmapUnionInQuery/testBitmapUnionInQuery.out new file mode 100644 index 0000000000..88913c5b65 --- /dev/null +++ b/regression-test/data/mv_p0/ut/testBitmapUnionInQuery/testBitmapUnionInQuery.out @@ -0,0 +1,9 @@ +-- This file is automatically generated. You should know what you did if you want to edit this +-- !select_star -- +2020-01-01 1 a 1 +2020-01-01 1 a 2 +2020-01-02 2 b 2 + +-- !select_mv -- +1 2 + diff --git a/regression-test/data/mv_p0/ut/testIncorrectRewriteCountDistinct/testIncorrectRewriteCountDistinct.out b/regression-test/data/mv_p0/ut/testIncorrectRewriteCountDistinct/testIncorrectRewriteCountDistinct.out new file mode 100644 index 0000000000..dd06cd3927 --- /dev/null +++ b/regression-test/data/mv_p0/ut/testIncorrectRewriteCountDistinct/testIncorrectRewriteCountDistinct.out @@ -0,0 +1,10 @@ +-- This file is automatically generated. You should know what you did if you want to edit this +-- !select_star -- +2020-01-01 1 a 1 +2020-01-01 1 a 2 +2020-01-02 2 b 2 + +-- !select_mv -- +a 2 +b 1 + diff --git a/regression-test/data/mv_p0/ut/testOrderByQueryOnProjectView/testOrderByQueryOnProjectView.out b/regression-test/data/mv_p0/ut/testOrderByQueryOnProjectView/testOrderByQueryOnProjectView.out new file mode 100644 index 0000000000..beefefba56 --- /dev/null +++ b/regression-test/data/mv_p0/ut/testOrderByQueryOnProjectView/testOrderByQueryOnProjectView.out @@ -0,0 +1,13 @@ +-- This file is automatically generated. You should know what you did if you want to edit this +-- !select_star -- +2020-01-01 1 a 1 1 1 +2020-01-01 1 a 1 1 1 +2020-01-02 2 b 2 2 2 +2020-01-03 3 c 3 3 3 + +-- !select_mv -- +1 +1 +2 +3 + diff --git a/regression-test/suites/mv_p0/sum_divede_count/sum_devide_count.groovy b/regression-test/suites/mv_p0/sum_divede_count/sum_devide_count.groovy new file mode 100644 index 0000000000..19b06d9fbc --- /dev/null +++ b/regression-test/suites/mv_p0/sum_divede_count/sum_devide_count.groovy @@ -0,0 +1,73 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +import org.codehaus.groovy.runtime.IOGroovyMethods + +suite ("sum_devide_count") { + sql """ DROP TABLE IF EXISTS d_table; """ + + sql """ + create table d_table( + k1 int null, + k2 int not null, + k3 bigint null, + k4 varchar(100) null + ) + duplicate key (k1,k2,k3) + distributed BY hash(k1) buckets 3 + properties("replication_num" = "1"); + """ + + sql "insert into d_table select 1,1,1,'a';" + sql "insert into d_table select 2,2,2,'b';" + sql "insert into d_table select 3,-3,null,'c';" + + test { + sql "create materialized view kavg as select k1,k4,avg(k2) from d_table group by k1,k4;" + exception "errCode = 2," + } + + createMV ("create materialized view kavg as select k1,k4,sum(k2),count(k2) from d_table group by k1,k4;") + + sql "insert into d_table select -4,-4,-4,'d';" + sql "insert into d_table select 3,2,null,'c';" + qt_select_star "select * from d_table order by k1,k2,k3,k4;" + + explain { + sql("select k1,k4,sum(k2)/count(k2) from d_table group by k1,k4 order by k1,k4;") + contains "(kavg)" + } + qt_select_mv "select k1,k4,sum(k2)/count(k2) from d_table group by k1,k4 order by k1,k4;" + + explain { + sql("select k1,sum(k2)/count(k2) from d_table group by k1 order by k1;") + contains "(kavg)" + } + qt_select_mv "select k1,sum(k2)/count(k2) from d_table group by k1 order by k1;" + + explain { + sql("select k4,sum(k2)/count(k2) from d_table group by k4 order by k4;") + contains "(kavg)" + } + qt_select_mv "select k4,sum(k2)/count(k2) from d_table group by k4 order by k4;" + + explain { + sql("select sum(k2)/count(k2) from d_table;") + contains "(kavg)" + } + qt_select_mv "select sum(k2)/count(k2) from d_table;" +} diff --git a/regression-test/suites/mv_p0/ut/testBitmapUnionInQuery/testBitmapUnionInQuery.groovy b/regression-test/suites/mv_p0/ut/testBitmapUnionInQuery/testBitmapUnionInQuery.groovy new file mode 100644 index 0000000000..da00a043b5 --- /dev/null +++ b/regression-test/suites/mv_p0/ut/testBitmapUnionInQuery/testBitmapUnionInQuery.groovy @@ -0,0 +1,49 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +import org.codehaus.groovy.runtime.IOGroovyMethods + +suite ("testBitmapUnionInQuery") { + sql """ DROP TABLE IF EXISTS user_tags; """ + + sql """ create table user_tags ( + time_col date, + user_id int, + user_name varchar(20), + tag_id int) + partition by range (time_col) (partition p1 values less than MAXVALUE) distributed by hash(time_col) buckets 3 properties('replication_num' = '1'); + """ + + sql """insert into user_tags values("2020-01-01",1,"a",1);""" + sql """insert into user_tags values("2020-01-02",2,"b",2);""" + + createMV("create materialized view user_tags_mv as select user_id, bitmap_union(to_bitmap(tag_id)) from user_tags group by user_id;") + + sql """insert into user_tags values("2020-01-01",1,"a",2);""" + + explain { + sql("select * from user_tags order by time_col;") + contains "(user_tags)" + } + qt_select_star "select * from user_tags order by time_col,tag_id;" + + explain { + sql("select user_id, bitmap_union_count(to_bitmap(tag_id)) a from user_tags group by user_id having a>1 order by a;") + contains "(user_tags_mv)" + } + qt_select_mv "select user_id, bitmap_union_count(to_bitmap(tag_id)) a from user_tags group by user_id having a>1 order by a;" +} diff --git a/regression-test/suites/mv_p0/ut/testIncorrectRewriteCountDistinct/testIncorrectRewriteCountDistinct.groovy b/regression-test/suites/mv_p0/ut/testIncorrectRewriteCountDistinct/testIncorrectRewriteCountDistinct.groovy new file mode 100644 index 0000000000..fe72c7f556 --- /dev/null +++ b/regression-test/suites/mv_p0/ut/testIncorrectRewriteCountDistinct/testIncorrectRewriteCountDistinct.groovy @@ -0,0 +1,49 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +import org.codehaus.groovy.runtime.IOGroovyMethods + +suite ("testIncorrectRewriteCountDistinct") { + sql """ DROP TABLE IF EXISTS user_tags; """ + + sql """ create table user_tags ( + time_col date, + user_id int, + user_name varchar(20), + tag_id int) + partition by range (time_col) (partition p1 values less than MAXVALUE) distributed by hash(time_col) buckets 3 properties('replication_num' = '1'); + """ + + sql """insert into user_tags values("2020-01-01",1,"a",1);""" + sql """insert into user_tags values("2020-01-02",2,"b",2);""" + + createMV("create materialized view user_tags_mv as select user_id, bitmap_union(to_bitmap(tag_id)) from user_tags group by user_id;") + + sql """insert into user_tags values("2020-01-01",1,"a",2);""" + + explain { + sql("select * from user_tags order by time_col;") + contains "(user_tags)" + } + qt_select_star "select * from user_tags order by time_col,tag_id;" + + explain { + sql("select user_name, count(distinct tag_id) from user_tags group by user_name;") + contains "(user_tags)" + } + qt_select_mv "select user_name, count(distinct tag_id) from user_tags group by user_name order by user_name;" +} diff --git a/regression-test/suites/mv_p0/ut/testOrderByQueryOnProjectView/testOrderByQueryOnProjectView.groovy b/regression-test/suites/mv_p0/ut/testOrderByQueryOnProjectView/testOrderByQueryOnProjectView.groovy new file mode 100644 index 0000000000..87bff6c630 --- /dev/null +++ b/regression-test/suites/mv_p0/ut/testOrderByQueryOnProjectView/testOrderByQueryOnProjectView.groovy @@ -0,0 +1,56 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +import org.codehaus.groovy.runtime.IOGroovyMethods + +suite ("testOrderByQueryOnProjectView") { + sql """ DROP TABLE IF EXISTS emps; """ + + sql """ + create table emps ( + time_col date, + empid int, + name varchar, + deptno int, + salary int, + commission int) + partition by range (time_col) (partition p1 values less than MAXVALUE) distributed by hash(time_col) buckets 3 properties('replication_num' = '1'); + """ + + sql """insert into emps values("2020-01-01",1,"a",1,1,1);""" + sql """insert into emps values("2020-01-02",2,"b",2,2,2);""" + sql """insert into emps values("2020-01-03",3,"c",3,3,3);""" + + createMV("create materialized view emps_mv as select deptno, empid from emps;") + + sql """insert into emps values("2020-01-01",1,"a",1,1,1);""" + + explain { + sql("select * from emps order by empid;") + contains "(emps)" + } + qt_select_star "select * from emps order by empid;" + + + explain { + sql("select empid from emps order by deptno;") + contains "(emps_mv)" + } + qt_select_mv "select empid from emps order by deptno;" + + +} \ No newline at end of file