Skip to content

Commit

Permalink
fix the ridiculously deep nested if-let chain in binder.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
longfangsong committed Aug 21, 2024
1 parent 8e87650 commit 216d82c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 16 deletions.
2 changes: 2 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![feature(let_chains)]

#[macro_use]
extern crate lazy_static;

Expand Down
29 changes: 13 additions & 16 deletions src/sql/planner/binder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,22 +251,19 @@ impl<'a> Binder<'a> {
let group_by_expr = group_by.first().unwrap();
let se = bind_scalar(ctx, &from_scope, group_by_expr)?;
if let ScalarExpr::FunctionCall(name, args) = se {
if name.eq(&String::from("tumblingWindow")) && args.len() == 2 {
if let ScalarExpr::Literal(datum) = args[0].clone() {
if let Datum::String(s) = datum {
if s.eq(&String::from("ss")) {
if let ScalarExpr::Literal(datum) = args[1].clone() {
if let Datum::Int(v) = datum {
plan = Plan::Window {
window_type: WindowType::TumblingWindow,
length: v,
input: Box::new(plan),
};
group_by.remove(0);
}
}
}
}
if name == "tumblingWindow" && args.len() == 2 {
if let (
ScalarExpr::Literal(Datum::String(s)),
ScalarExpr::Literal(Datum::Int(v)),
) = (&args[0], &args[1])
&& s == "ss"
{
plan = Plan::Window {
window_type: WindowType::TumblingWindow,
length: *v,
input: Box::new(plan),
};
group_by.remove(0);
}
}
}
Expand Down

0 comments on commit 216d82c

Please sign in to comment.