From 35f77c63e87f6712cb67028847ff601b468ce271 Mon Sep 17 00:00:00 2001 From: SevenLM361 <42933171+SevenLM361@users.noreply.github.com> Date: Tue, 17 Oct 2023 17:03:08 +0800 Subject: [PATCH] feat(frontend): stub session server_encoding (#12896) --- src/common/src/session_config/mod.rs | 34 +++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/src/common/src/session_config/mod.rs b/src/common/src/session_config/mod.rs index cab147d0000bb..7706899e26f92 100644 --- a/src/common/src/session_config/mod.rs +++ b/src/common/src/session_config/mod.rs @@ -38,7 +38,7 @@ use crate::util::epoch::Epoch; // This is a hack, &'static str is not allowed as a const generics argument. // TODO: refine this using the adt_const_params feature. -const CONFIG_KEYS: [&str; 38] = [ +const CONFIG_KEYS: [&str; 39] = [ "RW_IMPLICIT_FLUSH", "CREATE_COMPACTION_GROUP_FOR_MV", "QUERY_MODE", @@ -77,6 +77,7 @@ const CONFIG_KEYS: [&str; 38] = [ "CDC_BACKFILL", "RW_STREAMING_OVER_WINDOW_CACHE_POLICY", "BACKGROUND_DDL", + "SERVER_ENCODING", ]; // MUST HAVE 1v1 relationship to CONFIG_KEYS. e.g. CONFIG_KEYS[IMPLICIT_FLUSH] = @@ -119,6 +120,7 @@ const STREAMING_RATE_LIMIT: usize = 34; const CDC_BACKFILL: usize = 35; const STREAMING_OVER_WINDOW_CACHE_POLICY: usize = 36; const BACKGROUND_DDL: usize = 37; +const SERVER_ENCODING: usize = 38; trait ConfigEntry: Default + for<'a> TryFrom<&'a [&'a str], Error = RwError> { fn entry_name() -> &'static str; @@ -343,6 +345,7 @@ type StandardConformingStrings = ConfigString; type StreamingRateLimit = ConfigU64; type CdcBackfill = ConfigBool; type BackgroundDdl = ConfigBool; +type ServerEncoding = ConfigString; /// Report status or notice to caller. pub trait ConfigReporter { @@ -492,6 +495,10 @@ pub struct ConfigMap { streaming_over_window_cache_policy: OverWindowCachePolicy, background_ddl: BackgroundDdl, + + /// Shows the server-side character set encoding. At present, this parameter can be shown but not set, because the encoding is determined at database creation time. + #[educe(Default(expression = "ConfigString::(String::from(\"UTF8\"))"))] + server_encoding: ServerEncoding, } impl ConfigMap { @@ -611,6 +618,20 @@ impl ConfigMap { self.streaming_over_window_cache_policy = val.as_slice().try_into()?; } else if key.eq_ignore_ascii_case(BackgroundDdl::entry_name()) { self.background_ddl = val.as_slice().try_into()?; + } else if key.eq_ignore_ascii_case(ServerEncoding::entry_name()) { + let enc: ServerEncoding = val.as_slice().try_into()?; + // https://github.com/postgres/postgres/blob/REL_15_3/src/common/encnames.c#L525 + let clean = enc + .as_str() + .replace(|c: char| !c.is_ascii_alphanumeric(), ""); + if !clean.eq_ignore_ascii_case("UTF8") { + return Err(ErrorCode::InvalidConfigValue { + config_entry: ServerEncoding::entry_name().into(), + config_value: enc.0, + } + .into()); + } + // No actual assignment because we only support UTF8. } else { return Err(ErrorCode::UnrecognizedConfigurationParameter(key.to_string()).into()); } @@ -700,6 +721,8 @@ impl ConfigMap { Ok(self.streaming_over_window_cache_policy.to_string()) } else if key.eq_ignore_ascii_case(BackgroundDdl::entry_name()) { Ok(self.background_ddl.to_string()) + } else if key.eq_ignore_ascii_case(ServerEncoding::entry_name()) { + Ok(self.server_encoding.to_string()) } else { Err(ErrorCode::UnrecognizedConfigurationParameter(key.to_string()).into()) } @@ -897,6 +920,11 @@ impl ConfigMap { setting: self.background_ddl.to_string(), description: String::from("Run DDL statements in background"), }, + VariableInfo{ + name : ServerEncoding::entry_name().to_lowercase(), + setting : self.server_encoding.to_string(), + description : String::from("Sets the server character set encoding.") + }, ] } @@ -1039,4 +1067,8 @@ impl ConfigMap { pub fn get_background_ddl(&self) -> bool { self.background_ddl.0 } + + pub fn get_server_encoding(&self) -> &str { + &self.server_encoding + } }