Skip to content

Commit a773a73

Browse files
committed
feat: fmt
1 parent b67d83c commit a773a73

2 files changed

Lines changed: 44 additions & 30 deletions

File tree

src/binder/expr.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,14 +142,15 @@ impl<'a, T: Transaction, A: AsRef<[(&'static str, DataValue)]>> Binder<'a, '_, T
142142
trim_where: *trim_where,
143143
})
144144
}
145-
Expr::Exists {subquery, negated} => {
145+
Expr::Exists { subquery, negated } => {
146146
let (sub_query, column) = self.bind_subquery(subquery)?;
147147
let (_, sub_query) = if !self.context.is_step(&QueryBindStep::Where) {
148148
self.bind_temp_table(column, sub_query)?
149149
} else {
150150
(ScalarExpression::ColumnRef(column), sub_query)
151151
};
152-
self.context.sub_query(SubQueryType::ExistsSubQuery(*negated, sub_query));
152+
self.context
153+
.sub_query(SubQueryType::ExistsSubQuery(*negated, sub_query));
153154
Ok(ScalarExpression::Constant(DataValue::Boolean(true)))
154155
}
155156
Expr::Subquery(subquery) => {

src/binder/select.rs

Lines changed: 41 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ use super::{
2121
use crate::catalog::{ColumnCatalog, ColumnRef, ColumnSummary, TableName};
2222
use crate::errors::DatabaseError;
2323
use crate::execution::dql::join::joins_nullable;
24+
use crate::expression::agg::AggKind;
2425
use crate::expression::{AliasType, BinaryOperator};
26+
use crate::planner::operator::aggregate::AggregateOperator;
2527
use crate::planner::operator::function_scan::FunctionScanOperator;
2628
use crate::planner::operator::insert::InsertOperator;
2729
use crate::planner::operator::join::JoinCondition;
@@ -30,13 +32,15 @@ use crate::planner::operator::union::UnionOperator;
3032
use crate::planner::{Childrens, LogicalPlan, SchemaOutput};
3133
use crate::storage::Transaction;
3234
use crate::types::tuple::{Schema, SchemaRef};
35+
use crate::types::value::Utf8Type;
36+
use crate::types::LogicalType::Char;
3337
use crate::types::{ColumnId, LogicalType};
3438
use itertools::Itertools;
35-
use sqlparser::ast::{CharLengthUnits, Distinct, Expr, Ident, Join, JoinConstraint, JoinOperator, Offset, OrderByExpr, Query, Select, SelectInto, SelectItem, SetExpr, SetOperator, SetQuantifier, TableAlias, TableFactor, TableWithJoins};
36-
use crate::expression::agg::AggKind;
37-
use crate::planner::operator::aggregate::AggregateOperator;
38-
use crate::types::LogicalType::Char;
39-
use crate::types::value::Utf8Type;
39+
use sqlparser::ast::{
40+
CharLengthUnits, Distinct, Expr, Ident, Join, JoinConstraint, JoinOperator, Offset,
41+
OrderByExpr, Query, Select, SelectInto, SelectItem, SetExpr, SetOperator, SetQuantifier,
42+
TableAlias, TableFactor, TableWithJoins,
43+
};
4044

4145
impl<'a: 'b, 'b, T: Transaction, A: AsRef<[(&'static str, DataValue)]>> Binder<'a, 'b, T, A> {
4246
pub(crate) fn bind_query(&mut self, query: &Query) -> Result<LogicalPlan, DatabaseError> {
@@ -267,9 +271,9 @@ impl<'a: 'b, 'b, T: Transaction, A: AsRef<[(&'static str, DataValue)]>> Binder<'
267271
let mut tables = plan.referenced_table();
268272

269273
if let Some(TableAlias {
270-
name,
271-
columns: alias_column,
272-
}) = alias
274+
name,
275+
columns: alias_column,
276+
}) = alias
273277
{
274278
if tables.len() > 1 {
275279
return Err(DatabaseError::UnsupportedStmt(
@@ -291,9 +295,9 @@ impl<'a: 'b, 'b, T: Transaction, A: AsRef<[(&'static str, DataValue)]>> Binder<'
291295
let mut plan = FunctionScanOperator::build(function);
292296

293297
if let Some(TableAlias {
294-
name,
295-
columns: alias_column,
296-
}) = alias
298+
name,
299+
columns: alias_column,
300+
}) = alias
297301
{
298302
table_alias = Some(Arc::new(name.value.to_lowercase()));
299303

@@ -600,17 +604,13 @@ impl<'a: 'b, 'b, T: Transaction, A: AsRef<[(&'static str, DataValue)]>> Binder<'
600604
let (mut plan, join_ty) = match sub_query {
601605
SubQueryType::SubQuery(plan) => (plan, JoinType::Inner),
602606
SubQueryType::ExistsSubQuery(is_not, plan) => {
603-
let limit = LimitOperator::build(
604-
None,
605-
Some(1),
606-
plan,
607-
);
607+
let limit = LimitOperator::build(None, Some(1), plan);
608608
let mut agg = AggregateOperator::build(
609609
limit,
610610
vec![ScalarExpression::AggCall {
611611
distinct: false,
612612
kind: AggKind::Count,
613-
args: vec![ScalarExpression::Constant(DataValue::Utf8{
613+
args: vec![ScalarExpression::Constant(DataValue::Utf8 {
614614
value: "*".to_string(),
615615
ty: Utf8Type::Fixed(1),
616616
unit: CharLengthUnits::Characters,
@@ -620,19 +620,32 @@ impl<'a: 'b, 'b, T: Transaction, A: AsRef<[(&'static str, DataValue)]>> Binder<'
620620
vec![],
621621
false,
622622
);
623-
let filter = FilterOperator::build(ScalarExpression::Binary {
624-
op: if is_not { BinaryOperator::NotEq } else { BinaryOperator::Eq },
625-
left_expr: Box::new(ScalarExpression::ColumnRef(agg.output_schema()[0].clone())),
626-
right_expr: Box::new(ScalarExpression::Constant(DataValue::Int32(1))),
627-
evaluator: None,
628-
ty: LogicalType::Boolean,
629-
},
630-
agg,
631-
false);
623+
let filter = FilterOperator::build(
624+
ScalarExpression::Binary {
625+
op: if is_not {
626+
BinaryOperator::NotEq
627+
} else {
628+
BinaryOperator::Eq
629+
},
630+
left_expr: Box::new(ScalarExpression::ColumnRef(
631+
agg.output_schema()[0].clone(),
632+
)),
633+
right_expr: Box::new(ScalarExpression::Constant(DataValue::Int32(
634+
1,
635+
))),
636+
evaluator: None,
637+
ty: LogicalType::Boolean,
638+
},
639+
agg,
640+
false,
641+
);
632642
let projection = ProjectOperator {
633-
exprs: vec![ScalarExpression::Constant(DataValue::Int32(1))]
643+
exprs: vec![ScalarExpression::Constant(DataValue::Int32(1))],
634644
};
635-
let plan = LogicalPlan::new(Operator::Project(projection), Childrens::Only(filter));
645+
let plan = LogicalPlan::new(
646+
Operator::Project(projection),
647+
Childrens::Only(filter),
648+
);
636649
children = LJoinOperator::build(
637650
children,
638651
plan,

0 commit comments

Comments
 (0)