-
Notifications
You must be signed in to change notification settings - Fork 590
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(catalog): add system catalog
rw_depend
(#15385)
Signed-off-by: Runji Wang <[email protected]>
- Loading branch information
1 parent
e2149b6
commit a671b7f
Showing
3 changed files
with
101 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
statement ok | ||
create table t1 (a int); | ||
|
||
statement ok | ||
create source s1 (a int) with (connector='datagen'); | ||
|
||
statement ok | ||
create materialized view mv1 as select t1.a from t1 join s1 on t1.a = s1.a; | ||
|
||
statement ok | ||
create materialized view mv2 as select * from mv1; | ||
|
||
statement ok | ||
create sink sink1 from mv2 with (connector='blackhole'); | ||
|
||
|
||
# equivalent to: | ||
# select objid::regclass, refobjid::regclass from rw_depend; | ||
query TT rowsort | ||
select r1.name, r2.name relname | ||
from rw_depend d | ||
join rw_relations r1 on d.objid = r1.id | ||
join rw_relations r2 on d.refobjid = r2.id; | ||
---- | ||
mv1 s1 | ||
mv1 t1 | ||
mv2 mv1 | ||
sink1 mv2 | ||
|
||
statement ok | ||
drop sink sink1; | ||
|
||
statement ok | ||
drop materialized view mv2; | ||
|
||
statement ok | ||
drop materialized view mv1; | ||
|
||
statement ok | ||
drop source s1; | ||
|
||
statement ok | ||
drop table t1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
src/frontend/src/catalog/system_catalog/rw_catalog/rw_depend.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// Copyright 2024 RisingWave Labs | ||
// | ||
// Licensed 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. | ||
|
||
use risingwave_common::types::Fields; | ||
use risingwave_frontend_macro::system_catalog; | ||
|
||
use crate::catalog::system_catalog::SysCatalogReaderImpl; | ||
use crate::error::Result; | ||
|
||
/// The catalog `rw_depend` records the dependency relationships between tables, mviews etc. | ||
#[derive(Fields)] | ||
#[primary_key(objid, refobjid)] | ||
struct RwDepend { | ||
/// The OID of the specific dependent object | ||
objid: i32, | ||
/// The OID of the specific referenced object | ||
refobjid: i32, | ||
} | ||
|
||
#[system_catalog(table, "rw_catalog.rw_depend")] | ||
fn read_rw_depend(reader: &SysCatalogReaderImpl) -> Result<Vec<RwDepend>> { | ||
let catalog_reader = reader.catalog_reader.read_guard(); | ||
|
||
let mut depends = vec![]; | ||
for schema in catalog_reader.iter_schemas(&reader.auth_context.database)? { | ||
for table in schema.iter_table().chain(schema.iter_mv()) { | ||
for referenced in &table.dependent_relations { | ||
let depend = RwDepend { | ||
objid: table.id.table_id as i32, | ||
refobjid: referenced.table_id as i32, | ||
}; | ||
depends.push(depend); | ||
} | ||
} | ||
for sink in schema.iter_sink() { | ||
for referenced in &sink.dependent_relations { | ||
let depend = RwDepend { | ||
objid: sink.id.sink_id as i32, | ||
refobjid: referenced.table_id as i32, | ||
}; | ||
depends.push(depend); | ||
} | ||
} | ||
} | ||
Ok(depends) | ||
} |