Skip to content

Commit

Permalink
feat(frontend): stub session server_encoding (#12896)
Browse files Browse the repository at this point in the history
  • Loading branch information
0xRad7 authored Oct 17, 2023
1 parent 7c37573 commit 35f77c6
Showing 1 changed file with 33 additions and 1 deletion.
34 changes: 33 additions & 1 deletion src/common/src/session_config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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] =
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -343,6 +345,7 @@ type StandardConformingStrings = ConfigString<STANDARD_CONFORMING_STRINGS>;
type StreamingRateLimit = ConfigU64<STREAMING_RATE_LIMIT, 0>;
type CdcBackfill = ConfigBool<CDC_BACKFILL, false>;
type BackgroundDdl = ConfigBool<BACKGROUND_DDL, false>;
type ServerEncoding = ConfigString<SERVER_ENCODING>;

/// Report status or notice to caller.
pub trait ConfigReporter {
Expand Down Expand Up @@ -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::<SERVER_ENCODING>(String::from(\"UTF8\"))"))]
server_encoding: ServerEncoding,
}

impl ConfigMap {
Expand Down Expand Up @@ -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());
}
Expand Down Expand Up @@ -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())
}
Expand Down Expand Up @@ -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.")
},
]
}

Expand Down Expand Up @@ -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
}
}

0 comments on commit 35f77c6

Please sign in to comment.