Some small optimizations (#1424)

This commit is contained in:
Thomas Dagenais 2024-09-21 06:25:14 -04:00 committed by GitHub
parent 9934f3d931
commit 2403f79f55
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 17 additions and 23 deletions

View file

@ -108,11 +108,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(())

View file

@ -4511,30 +4511,21 @@ 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() {
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 {

View file

@ -10552,12 +10552,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