@@ -21,7 +21,9 @@ use super::{
2121use crate :: catalog:: { ColumnCatalog , ColumnRef , ColumnSummary , TableName } ;
2222use crate :: errors:: DatabaseError ;
2323use crate :: execution:: dql:: join:: joins_nullable;
24+ use crate :: expression:: agg:: AggKind ;
2425use crate :: expression:: { AliasType , BinaryOperator } ;
26+ use crate :: planner:: operator:: aggregate:: AggregateOperator ;
2527use crate :: planner:: operator:: function_scan:: FunctionScanOperator ;
2628use crate :: planner:: operator:: insert:: InsertOperator ;
2729use crate :: planner:: operator:: join:: JoinCondition ;
@@ -30,13 +32,15 @@ use crate::planner::operator::union::UnionOperator;
3032use crate :: planner:: { Childrens , LogicalPlan , SchemaOutput } ;
3133use crate :: storage:: Transaction ;
3234use crate :: types:: tuple:: { Schema , SchemaRef } ;
35+ use crate :: types:: value:: Utf8Type ;
36+ use crate :: types:: LogicalType :: Char ;
3337use crate :: types:: { ColumnId , LogicalType } ;
3438use 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
4145impl < ' 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