Skip to content

Commit

Permalink
feat(frontend): add description column for SHOW PARAMETERS (#15113)
Browse files Browse the repository at this point in the history
Signed-off-by: Bugen Zhao <[email protected]>
  • Loading branch information
BugenZhao authored Feb 19, 2024
1 parent b2bda85 commit 205a152
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 10 deletions.
28 changes: 23 additions & 5 deletions src/common/src/system_param/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,17 @@ use std::borrow::Borrow;

use risingwave_pb::meta::PbSystemParams;

use super::{default, system_params_to_kv, ParamValue};
use super::{default, ParamValue};
use crate::for_all_params;

/// Information about a system parameter.
pub struct ParameterInfo {
pub name: &'static str,
pub mutable: bool,
pub value: String,
pub description: &'static str,
}

macro_rules! define_system_params_read_trait {
($({ $field:ident, $type:ty, $default:expr, $is_mutable:expr, $doc:literal, $($rest:tt)* },)*) => {
/// The trait delegating reads on [`risingwave_pb::meta::SystemParams`].
Expand All @@ -32,6 +40,20 @@ macro_rules! define_system_params_read_trait {
#[doc = $doc]
fn $field(&self) -> <$type as ParamValue>::Borrowed<'_>;
)*

/// Return the information of all parameters.
fn get_all(&self) -> Vec<ParameterInfo> {
vec![
$(
ParameterInfo {
name: stringify!($field),
mutable: $is_mutable,
value: self.$field().to_string(),
description: $doc,
},
)*
]
}
}
};
}
Expand Down Expand Up @@ -70,10 +92,6 @@ where
}
}

pub fn to_kv(&self) -> Vec<(String, String)> {
system_params_to_kv(self.inner()).unwrap()
}

fn inner(&self) -> &PbSystemParams {
self.inner.borrow()
}
Expand Down
15 changes: 10 additions & 5 deletions src/frontend/src/handler/variable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use pgwire::pg_protocol::ParameterStatus;
use pgwire::pg_response::{PgResponse, StatementType};
use pgwire::types::Row;
use risingwave_common::session_config::{ConfigReporter, SESSION_CONFIG_LIST_SEP};
use risingwave_common::system_param::is_mutable;
use risingwave_common::system_param::reader::SystemParamsRead;
use risingwave_common::types::{DataType, ScalarRefImpl};
use risingwave_sqlparser::ast::{Ident, SetTimeZoneValue, SetVariableValue, Value};
use risingwave_sqlparser::keywords::Keyword;
Expand Down Expand Up @@ -158,13 +158,18 @@ async fn handle_show_system_params(handler_args: HandlerArgs) -> Result<Vec<Row>
.get_system_params()
.await?;
let rows = params
.to_kv()
.get_all()
.into_iter()
.map(|(k, v)| {
let is_mutable_bytes = ScalarRefImpl::Bool(is_mutable(&k).unwrap())
.map(|info| {
let is_mutable_bytes = ScalarRefImpl::Bool(info.mutable)
.text_format(&DataType::Boolean)
.into();
Row::new(vec![Some(k.into()), Some(v.into()), Some(is_mutable_bytes)])
Row::new(vec![
Some(info.name.into()),
Some(info.value.into()),
Some(info.description.into()),
Some(is_mutable_bytes),
])
})
.collect_vec();
Ok(rows)
Expand Down
5 changes: 5 additions & 0 deletions src/frontend/src/utils/infer_stmt_row_desc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,11 @@ pub fn infer_show_variable(name: &str) -> Vec<PgFieldDescriptor> {
DataType::Varchar.to_oid(),
DataType::Varchar.type_len(),
),
PgFieldDescriptor::new(
"Description".to_string(),
DataType::Varchar.to_oid(),
DataType::Varchar.type_len(),
),
PgFieldDescriptor::new(
"Mutable".to_string(),
DataType::Boolean.to_oid(),
Expand Down

0 comments on commit 205a152

Please sign in to comment.