Skip to content

Some small optimizations #1424

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Sep 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/ast/helpers/stmt_data_loading.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
Expand Down
25 changes: 8 additions & 17 deletions src/ast/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4490,30 +4490,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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is certainly good

(true, Some(query)) => write!(f, " AS {query}"),
(true, None) => f.write_str(" AS"),
(false, Some(query)) => write!(f, " {query}"),
(false, None) => Ok(()),
}
}
Statement::UNCache {
Expand Down
6 changes: 3 additions & 3 deletions src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()?;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

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
Expand Down
Loading