mirror of
https://github.com/GreptimeTeam/greptimedb.git
synced 2026-10-17 01:12:27 +00:00
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:
@@ -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));
|
||||
}
|
||||
|
||||
|
||||
@@ -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.")
|
||||
|
||||
@@ -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("ed));
|
||||
assert_eq!(
|
||||
object_name_to_string_unquoted(&unquoted),
|
||||
object_name_to_string_unquoted("ed)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user