| -- MV source tables are iceberg tables but MV is not |
| -- SORT_QUERY_RESULTS |
| |
| set hive.support.concurrency=true; |
| set hive.txn.manager=org.apache.hadoop.hive.ql.lockmgr.DbTxnManager; |
| |
| drop table if exists tbl_ice; |
| drop table if exists tbl_ice_v2; |
| |
| create external table tbl_ice(a int, b string, c int) stored by iceberg stored as orc tblproperties ('format-version'='1'); |
| create external table tbl_ice_v2(d int, e string, f int) stored by iceberg stored as orc tblproperties ('format-version'='2'); |
| |
| insert into tbl_ice_v2 values (1, 'one v2', 50), (4, 'four v2', 53), (5, 'five v2', 54); |
| |
| create materialized view mat1 disable rewrite as |
| select tbl_ice.b, tbl_ice.c, tbl_ice_v2.e from tbl_ice join tbl_ice_v2 on tbl_ice.a=tbl_ice_v2.d where tbl_ice.c > 52; |
| |
| -- view should be empty |
| select * from mat1; |
| |
| alter materialized view mat1 enable rewrite; |
| |
| -- view is up-to-date, use it |
| explain cbo |
| select tbl_ice.b, tbl_ice.c, tbl_ice_v2.e from tbl_ice join tbl_ice_v2 on tbl_ice.a=tbl_ice_v2.d where tbl_ice.c > 52; |
| |
| -- insert some new values to one of the source tables |
| insert into tbl_ice values (1, 'one', 50), (2, 'two', 51), (3, 'three', 52), (4, 'four', 53), (5, 'five', 54); |
| |
| -- view is outdated, can not be used |
| explain cbo |
| select tbl_ice.b, tbl_ice.c, tbl_ice_v2.e from tbl_ice join tbl_ice_v2 on tbl_ice.a=tbl_ice_v2.d where tbl_ice.c > 52; |
| |
| explain cbo |
| alter materialized view mat1 rebuild; |
| |
| alter materialized view mat1 rebuild; |
| |
| -- view should contain data |
| select * from mat1; |
| |
| -- view is up-to-date again, use it |
| explain cbo |
| select tbl_ice.b, tbl_ice.c, tbl_ice_v2.e from tbl_ice join tbl_ice_v2 on tbl_ice.a=tbl_ice_v2.d where tbl_ice.c > 52; |