From 1a9e6e43c12aac68f164d87b0768e46963bd5bb5 Mon Sep 17 00:00:00 2001 From: Bugen Zhao Date: Thu, 7 Mar 2024 13:35:54 +0800 Subject: [PATCH] fix(frontend): accept all boolean literals for boolean config entry (#15485) Signed-off-by: Bugen Zhao --- e2e_test/batch/config.slt | 9 +++++++++ e2e_test/error_ui/simple/main.slt | 2 +- src/common/proc_macro/src/session_config.rs | 9 ++++++++- src/common/src/lib.rs | 2 +- 4 files changed, 19 insertions(+), 3 deletions(-) diff --git a/e2e_test/batch/config.slt b/e2e_test/batch/config.slt index 9cbd6b667b396..feaa6a485b4db 100644 --- a/e2e_test/batch/config.slt +++ b/e2e_test/batch/config.slt @@ -8,3 +8,12 @@ query T show application_name; ---- slt + +statement ok +set synchronize_seqscans to on; + +statement ok +set synchronize_seqscans to f; + +statement ok +set synchronize_seqscans to default; diff --git a/e2e_test/error_ui/simple/main.slt b/e2e_test/error_ui/simple/main.slt index 50eedcf4529cf..cbe2154fa4f6b 100644 --- a/e2e_test/error_ui/simple/main.slt +++ b/e2e_test/error_ui/simple/main.slt @@ -80,7 +80,7 @@ db error: ERROR: Failed to run the query Caused by these errors (recent errors listed first): 1: Failed to get/set session config 2: Invalid value `maybe` for `rw_implicit_flush` - 3: provided string was not `true` or `false` + 3: Invalid bool statement error diff --git a/src/common/proc_macro/src/session_config.rs b/src/common/proc_macro/src/session_config.rs index 4bb4ea94048c3..2d961f360ad7c 100644 --- a/src/common/proc_macro/src/session_config.rs +++ b/src/common/proc_macro/src/session_config.rs @@ -136,6 +136,13 @@ pub(crate) fn derive_config(input: DeriveInput) -> TokenStream { quote! {} }; + // An easy way to check if the type is bool and use a different parse function. + let parse = if quote!(#ty).to_string() == "bool" { + quote!(risingwave_common::cast::str_to_bool) + } else { + quote!(<#ty as ::std::str::FromStr>::from_str) + }; + struct_impl_set.push(quote! { #[doc = #set_func_doc] pub fn #set_func_name( @@ -143,7 +150,7 @@ pub(crate) fn derive_config(input: DeriveInput) -> TokenStream { val: &str, reporter: &mut impl ConfigReporter ) -> SessionConfigResult<()> { - let val_t = <#ty as ::std::str::FromStr>::from_str(val).map_err(|e| { + let val_t = #parse(val).map_err(|e| { SessionConfigError::InvalidValue { entry: #entry_name, value: val.to_string(), diff --git a/src/common/src/lib.rs b/src/common/src/lib.rs index 313c0bada6616..4df0999828c85 100644 --- a/src/common/src/lib.rs +++ b/src/common/src/lib.rs @@ -45,7 +45,7 @@ #![feature(array_methods)] #![feature(btree_cursors)] -#[cfg_attr(not(test), expect(unused_extern_crates))] +#[cfg_attr(not(test), allow(unused_extern_crates))] extern crate self as risingwave_common; #[macro_use]