Skip to content

Commit

Permalink
code fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
KKould committed Nov 11, 2023
1 parent 7c380f3 commit 63c43e8
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 33 deletions.
15 changes: 3 additions & 12 deletions src/binder/aggregate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,17 +87,12 @@ impl<'a, T: Transaction> Binder<'a, T> {
Ok((return_having, return_orderby))
}

fn visit_column_agg_expr(
&mut self,
expr: &mut ScalarExpression,
) -> Result<(), BindError> {
fn visit_column_agg_expr(&mut self, expr: &mut ScalarExpression) -> Result<(), BindError> {
match expr {
ScalarExpression::AggCall { .. } => {
self.context.agg_calls.push(expr.clone());
}
ScalarExpression::TypeCast { expr, .. } => {
self.visit_column_agg_expr(expr)?
}
ScalarExpression::TypeCast { expr, .. } => self.visit_column_agg_expr(expr)?,
ScalarExpression::IsNull { expr, .. } => self.visit_column_agg_expr(expr)?,
ScalarExpression::Unary { expr, .. } => self.visit_column_agg_expr(expr)?,
ScalarExpression::Alias { expr, .. } => self.visit_column_agg_expr(expr)?,
Expand All @@ -109,11 +104,7 @@ impl<'a, T: Transaction> Binder<'a, T> {
self.visit_column_agg_expr(left_expr)?;
self.visit_column_agg_expr(right_expr)?;
}
ScalarExpression::In {
expr,
args,
..
} => {
ScalarExpression::In { expr, args, .. } => {
self.visit_column_agg_expr(expr)?;
for arg in args {
self.visit_column_agg_expr(arg)?;
Expand Down
17 changes: 12 additions & 5 deletions src/binder/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@ impl<'a, T: Transaction> Binder<'a, T> {
} => self.bind_like(*negated, expr, pattern),
Expr::IsNull(expr) => self.bind_is_null(expr, false),
Expr::IsNotNull(expr) => self.bind_is_null(expr, true),
Expr::InList { expr, list, negated } => self.bind_is_in(expr, list, *negated),
Expr::InList {
expr,
list,
negated,
} => self.bind_is_in(expr, list, *negated),
_ => {
todo!()
}
Expand Down Expand Up @@ -236,10 +240,13 @@ impl<'a, T: Transaction> Binder<'a, T> {
})
}

fn bind_is_in(&mut self, expr: &Expr, list: &[Expr], negated: bool) -> Result<ScalarExpression, BindError> {
let args = list.iter()
.map(|expr| self.bind_expr(expr))
.try_collect()?;
fn bind_is_in(
&mut self,
expr: &Expr,
list: &[Expr],
negated: bool,
) -> Result<ScalarExpression, BindError> {
let args = list.iter().map(|expr| self.bind_expr(expr)).try_collect()?;

Ok(ScalarExpression::In {
negated,
Expand Down
4 changes: 3 additions & 1 deletion src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,9 @@ mod test {
println!("{}", create_table(&tuples_in_t1));

println!("not in t1:");
let tuples_not_in_t1 = kipsql.run("select * from t1 where a not in (5, 29)").await?;
let tuples_not_in_t1 = kipsql
.run("select * from t1 where a not in (5, 29)")
.await?;
println!("{}", create_table(&tuples_not_in_t1));

println!("limit:");
Expand Down
8 changes: 6 additions & 2 deletions src/expression/evaluator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,17 @@ impl ScalarExpression {
}
Ok(Arc::new(DataValue::Boolean(Some(is_null))))
}
ScalarExpression::In { expr, args, negated } => {
ScalarExpression::In {
expr,
args,
negated,
} => {
let value = expr.eval(tuple)?;
let mut is_in = false;
for arg in args {
if arg.eval(tuple)? == value {
is_in = true;
break
break;
}
}
if *negated {
Expand Down
30 changes: 17 additions & 13 deletions src/expression/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ pub enum ScalarExpression {
In {
negated: bool,
expr: Box<ScalarExpression>,
args: Vec<ScalarExpression>
}
args: Vec<ScalarExpression>,
},
}

impl ScalarExpression {
Expand Down Expand Up @@ -103,9 +103,7 @@ impl ScalarExpression {
ScalarExpression::In { expr, args, .. } => {
args.iter().all(ScalarExpression::nullable) && expr.nullable()
}
ScalarExpression::AggCall { args, .. } => {
args.iter().all(ScalarExpression::nullable)
},
ScalarExpression::AggCall { args, .. } => args.iter().all(ScalarExpression::nullable),
}
}

Expand Down Expand Up @@ -289,17 +287,23 @@ impl ScalarExpression {
Some(self.clone()),
))
}
ScalarExpression::In { negated, expr, args } => {
let args_string = args.iter()
ScalarExpression::In {
negated,
expr,
args,
} => {
let args_string = args
.iter()
.map(|arg| arg.output_columns().name().to_string())
.join(", ");
let op_string = if *negated {
"not in"
} else {
"in"
};
let op_string = if *negated { "not in" } else { "in" };
Arc::new(ColumnCatalog::new(
format!("{} {} ({})", expr.output_columns().name(), op_string, args_string),
format!(
"{} {} ({})",
expr.output_columns().name(),
op_string,
args_string
),
true,
ColumnDesc::new(LogicalType::Boolean, false, false),
Some(self.clone()),
Expand Down

0 comments on commit 63c43e8

Please sign in to comment.