fix: resolve SET/SHOW option names from unquoted identifiers

SET "query.parallelism" = 4 previously succeeded without taking effect:
ObjectName::to_string() keeps the quotes, so the name never matched the
known query options and fell through to the unknown-setting compatibility
branch, bypassing validation of invalid values such as 0.

Resolve the option name from the parsed identifier values
(object_name_to_string_unquoted) for both SET and SHOW so quoted and
unquoted spellings behave identically.

Signed-off-by: discord9 <55937128+discord9@users.noreply.github.com>
This commit is contained in:
discord9
2026-10-14 15:20:33 +08:00
parent 8a451ea4e0
commit c47a42f488
3 changed files with 38 additions and 7 deletions
+3 -6
View File
@@ -527,7 +527,8 @@ impl StatementExecutor {
}
fn set_variables(&self, set_var: SetVariables, query_ctx: QueryContextRef) -> Result<Output> {
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));
}
+1 -1
View File
@@ -850,7 +850,7 @@ pub fn show_query_option(
query_ctx: QueryContextRef,
engine: &dyn crate::QueryEngine,
) -> Result<Option<Output>> {
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.")
+34
View File
@@ -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::<Vec<_>>()
.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(&quoted));
assert_eq!(
object_name_to_string_unquoted(&unquoted),
object_name_to_string_unquoted(&quoted)
);
}
}