Skip to content

Commit 3f5a6c8

Browse files
author
Tao Wu
authored
feat: support information_schema.views (risingwavelabs#12045)
1 parent 999b9d2 commit 3f5a6c8

File tree

3 files changed

+48
-0
lines changed

3 files changed

+48
-0
lines changed

src/frontend/src/catalog/system_catalog/information_schema/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

1515
pub mod columns;
1616
pub mod tables;
17+
pub mod views;
1718

1819
pub use columns::*;
1920
pub use tables::*;
21+
pub use views::*;
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// Copyright 2023 RisingWave Labs
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
use std::sync::LazyLock;
16+
17+
use risingwave_common::catalog::INFORMATION_SCHEMA_SCHEMA_NAME;
18+
use risingwave_common::types::DataType;
19+
20+
use crate::catalog::system_catalog::BuiltinView;
21+
22+
/// The view `views` contains all views defined in the current database. Only those views
23+
/// are shown that the current user has access to (by way of being the owner or having
24+
/// some privilege).
25+
/// Ref: [`https://www.postgresql.org/docs/current/infoschema-views.html`]
26+
///
27+
/// In RisingWave, `views` contains information about defined views.
28+
pub static INFORMATION_SCHEMA_VIEWS: LazyLock<BuiltinView> = LazyLock::new(|| BuiltinView {
29+
name: "views",
30+
schema: INFORMATION_SCHEMA_SCHEMA_NAME,
31+
columns: &[
32+
(DataType::Varchar, "table_catalog"),
33+
(DataType::Varchar, "table_schema"),
34+
(DataType::Varchar, "table_name"),
35+
(DataType::Varchar, "view_definition"),
36+
],
37+
sql: "SELECT CURRENT_DATABASE() AS table_catalog, \
38+
s.name AS table_schema, \
39+
v.name AS table_name, \
40+
v.definition AS view_definition \
41+
FROM rw_catalog.rw_views v \
42+
JOIN rw_catalog.rw_schemas s ON v.schema_id = s.id \
43+
ORDER BY table_schema, table_name"
44+
.to_string(),
45+
});

src/frontend/src/catalog/system_catalog/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,7 @@ prepare_sys_catalog! {
377377
{ BuiltinCatalog::View(&PG_DEPEND) },
378378
{ BuiltinCatalog::View(&INFORMATION_SCHEMA_COLUMNS) },
379379
{ BuiltinCatalog::View(&INFORMATION_SCHEMA_TABLES) },
380+
{ BuiltinCatalog::View(&INFORMATION_SCHEMA_VIEWS) },
380381
{ BuiltinCatalog::Table(&RW_DATABASES), read_rw_database_info },
381382
{ BuiltinCatalog::Table(&RW_SCHEMAS), read_rw_schema_info },
382383
{ BuiltinCatalog::Table(&RW_USERS), read_rw_user_info },

0 commit comments

Comments
 (0)