diff --git a/src/operator/src/statement.rs b/src/operator/src/statement.rs index c04e2d11fe8..6122a9f4281 100644 --- a/src/operator/src/statement.rs +++ b/src/operator/src/statement.rs @@ -527,7 +527,8 @@ impl StatementExecutor { } fn set_variables(&self, set_var: SetVariables, query_ctx: QueryContextRef) -> Result { - let var_name = set_var.variable.to_string().to_uppercase(); + let variable = sql::ast::object_name_to_string_unquoted(&set_var.variable); + let var_name = variable.to_uppercase(); debug!( "Trying to set {}={} for session: {} ", @@ -536,11 +537,7 @@ impl StatementExecutor { query_ctx.conn_info() ); - if set_query_option( - &set_var.variable.to_string(), - set_var.value.clone(), - query_ctx.clone(), - )? { + if set_query_option(&variable, set_var.value.clone(), query_ctx.clone())? { return Ok(Output::new_with_affected_rows(0)); } diff --git a/src/query/src/sql.rs b/src/query/src/sql.rs index 8d4a4bc99d4..260b13c7541 100644 --- a/src/query/src/sql.rs +++ b/src/query/src/sql.rs @@ -850,7 +850,7 @@ pub fn show_query_option( query_ctx: QueryContextRef, engine: &dyn crate::QueryEngine, ) -> Result> { - let name = stmt.variable.to_string(); + let name = sql::ast::object_name_to_string_unquoted(&stmt.variable); let Some(canonical) = session::query_options::canonical_query_option_name(&name) else { if name.to_ascii_lowercase().starts_with("query.") || name.to_ascii_lowercase().starts_with("datafusion.") diff --git a/src/sql/src/ast.rs b/src/sql/src/ast.rs index 122740987a0..f9e879c7569 100644 --- a/src/sql/src/ast.rs +++ b/src/sql/src/ast.rs @@ -32,3 +32,37 @@ impl ObjectNamePartExt for ObjectNamePart { ident.value.clone() } } + +/// Formats an object name by joining its identifier values without quotes. +pub fn object_name_to_string_unquoted(name: &ObjectName) -> String { + name.0 + .iter() + .map(ObjectNamePartExt::to_string_unquoted) + .collect::>() + .join(".") +} + +#[cfg(test)] +mod tests { + use sqlparser::ast::{Ident, ObjectName, ObjectNamePart}; + + use super::object_name_to_string_unquoted; + + #[test] + fn test_object_name_to_string_unquoted() { + let quoted = ObjectName(vec![ObjectNamePart::Identifier(Ident::with_quote( + '"', + "query.parallelism", + ))]); + let unquoted = ObjectName(vec![ + ObjectNamePart::Identifier(Ident::new("query")), + ObjectNamePart::Identifier(Ident::new("parallelism")), + ]); + + assert_eq!("query.parallelism", object_name_to_string_unquoted("ed)); + assert_eq!( + object_name_to_string_unquoted(&unquoted), + object_name_to_string_unquoted("ed) + ); + } +}