Skip to content

Commit

Permalink
fix clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
andylokandy committed May 11, 2022
1 parent 5e8cefc commit b5b2e5a
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 20 deletions.
2 changes: 1 addition & 1 deletion common/ast/src/ast/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ pub enum JoinOperator {

#[derive(Debug, Clone, PartialEq)]
pub enum JoinCondition<'a> {
On(Expr<'a>),
On(Box<Expr<'a>>),
Using(Vec<Identifier<'a>>),
Natural,
None,
Expand Down
6 changes: 3 additions & 3 deletions common/ast/src/parser/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ pub enum ExprElement<'a> {
trim_where: Option<(TrimWhere, Box<Expr<'a>>)>,
},
/// A literal value, such as string, number, date or NULL
Literal(Literal),
Literal { lit: Literal },
/// `Count(*)` expression
CountAll,
/// `(foo, bar)`
Expand Down Expand Up @@ -361,7 +361,7 @@ impl<'a, I: Iterator<Item = WithSpan<'a>>> PrattParser<I> for ExprParser {
expr,
trim_where,
},
ExprElement::Literal(lit) => Expr::Literal {
ExprElement::Literal { lit } => Expr::Literal {
span: elem.span.0,
lit,
},
Expand Down Expand Up @@ -722,7 +722,7 @@ pub fn expr_element(i: Input) -> IResult<WithSpan> {
);
let binary_op = map(binary_op, |op| ExprElement::BinaryOp { op });
let unary_op = map(unary_op, |op| ExprElement::UnaryOp { op });
let literal = map(literal, ExprElement::Literal);
let literal = map(literal, |lit| ExprElement::Literal { lit });
let map_access = map(map_access, |accessor| ExprElement::MapAccess { accessor });

let (rest, (span, elem)) = consumed(alt((
Expand Down
2 changes: 1 addition & 1 deletion common/ast/src/parser/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ pub fn joined_tables(i: Input) -> IResult<TableReference> {
rule! {
ON ~ #expr
},
|(_, expr)| JoinCondition::On(expr),
|(_, expr)| JoinCondition::On(Box::new(expr)),
);
let join_condition_using = map(
rule! {
Expand Down
20 changes: 13 additions & 7 deletions query/src/sql/planner/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,9 @@ impl Metadata {
match expr {
Expr::ColumnRef { column, .. } => Ok(column.name.clone()),

Expr::Literal(literal) => Ok(format!("{}", literal)),
Expr::Literal { lit, .. } => Ok(format!("{lit}")),

Expr::CountAll => Ok("count(*)".to_string()),
Expr::CountAll { .. } => Ok("count(*)".to_string()),

Expr::FunctionCall {
name,
Expand All @@ -155,13 +155,15 @@ impl Metadata {
})
}

Expr::IsNull { expr, not } => Ok(format!(
Expr::IsNull { expr, not, .. } => Ok(format!(
"{} IS {}NULL",
expr,
if *not { "NOT " } else { "" }
)),

Expr::InList { expr, list, not } => {
Expr::InList {
expr, list, not, ..
} => {
let mut w = vec![];
write!(&mut w, "{} {}IN (", expr, if *not { "NOT " } else { "" })?;
for (i, expr) in list.iter().enumerate() {
Expand All @@ -180,6 +182,7 @@ impl Metadata {
low,
high,
not,
..
} => Ok(format!(
"{} {}BETWEEN {} AND {}",
expr,
Expand All @@ -188,9 +191,11 @@ impl Metadata {
high
)),

Expr::BinaryOp { op, left, right } => Ok(format!("{} {} {}", left, op, right)),
Expr::BinaryOp {
op, left, right, ..
} => Ok(format!("{} {} {}", left, op, right)),

Expr::UnaryOp { op, expr } => Ok(format!("{} {}", op, expr)),
Expr::UnaryOp { op, expr, .. } => Ok(format!("{} {}", op, expr)),

Expr::Cast {
expr, target_type, ..
Expand All @@ -200,6 +205,7 @@ impl Metadata {
expr,
substring_from,
substring_for,
..
} => Ok(format!(
"SUBSTRING({}{}{})",
expr,
Expand Down Expand Up @@ -266,5 +272,5 @@ pub fn optimize_remove_count_args(name: &str, distinct: bool, args: &[&Expr]) ->
&& !distinct
&& args
.iter()
.all(|expr| matches!(expr, Expr::Literal(literal) if *literal!=Literal::Null))
.all(|expr| matches!(expr, Expr::Literal{lit,..} if *lit!=Literal::Null))
}
26 changes: 18 additions & 8 deletions query/src/sql/planner/semantic/type_check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ impl<'a> TypeChecker<'a> {
database: _,
table,
column,
..
} => {
let column = self
.bind_context
Expand All @@ -88,7 +89,7 @@ impl<'a> TypeChecker<'a> {
Ok((BoundColumnRef { column }.into(), data_type))
}

Expr::IsNull { expr, not } => {
Expr::IsNull { expr, not, .. } => {
let func_name = if *not {
"is_not_null".to_string()
} else {
Expand All @@ -99,7 +100,9 @@ impl<'a> TypeChecker<'a> {
.await
}

Expr::InList { expr, list, not } => {
Expr::InList {
expr, list, not, ..
} => {
let func_name = if *not {
"not_in".to_string()
} else {
Expand All @@ -119,6 +122,7 @@ impl<'a> TypeChecker<'a> {
low,
high,
not,
..
} => {
if !*not {
// Rewrite `expr BETWEEN low AND high`
Expand Down Expand Up @@ -157,12 +161,16 @@ impl<'a> TypeChecker<'a> {
}
}

Expr::BinaryOp { op, left, right } => {
Expr::BinaryOp {
op, left, right, ..
} => {
self.resolve_binary_op(op, &**left, &**right, required_type)
.await
}

Expr::UnaryOp { op, expr } => self.resolve_unary_op(op, &**expr, required_type).await,
Expr::UnaryOp { op, expr, .. } => {
self.resolve_unary_op(op, &**expr, required_type).await
}

Expr::Cast {
expr, target_type, ..
Expand All @@ -188,6 +196,7 @@ impl<'a> TypeChecker<'a> {
expr,
substring_from,
substring_for,
..
} => {
let mut arguments = vec![&**expr];
match (substring_from, substring_for) {
Expand All @@ -205,8 +214,8 @@ impl<'a> TypeChecker<'a> {
.await
}

Expr::Literal(literal) => {
let value = self.parse_literal(literal, required_type)?;
Expr::Literal { lit, .. } => {
let value = self.parse_literal(lit, required_type)?;
let data_type = value.data_type();
Ok((ConstantExpr { value }.into(), data_type))
}
Expand All @@ -216,6 +225,7 @@ impl<'a> TypeChecker<'a> {
name,
args,
params,
..
} => {
let args: Vec<&Expr> = args.iter().collect();
let func_name = name.name.as_str();
Expand Down Expand Up @@ -267,7 +277,7 @@ impl<'a> TypeChecker<'a> {
}
}

Expr::CountAll => {
Expr::CountAll { .. } => {
let agg_func = AggregateFunctionFactory::instance().get("count", vec![], vec![])?;

Ok((
Expand All @@ -283,7 +293,7 @@ impl<'a> TypeChecker<'a> {
))
}

Expr::Subquery(subquery) => self.resolve_subquery(subquery, false, None).await,
Expr::Subquery { subquery, .. } => self.resolve_subquery(subquery, false, None).await,

_ => Err(ErrorCode::UnImplement(format!(
"Unsupported expr: {:?}",
Expand Down

0 comments on commit b5b2e5a

Please sign in to comment.