[Chore](case) add some regression-test case about materialized-view #18946

This commit is contained in:
Pxl
2023-04-24 11:36:56 +08:00
committed by GitHub
parent 296b0c92f7
commit 1f9450e0f7
9 changed files with 288 additions and 0 deletions

Binary file not shown.

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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;"
}

View File

@ -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;"
}

View File

@ -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;"
}

View File

@ -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;"
}