Skip to content

Commit

Permalink
QueryWithSetting rename to StatementWithSettings
Browse files Browse the repository at this point in the history
  • Loading branch information
TCeason committed Oct 30, 2024
1 parent 09f4e84 commit 4d0f921
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 25 deletions.
8 changes: 4 additions & 4 deletions src/query/ast/src/ast/statements/statement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ use crate::ast::Query;
#[derive(Debug, Clone, PartialEq, Drive, DriveMut)]
pub enum Statement {
Query(Box<Query>),
QueryWithSetting {
StatementWithSettings {
settings: Option<Settings>,
query: Box<Statement>,
stmt: Box<Statement>,
},
Explain {
kind: ExplainKind,
Expand Down Expand Up @@ -418,7 +418,7 @@ impl Display for Statement {
}
write!(f, " {query}")?;
}
Statement::QueryWithSetting { settings, query } => {
Statement::StatementWithSettings { settings, stmt } => {
if let Some(setting) = settings {
write!(f, "SETTINGS (")?;
let ids = &setting.identifiers;
Expand All @@ -433,7 +433,7 @@ impl Display for Statement {
}
write!(f, ") ")?;
}
write!(f, "{query}")?;
write!(f, "{stmt}")?;
}
Statement::ExplainAnalyze {
partial,
Expand Down
14 changes: 2 additions & 12 deletions src/query/ast/src/parser/statement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,9 @@ pub fn statement_body(i: Input) -> IResult<Statement> {
SETTINGS ~ #query_statement_setting? ~ #statement_body
},
|(_, opt_settings, statement)| {
Ok(Statement::QueryWithSetting {
Ok(Statement::StatementWithSettings {
settings: opt_settings,
query: Box::new(statement),
stmt: Box::new(statement),
})
},
);
Expand Down Expand Up @@ -2821,16 +2821,6 @@ pub fn query_statement_setting(i: Input) -> IResult<Settings> {
identifiers: ids,
values: SetValues::Expr(values.into_iter().map(|x| x.into()).collect()),
}
// let (ids, values): (Vec<Identifier>, Vec<Expr>) = query_setting
// .iter()
// .map(|(id, value)| (id.clone(), value.clone()))
// .unzip();
//
// Ok(Settings {
// set_type: SetType::SettingsQuery,
// identifiers: ids,
// values: SetValues::Expr(values.into_iter().map(Into::into).collect()),
// })
},
);
rule!(#query_set: "(SETTING_NAME = VALUE, ...)")(i)
Expand Down
4 changes: 2 additions & 2 deletions src/query/sql/src/planner/binder/binder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,8 @@ impl<'a> Binder {
}
}

Statement::QueryWithSetting { settings, query} => {
self.bind_query_setting(bind_context, settings, query).await?
Statement::StatementWithSettings { settings, stmt } => {
self.bind_statement_settings(bind_context, settings, stmt).await?
}

Statement::Explain { query, options, kind } => {
Expand Down
2 changes: 1 addition & 1 deletion src/query/sql/src/planner/binder/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ mod presign;
mod project;
mod project_set;
mod qualify;
mod query_setting;
mod replace;
mod scalar;
mod scalar_common;
Expand All @@ -48,6 +47,7 @@ mod set;
mod set_priority;
mod show;
mod sort;
mod statement_settings;
mod stream_column_factory;
mod system;
mod table;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,17 @@ use crate::Binder;
use crate::TypeChecker;

impl Binder {
pub async fn bind_query_setting(
pub async fn bind_statement_settings(
&mut self,
bind_context: &mut BindContext,
settings: &Option<Settings>,
inner: &Statement,
) -> Result<Plan> {
if let Statement::QueryWithSetting { .. } = inner {
if let Statement::StatementWithSettings { .. } = inner {
return Err(ErrorCode::SyntaxException("Invalid statement"));
}

let mut query_settings: HashMap<String, String> = HashMap::new();
let mut statement_settings: HashMap<String, String> = HashMap::new();
if let Some(settings) = settings {
let Settings {
set_type,
Expand Down Expand Up @@ -117,7 +117,7 @@ impl Binder {
})?;
}

query_settings.entry(var.to_string()).or_insert(value);
statement_settings.entry(var.to_string()).or_insert(value);
}
}
_ => {
Expand All @@ -126,7 +126,7 @@ impl Binder {
}
self.ctx
.get_shared_settings()
.set_batch_settings(&query_settings, true)?;
.set_batch_settings(&statement_settings, true)?;
self.bind_statement(bind_context, inner).await
} else {
self.bind_statement(bind_context, inner).await
Expand Down
2 changes: 1 addition & 1 deletion src/query/sql/src/planner/planner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ impl Planner {
pub fn get_query_kind(stmt: &Statement) -> QueryKind {
match stmt {
Statement::Query { .. } => QueryKind::Query,
Statement::QueryWithSetting { query, .. } => get_query_kind(query),
Statement::StatementWithSettings { stmt, .. } => get_query_kind(stmt),
Statement::CopyIntoTable(_) => QueryKind::CopyIntoTable,
Statement::CopyIntoLocation(_) => QueryKind::CopyIntoLocation,
Statement::Explain { .. } => QueryKind::Explain,
Expand Down

0 comments on commit 4d0f921

Please sign in to comment.