From 7c81e4e54eefaf07aeb125686acc28e8f32751ba Mon Sep 17 00:00:00 2001 From: Thomas Dagenais Date: Thu, 12 Sep 2024 13:51:11 +0000 Subject: [PATCH 1/4] Fix formatting logic in DataLoadingOptions Beyond efficiency, the previous impl might not add a space if the there where duplicated options. --- src/ast/helpers/stmt_data_loading.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/ast/helpers/stmt_data_loading.rs b/src/ast/helpers/stmt_data_loading.rs index a259e664b..a3dc8d6d2 100644 --- a/src/ast/helpers/stmt_data_loading.rs +++ b/src/ast/helpers/stmt_data_loading.rs @@ -103,11 +103,14 @@ impl fmt::Display for StageParamsObject { impl fmt::Display for DataLoadingOptions { fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { if !self.options.is_empty() { + let mut first = false; for option in &self.options { - write!(f, "{}", option)?; - if !option.eq(self.options.last().unwrap()) { - write!(f, " ")?; + if !first { + first = true; + } else { + f.write_str(" ")?; } + write!(f, "{}", option)?; } } Ok(()) From 11a46553da73c6c4e54a457a0702885a964bbeb4 Mon Sep 17 00:00:00 2001 From: Thomas Dagenais Date: Thu, 12 Sep 2024 13:56:15 +0000 Subject: [PATCH 2/4] Avoid clone of query in Display for Statement Also converted code to more idomatic removing an unwrap. --- --- src/ast/mod.rs | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/src/ast/mod.rs b/src/ast/mod.rs index 6c851906c..f5a8c3fc2 100644 --- a/src/ast/mod.rs +++ b/src/ast/mod.rs @@ -4505,15 +4505,11 @@ impl fmt::Display for Statement { write!(f, " OPTIONS({})", display_comma_separated(options))?; } - let has_query = query.is_some(); - if *has_as && has_query { - write!(f, " AS {query}", query = query.clone().unwrap()) - } else if !has_as && has_query { - write!(f, " {query}", query = query.clone().unwrap()) - } else if *has_as && !has_query { - write!(f, " AS") - } else { - Ok(()) + match (*has_as, query) { + (true, Some(query)) => write!(f, " AS {query}"), + (true, None) => f.write_str(" AS"), + (false, Some(query)) => write!(f, " {query}"), + (false, None) => Ok(()), } } Statement::UNCache { From 8d431c273731b0c4554ea2fb63a6d01b77b77cea Mon Sep 17 00:00:00 2001 From: Thomas Dagenais Date: Thu, 12 Sep 2024 14:00:11 +0000 Subject: [PATCH 3/4] Avoid Clone in parse_replace --- src/parser/mod.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/parser/mod.rs b/src/parser/mod.rs index 8d920b2ce..7e205e827 100644 --- a/src/parser/mod.rs +++ b/src/parser/mod.rs @@ -10477,12 +10477,12 @@ impl<'a> Parser<'a> { return parser_err!("Unsupported statement REPLACE", self.peek_token().location); } - let insert = &mut self.parse_insert()?; - if let Statement::Insert(Insert { replace_into, .. }) = insert { + let mut insert = self.parse_insert()?; + if let Statement::Insert(Insert { replace_into, .. }) = &mut insert { *replace_into = true; } - Ok(insert.clone()) + Ok(insert) } /// Parse an INSERT statement, returning a `Box`ed SetExpr From 112c5374bd37012d3e5798a8efa5f3a5718bdbd4 Mon Sep 17 00:00:00 2001 From: Thomas Dagenais Date: Thu, 12 Sep 2024 15:16:03 +0000 Subject: [PATCH 4/4] Avoid clone of table flag in statement Display --- src/ast/mod.rs | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/ast/mod.rs b/src/ast/mod.rs index f5a8c3fc2..42ed3fd43 100644 --- a/src/ast/mod.rs +++ b/src/ast/mod.rs @@ -4490,15 +4490,10 @@ impl fmt::Display for Statement { options, query, } => { - if table_flag.is_some() { - write!( - f, - "CACHE {table_flag} TABLE {table_name}", - table_flag = table_flag.clone().unwrap(), - table_name = table_name, - )?; + if let Some(table_flag) = table_flag { + write!(f, "CACHE {table_flag} TABLE {table_name}")?; } else { - write!(f, "CACHE TABLE {table_name}",)?; + write!(f, "CACHE TABLE {table_name}")?; } if !options.is_empty() {