Skip to content

Commit 2403f79

Browse files
authored
Some small optimizations (#1424)
1 parent 9934f3d commit 2403f79

File tree

3 files changed

+17
-23
lines changed

3 files changed

+17
-23
lines changed

src/ast/helpers/stmt_data_loading.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -108,11 +108,14 @@ impl fmt::Display for StageParamsObject {
108108
impl fmt::Display for DataLoadingOptions {
109109
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
110110
if !self.options.is_empty() {
111+
let mut first = false;
111112
for option in &self.options {
112-
write!(f, "{}", option)?;
113-
if !option.eq(self.options.last().unwrap()) {
114-
write!(f, " ")?;
113+
if !first {
114+
first = true;
115+
} else {
116+
f.write_str(" ")?;
115117
}
118+
write!(f, "{}", option)?;
116119
}
117120
}
118121
Ok(())

src/ast/mod.rs

+8-17
Original file line numberDiff line numberDiff line change
@@ -4511,30 +4511,21 @@ impl fmt::Display for Statement {
45114511
options,
45124512
query,
45134513
} => {
4514-
if table_flag.is_some() {
4515-
write!(
4516-
f,
4517-
"CACHE {table_flag} TABLE {table_name}",
4518-
table_flag = table_flag.clone().unwrap(),
4519-
table_name = table_name,
4520-
)?;
4514+
if let Some(table_flag) = table_flag {
4515+
write!(f, "CACHE {table_flag} TABLE {table_name}")?;
45214516
} else {
4522-
write!(f, "CACHE TABLE {table_name}",)?;
4517+
write!(f, "CACHE TABLE {table_name}")?;
45234518
}
45244519

45254520
if !options.is_empty() {
45264521
write!(f, " OPTIONS({})", display_comma_separated(options))?;
45274522
}
45284523

4529-
let has_query = query.is_some();
4530-
if *has_as && has_query {
4531-
write!(f, " AS {query}", query = query.clone().unwrap())
4532-
} else if !has_as && has_query {
4533-
write!(f, " {query}", query = query.clone().unwrap())
4534-
} else if *has_as && !has_query {
4535-
write!(f, " AS")
4536-
} else {
4537-
Ok(())
4524+
match (*has_as, query) {
4525+
(true, Some(query)) => write!(f, " AS {query}"),
4526+
(true, None) => f.write_str(" AS"),
4527+
(false, Some(query)) => write!(f, " {query}"),
4528+
(false, None) => Ok(()),
45384529
}
45394530
}
45404531
Statement::UNCache {

src/parser/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -10552,12 +10552,12 @@ impl<'a> Parser<'a> {
1055210552
return parser_err!("Unsupported statement REPLACE", self.peek_token().location);
1055310553
}
1055410554

10555-
let insert = &mut self.parse_insert()?;
10556-
if let Statement::Insert(Insert { replace_into, .. }) = insert {
10555+
let mut insert = self.parse_insert()?;
10556+
if let Statement::Insert(Insert { replace_into, .. }) = &mut insert {
1055710557
*replace_into = true;
1055810558
}
1055910559

10560-
Ok(insert.clone())
10560+
Ok(insert)
1056110561
}
1056210562

1056310563
/// Parse an INSERT statement, returning a `Box`ed SetExpr

0 commit comments

Comments
 (0)