Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add some missing columns and views to support atlas #15151

Merged
merged 2 commits into from
Feb 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,37 @@ use risingwave_frontend_macro::system_catalog;
NULL::integer AS numeric_scale,
c.position AS ordinal_position,
'YES' AS is_nullable,
NULL AS collation_name,
'pg_catalog' AS udt_schema,
CASE
WHEN c.data_type = 'varchar' THEN 'character varying'
ELSE c.data_type
END AS data_type,
c.udt_type AS udt_name
CURRENT_DATABASE() AS udt_catalog,
'pg_catalog' AS udt_schema,
c.udt_type AS udt_name,
NULL AS character_set_catalog,
NULL AS character_set_schema,
NULL AS character_set_name,
NULL AS collation_catalog,
NULL AS collation_schema,
NULL AS collation_name,
NULL AS domain_catalog,
NULL AS domain_schema,
NULL AS domain_name,
NULL AS scope_catalog,
NULL AS scope_schema,
NULL AS scope_name,
'NO' AS is_identity,
NULL AS identity_generation,
NULL AS identity_start,
NULL AS identity_increment,
NULL AS identity_maximum,
NULL AS identity_minimum,
NULL AS identity_cycle,
CASE
WHEN c.is_generated THEN 'ALWAYS'
ELSE 'NEVER'
END AS is_generated,
c.generation_expression
FROM rw_catalog.rw_columns c
LEFT JOIN rw_catalog.rw_relations r ON c.relation_id = r.id
JOIN rw_catalog.rw_schemas s ON s.id = r.schema_id
Expand All @@ -58,8 +82,29 @@ struct Column {
numeric_scale: i32,
ordinal_position: i32,
is_nullable: String,
collation_name: String,
udt_schema: String,
data_type: String,
udt_catalog: String,
udt_schema: String,
udt_name: String,
character_set_catalog: String,
character_set_schema: String,
character_set_name: String,
collation_catalog: String,
collation_schema: String,
collation_name: String,
domain_catalog: String,
domain_schema: String,
domain_name: String,
scope_catalog: String,
scope_schema: String,
scope_name: String,
is_identity: String,
identity_generation: String,
identity_start: String,
identity_increment: String,
identity_maximum: String,
identity_minimum: String,
identity_cycle: String,
is_generated: String,
generation_expression: String,
}
1 change: 1 addition & 0 deletions src/frontend/src/catalog/system_catalog/pg_catalog/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ mod pg_matviews;
mod pg_namespace;
mod pg_opclass;
mod pg_operator;
mod pg_partitioned_table;
mod pg_proc;
mod pg_roles;
mod pg_settings;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ use risingwave_frontend_macro::system_catalog;
ARRAY[]::smallint[] as indoption,
NULL AS indexprs,
NULL AS indpred,
FALSE AS indisprimary
FALSE AS indisprimary,
ARRAY[]::int[] AS indclass
FROM rw_catalog.rw_indexes"
)]
#[derive(Fields)]
Expand All @@ -46,4 +47,6 @@ struct PgIndex {
indpred: Option<String>,
// TODO: we return false as the default value.
indisprimary: bool,
// Empty array. We only have a dummy implementation of `pg_opclass` yet.
indclass: Vec<i32>,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// 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;

/// The catalog `pg_partitioned_table` stores information about how tables are partitioned. Reference: [`https://www.postgresql.org/docs/current/catalog-pg-partitioned-table.html`]
#[system_catalog(view, "pg_catalog.pg_partitioned_table")]
#[derive(Fields)]
struct PgPartitionedTable {
partrelid: i32,
partstrat: String,
partnatts: i16,
partdefid: i32,
partattrs: Vec<i16>,
partclass: Vec<i32>,
partcollation: Vec<i32>,
partexprs: Option<String>,
}
21 changes: 21 additions & 0 deletions src/frontend/src/catalog/system_catalog/rw_catalog/rw_columns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use risingwave_frontend_macro::system_catalog;

use crate::catalog::system_catalog::SysCatalogReaderImpl;
use crate::error::Result;
use crate::expr::{ExprDisplay, ExprImpl};

#[derive(Fields)]
#[primary_key(relation_id, name)]
Expand All @@ -27,6 +28,8 @@ struct RwColumn {
is_hidden: bool,
is_primary_key: bool,
is_distribution_key: bool,
is_generated: bool,
generation_expression: Option<String>,
data_type: String,
type_oid: i32,
type_len: i16,
Expand All @@ -51,6 +54,8 @@ fn read_rw_columns(reader: &SysCatalogReaderImpl) -> Result<Vec<RwColumn>> {
is_hidden: false,
is_primary_key: false,
is_distribution_key: false,
is_generated: false,
generation_expression: None,
data_type: column.data_type().to_string(),
type_oid: column.data_type().to_oid(),
type_len: column.data_type().type_len(),
Expand All @@ -71,6 +76,8 @@ fn read_rw_columns(reader: &SysCatalogReaderImpl) -> Result<Vec<RwColumn>> {
is_hidden: column.is_hidden,
is_primary_key: sink.downstream_pk.contains(&index),
is_distribution_key: sink.distribution_key.contains(&index),
is_generated: false,
generation_expression: None,
data_type: column.data_type().to_string(),
type_oid: column.data_type().to_oid(),
type_len: column.data_type().type_len(),
Expand All @@ -93,6 +100,8 @@ fn read_rw_columns(reader: &SysCatalogReaderImpl) -> Result<Vec<RwColumn>> {
is_hidden: column.is_hidden,
is_primary_key: table.pk.contains(&index),
is_distribution_key: false,
is_generated: false,
generation_expression: None,
data_type: column.data_type().to_string(),
type_oid: column.data_type().to_oid(),
type_len: column.data_type().type_len(),
Expand All @@ -104,6 +113,7 @@ fn read_rw_columns(reader: &SysCatalogReaderImpl) -> Result<Vec<RwColumn>> {
let table_rows = schema
.iter_valid_table()
.flat_map(|table| {
let schema = table.column_schema();
table
.columns
.iter()
Expand All @@ -115,6 +125,15 @@ fn read_rw_columns(reader: &SysCatalogReaderImpl) -> Result<Vec<RwColumn>> {
is_hidden: column.is_hidden,
is_primary_key: table.pk().iter().any(|idx| idx.column_index == index),
is_distribution_key: table.distribution_key.contains(&index),
is_generated: column.is_generated(),
generation_expression: column.generated_expr().map(|expr_node| {
let expr = ExprImpl::from_expr_proto(expr_node).unwrap();
let expr_display = ExprDisplay {
expr: &expr,
input_schema: &schema,
};
expr_display.to_string()
}),
data_type: column.data_type().to_string(),
type_oid: column.data_type().to_oid(),
type_len: column.data_type().type_len(),
Expand All @@ -138,6 +157,8 @@ fn read_rw_columns(reader: &SysCatalogReaderImpl) -> Result<Vec<RwColumn>> {
is_hidden: column.is_hidden,
is_primary_key: source.pk_col_ids.contains(&column.column_id()),
is_distribution_key: false,
is_generated: false,
generation_expression: None,
data_type: column.data_type().to_string(),
type_oid: column.data_type().to_oid(),
type_len: column.data_type().type_len(),
Expand Down
11 changes: 10 additions & 1 deletion src/frontend/src/catalog/table_catalog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use std::collections::{HashMap, HashSet};
use fixedbitset::FixedBitSet;
use itertools::Itertools;
use risingwave_common::catalog::{
ColumnCatalog, ConflictBehavior, TableDesc, TableId, TableVersionId,
ColumnCatalog, ConflictBehavior, Field, Schema, TableDesc, TableId, TableVersionId,
};
use risingwave_common::util::epoch::Epoch;
use risingwave_common::util::sort_util::ColumnOrder;
Expand Down Expand Up @@ -492,6 +492,15 @@ impl TableCatalog {
pub fn has_generated_column(&self) -> bool {
self.columns.iter().any(|c| c.is_generated())
}

pub fn column_schema(&self) -> Schema {
Schema::new(
self.columns
.iter()
.map(|c| Field::from(&c.column_desc))
.collect(),
)
}
}

impl From<PbTable> for TableCatalog {
Expand Down
Loading