Skip to content

Commit

Permalink
chore(frontend): migrate mv on mv e2e tests (#1338)
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Chi <iskyzh@gmail.com>
  • Loading branch information
skyzh authored Mar 29, 2022
1 parent a8670e9 commit aca1e20
Show file tree
Hide file tree
Showing 18 changed files with 447 additions and 112 deletions.
2 changes: 1 addition & 1 deletion e2e_test/streaming/mv_on_mv.slt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ statement ok
create materialized view m3 as select sum(m1.v1) as sum_m1_v1, sum(m1.v2) as sum_m1_v2 from m1;

statement ok
create materialized view m4 as select m1.v1, m1.v2, m2.v1, m2.v2 from m1 join m2 on m1.v1 = m2.v1;
create materialized view m4 as select m1.v1 as m1v1, m1.v2 as m1v2, m2.v1 as m2v1, m2.v2 as m2v2 from m1 join m2 on m1.v1 = m2.v1;

statement ok
flush;
Expand Down
282 changes: 282 additions & 0 deletions e2e_test/v2/streaming/mv_on_mv.slt
Original file line number Diff line number Diff line change
@@ -0,0 +1,282 @@
control sortmode rowsort

statement ok
create table t1(v1 int not null, v2 int not null);

statement ok
create table t2(v1 real not null, v2 int not null, v3 real not null);

statement ok
create materialized view m1 as select v1, v2 from t1 where v1 = 1;

statement ok
create materialized view m2 as select v1, v2 from t1 where v2 = 1;

statement ok
create materialized view m3 as select sum(m1.v1) as sum_m1_v1, sum(m1.v2) as sum_m1_v2 from m1;

statement ok
create materialized view m4 as select m1.v1 as m1v1, m1.v2 as m1v2, m2.v1 as m2v1, m2.v2 as m2v2 from m1 join m2 on m1.v1 = m2.v1;

statement ok
flush;

statement ok
insert into t1 values (2,1),(1,2),(1,1);

statement ok
flush;

query II
select v1, v2 from t1;
----
2 1
1 2
1 1

query II
select v1, v2 from m1;
----
1 2
1 1

query II
select v1, v2 from m2;
----
2 1
1 1

query II
select sum_m1_v1, sum_m1_v2 from m3;
----
2 3

query IIII
select m1v1, m1v2, m2v1, m2v2 from m4;
----
1 2 1 1
1 1 1 1

statement ok
create materialized view m5 as select m1.v1 as m1v1, m1.v2 as m1v2, m2.v1 as m2v1, m2.v2 as m2v2 from m1 join m2 on m1.v1 = m2.v1;

statement ok
flush;

query IIII
select m1v1, m1v2, m2v1, m2v2 from m5;
----
1 2 1 1
1 1 1 1

statement ok
insert into t1 values (3,1),(1,3);

statement ok
flush;

query IIII
select m1v1, m1v2, m2v1, m2v2 from m5;
----
1 2 1 1
1 1 1 1
1 3 1 1

statement ok
create materialized view m6 as select v2, v3, v1 from t2;

statement ok
create materialized view m7 as select sum(v1) as sum_v1, avg(v3) as avg_v3 from m6 group by v1;

statement ok
create materialized view m8 as select sum(v1) as sum_v1 from m6 group by v2;

statement ok
flush;

statement ok
insert into t2 values (1,2,3),(1,5,6),(3,2,6);

statement ok
flush;

query III
select v1, v2, v3 from t2;
----
1 2 3
1 5 6
3 2 6

query III
select v2, v3, v1 from m6;
----
2 3 1
5 6 1
2 6 3

query II
select sum_v1, avg_v3 from m7;
----
2 4.5
3 6

query I
select sum_v1 from m8;
----
4
1

statement ok
create materialized view m9 as select * from t2;

statement ok
create materialized view m10 as select sum(v1) as sum_v1, sum(v3) as sum_v3 from m9 group by v2;

statement ok
flush;

query III
select v1, v2, v3 from m9;
----
1 2 3
1 5 6
3 2 6

query II
select sum_v1, sum_v3 from m10;
----
4 9
1 6

statement ok
create table t3(v1 int not null, v2 int not null, v3 int not null);

statement ok
flush;

statement ok
insert into t3 values (1,2,3),(1,5,6),(3,2,6);

statement ok
flush;

statement ok
create materialized view m11 as select v1, v2, v3 from t3;

statement ok
create materialized view m12 as select avg(v1) as avg_v1, sum(v2) as sum_v2, count(v3) as count_v3 from m11;

statement ok
flush;

query III
select v1, v2, v3 from m11;
----
1 2 3
1 5 6
3 2 6

# TODO: enable avg_v1
query III
select sum_v2, count_v3 from m12;
----
9 3

statement ok
create table t4(v1 real not null);

statement ok
flush;

statement ok
insert into t4 values(1),(2),(3);

statement ok
flush;

statement ok
create materialized view m13 as select * from t4;

statement ok
create materialized view m14 as select count(v1) as count_v1 from m13;

statement ok
flush;

query I
select v1 from m13;
----
1
2
3

query I
select * from m14;
----
3

statement ok
flush;

statement ok
flush;

statement ok
flush;

statement ok
drop materialized view m3;

statement ok
drop materialized view m4;

statement ok
drop materialized view m5;

statement ok
drop materialized view m1;

statement ok
drop materialized view m2;

statement ok
drop table t1;


statement ok
drop materialized view m7;

statement ok
drop materialized view m8;

statement ok
drop materialized view m6;

statement ok
drop materialized view m10;

statement ok
drop materialized view m9;

statement ok
drop table t2;


statement ok
drop materialized view m12;

statement ok
drop materialized view m11;

statement ok
drop table t3;


statement ok
drop materialized view m14;

statement ok
drop materialized view m13;

statement ok
drop table t4;
10 changes: 9 additions & 1 deletion rust/frontend/src/binder/bind_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,23 @@ pub struct ColumnBinding {
pub column_name: String,
pub index: usize,
pub data_type: DataType,
pub is_hidden: bool,
}

impl ColumnBinding {
pub fn new(table_name: String, column_name: String, index: usize, data_type: DataType) -> Self {
pub fn new(
table_name: String,
column_name: String,
index: usize,
data_type: DataType,
is_hidden: bool,
) -> Self {
ColumnBinding {
table_name,
column_name,
index,
data_type,
is_hidden,
}
}
}
Expand Down
24 changes: 16 additions & 8 deletions rust/frontend/src/binder/relation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

use std::collections::hash_map::Entry;

use itertools::Itertools;
use risingwave_common::catalog::{ColumnDesc, TableDesc, DEFAULT_SCHEMA_NAME};
use risingwave_common::error::{ErrorCode, Result};
use risingwave_common::try_match_expand;
Expand Down Expand Up @@ -180,12 +181,14 @@ impl Binder {
let table_desc = table_catalog.table_desc();
let columns = table_catalog.columns().to_vec();

let columns = columns
.into_iter()
.map(|c| c.column_desc)
.collect::<Vec<ColumnDesc>>();
self.bind_context(
columns.iter().cloned().map(|c| (c.name, c.data_type)),
columns.iter().map(|c| {
(
c.column_desc.name.clone(),
c.column_desc.data_type.clone(),
c.is_hidden,
)
}),
table_name.clone(),
)?;

Expand Down Expand Up @@ -224,19 +227,20 @@ impl Binder {
/// Fill the [`BindContext`](super::BindContext) for table.
fn bind_context(
&mut self,
columns: impl IntoIterator<Item = (String, DataType)>,
columns: impl IntoIterator<Item = (String, DataType, bool)>,
table_name: String,
) -> Result<()> {
let begin = self.context.columns.len();
columns
.into_iter()
.enumerate()
.for_each(|(index, (name, data_type))| {
.for_each(|(index, (name, data_type, is_hidden))| {
self.context.columns.push(ColumnBinding::new(
table_name.clone(),
name.clone(),
begin + index,
data_type,
is_hidden,
));
self.context
.indexs_of
Expand Down Expand Up @@ -266,7 +270,11 @@ impl Binder {
let query = self.bind_query(query)?;
let sub_query_id = self.next_subquery_id();
self.bind_context(
itertools::zip_eq(query.names().into_iter(), query.data_types().into_iter()),
query
.names()
.into_iter()
.zip_eq(query.data_types().into_iter())
.map(|(x, y)| (x, y, false)),
format!("{}_{}", UNNAMED_SUBQUERY, sub_query_id),
)?;
Ok(BoundSubquery { query })
Expand Down
Loading

0 comments on commit aca1e20

Please sign in to comment.