Replace Option<Vec<T>> with Vec<T>

Vectors can already represent the absence of any arguments (i.e., by
being empty), so there is no need to wrap them in an Option.
This commit is contained in:
Nikhil Benesch 2019-05-22 11:39:45 -04:00
parent 4f944dd4aa
commit 5652b4676c
No known key found for this signature in database
GPG key ID: F7386C5DEADABA7F
3 changed files with 25 additions and 25 deletions

View file

@ -9,7 +9,7 @@ pub struct SQLQuery {
/// SELECT or UNION / EXCEPT / INTECEPT
pub body: SQLSetExpr,
/// ORDER BY
pub order_by: Option<Vec<SQLOrderByExpr>>,
pub order_by: Vec<SQLOrderByExpr>,
/// LIMIT
pub limit: Option<ASTNode>,
}
@ -21,8 +21,8 @@ impl ToString for SQLQuery {
s += &format!("WITH {} ", comma_separated_string(&self.ctes))
}
s += &self.body.to_string();
if let Some(ref order_by) = self.order_by {
s += &format!(" ORDER BY {}", comma_separated_string(order_by));
if !self.order_by.is_empty() {
s += &format!(" ORDER BY {}", comma_separated_string(&self.order_by));
}
if let Some(ref limit) = self.limit {
s += &format!(" LIMIT {}", limit.to_string());
@ -106,7 +106,7 @@ pub struct SQLSelect {
/// WHERE
pub selection: Option<ASTNode>,
/// GROUP BY
pub group_by: Option<Vec<ASTNode>>,
pub group_by: Vec<ASTNode>,
/// HAVING
pub having: Option<ASTNode>,
}
@ -127,8 +127,8 @@ impl ToString for SQLSelect {
if let Some(ref selection) = self.selection {
s += &format!(" WHERE {}", selection.to_string());
}
if let Some(ref group_by) = self.group_by {
s += &format!(" GROUP BY {}", comma_separated_string(group_by));
if !self.group_by.is_empty() {
s += &format!(" GROUP BY {}", comma_separated_string(&self.group_by));
}
if let Some(ref having) = self.having {
s += &format!(" HAVING {}", having.to_string());
@ -193,7 +193,7 @@ pub enum TableFactor {
/// Arguments of a table-valued function, as supported by Postgres
/// and MSSQL. Note that deprecated MSSQL `FROM foo (NOLOCK)` syntax
/// will also be parsed as `args`.
args: Option<Vec<ASTNode>>,
args: Vec<ASTNode>,
/// MSSQL-specific `WITH (...)` hints such as NOLOCK.
with_hints: Vec<ASTNode>,
},
@ -213,7 +213,7 @@ impl ToString for TableFactor {
with_hints,
} => {
let mut s = name.to_string();
if let Some(args) = args {
if !args.is_empty() {
s += &format!("({})", comma_separated_string(args))
};
if let Some(alias) = alias {

View file

@ -1198,9 +1198,9 @@ impl Parser {
let body = self.parse_query_body(0)?;
let order_by = if self.parse_keywords(vec!["ORDER", "BY"]) {
Some(self.parse_order_by_expr_list()?)
self.parse_order_by_expr_list()?
} else {
None
vec![]
};
let limit = if self.parse_keyword("LIMIT") {
@ -1318,9 +1318,9 @@ impl Parser {
};
let group_by = if self.parse_keywords(vec!["GROUP", "BY"]) {
Some(self.parse_expr_list()?)
self.parse_expr_list()?
} else {
None
vec![]
};
let having = if self.parse_keyword("HAVING") {
@ -1351,9 +1351,9 @@ impl Parser {
let name = self.parse_object_name()?;
// Postgres, MSSQL: table-valued functions:
let args = if self.consume_token(&Token::LParen) {
Some(self.parse_optional_args()?)
self.parse_optional_args()?
} else {
None
vec![]
};
let alias = self.parse_optional_alias(keywords::RESERVED_FOR_TABLE_ALIAS)?;
// MSSQL-specific table hints: