diff --git a/regression-test/certificate.p12 b/regression-test/certificate.p12 new file mode 100644 index 0000000000..3098460e8b Binary files /dev/null and b/regression-test/certificate.p12 differ 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