Skip to content

Commit

Permalink
Simplify, clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
Dandandan committed Feb 7, 2021
1 parent 63289c1 commit 6f66c87
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 40 deletions.
41 changes: 4 additions & 37 deletions src/ast/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,8 @@ pub enum Expr {
/// SUBSTRING(<expr> [FROM <expr>] [FOR <expr>])
Substring {
expr: Box<Expr>,
substring_from: Option<SubstringFrom>,
substring_for: Option<SubstringFor>,
substring_from: Option<Box<Expr>>,
substring_for: Option<Box<Expr>>,
},
/// `expr COLLATE collation`
Collate {
Expand Down Expand Up @@ -347,10 +347,10 @@ impl fmt::Display for Expr {
} => {
write!(f, "SUBSTRING({}", expr)?;
if let Some(from_part) = substring_from {
write!(f, " {}", from_part)?;
write!(f, " FROM {}", from_part)?;
}
if let Some(from_part) = substring_for {
write!(f, " {}", from_part)?;
write!(f, " FOR {}", from_part)?;
}

write!(f, ")")
Expand Down Expand Up @@ -460,39 +460,6 @@ impl fmt::Display for WindowFrameBound {
}
}

#[derive(Debug, Clone, PartialEq, Eq, Hash)]
/// FROM part of SUBSTRING(<expr> [FROM <expr>])
pub enum SubstringFrom {
///
FromExpr(Box<Expr>),
}

impl fmt::Display for SubstringFrom {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
SubstringFrom::FromExpr(expr) => {
write!(f, "FROM {}", expr)
}
}
}
}

/// FROM part of SUBSTRING(<expr> [TO <expr>])
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum SubstringFor {
ForExpr(Box<Expr>),
}

impl fmt::Display for SubstringFor {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
SubstringFor::ForExpr(expr) => {
write!(f, "FOR {}", expr)
}
}
}
}

#[derive(Debug, Clone, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub enum AddDropSync {
Expand Down
4 changes: 2 additions & 2 deletions src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -623,8 +623,8 @@ impl<'a> Parser<'a> {

Ok(Expr::Substring {
expr: Box::new(expr),
substring_from: from_expr.map(|x| SubstringFrom::FromExpr(Box::new(x))),
substring_for: to_expr.map(|x| SubstringFor::ForExpr(Box::new(x))),
substring_from: from_expr.map(Box::new),
substring_for: to_expr.map(Box::new),
})
}

Expand Down
2 changes: 1 addition & 1 deletion tests/sqlparser_regression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ macro_rules! tpch_tests {
fn $name() {
let dialect = GenericDialect {};

let res = Parser::parse_sql(&dialect, QUERIES[$value -1]);
let _res = Parser::parse_sql(&dialect, QUERIES[$value -1]);
}
)*
}
Expand Down

0 comments on commit 6f66c87

Please sign in to comment.