From 626a7e11da2dd6e552a433eb37bce80c57a691be Mon Sep 17 00:00:00 2001 From: Bugen Zhao Date: Sun, 18 Feb 2024 18:24:35 +0800 Subject: [PATCH 1/2] refine show parameters --- src/common/src/system_param/reader.rs | 28 +++++++++++++++---- src/frontend/src/handler/variable.rs | 14 +++++++--- src/frontend/src/utils/infer_stmt_row_desc.rs | 5 ++++ 3 files changed, 38 insertions(+), 9 deletions(-) diff --git a/src/common/src/system_param/reader.rs b/src/common/src/system_param/reader.rs index c6b8d8c5af6aa..cf17c7bb43dd5 100644 --- a/src/common/src/system_param/reader.rs +++ b/src/common/src/system_param/reader.rs @@ -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`]. @@ -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 { + vec![ + $( + ParameterInfo { + name: stringify!($field), + mutable: $is_mutable, + value: self.$field().to_string(), + description: $doc, + }, + )* + ] + } } }; } @@ -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() } diff --git a/src/frontend/src/handler/variable.rs b/src/frontend/src/handler/variable.rs index 884947c88b763..70028ae239133 100644 --- a/src/frontend/src/handler/variable.rs +++ b/src/frontend/src/handler/variable.rs @@ -19,6 +19,7 @@ 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; @@ -158,13 +159,18 @@ async fn handle_show_system_params(handler_args: HandlerArgs) -> Result .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) diff --git a/src/frontend/src/utils/infer_stmt_row_desc.rs b/src/frontend/src/utils/infer_stmt_row_desc.rs index 1ee950997720c..690b2bf81872f 100644 --- a/src/frontend/src/utils/infer_stmt_row_desc.rs +++ b/src/frontend/src/utils/infer_stmt_row_desc.rs @@ -232,6 +232,11 @@ pub fn infer_show_variable(name: &str) -> Vec { 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(), From b8b5ccd8b5c105b0cf82edfdb0f49192f37ab34d Mon Sep 17 00:00:00 2001 From: Bugen Zhao Date: Sun, 18 Feb 2024 18:29:48 +0800 Subject: [PATCH 2/2] fix unused imports Signed-off-by: Bugen Zhao --- src/frontend/src/handler/variable.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/frontend/src/handler/variable.rs b/src/frontend/src/handler/variable.rs index 70028ae239133..9b4828b232837 100644 --- a/src/frontend/src/handler/variable.rs +++ b/src/frontend/src/handler/variable.rs @@ -18,7 +18,6 @@ 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};