1- use std:: collections:: HashSet ;
21use ahash:: RandomState ;
32use itertools:: Itertools ;
43use sqlparser:: ast:: { Expr , OrderByExpr } ;
4+ use std:: collections:: HashSet ;
55
6- use crate :: {
7- expression:: ScalarExpression ,
8- planner:: {
9- operator:: { aggregate:: AggregateOperator , sort:: SortField } ,
10- } ,
11- } ;
126use crate :: binder:: { BindError , InputRefType } ;
137use crate :: planner:: LogicalPlan ;
148use crate :: storage:: Storage ;
9+ use crate :: {
10+ expression:: ScalarExpression ,
11+ planner:: operator:: { aggregate:: AggregateOperator , sort:: SortField } ,
12+ } ;
1513
1614use super :: Binder ;
1715
@@ -40,7 +38,8 @@ impl<S: Storage> Binder<S> {
4038 select_list : & mut [ ScalarExpression ] ,
4139 groupby : & [ Expr ] ,
4240 ) -> Result < ( ) , BindError > {
43- self . validate_groupby_illegal_column ( select_list, groupby) . await ?;
41+ self . validate_groupby_illegal_column ( select_list, groupby)
42+ . await ?;
4443
4544 for gb in groupby {
4645 let mut expr = self . bind_expr ( gb) . await ?;
@@ -89,24 +88,25 @@ impl<S: Storage> Binder<S> {
8988 Ok ( ( return_having, return_orderby) )
9089 }
9190
92- fn visit_column_agg_expr ( & mut self , expr : & mut ScalarExpression , is_select : bool ) -> Result < ( ) , BindError > {
91+ fn visit_column_agg_expr (
92+ & mut self ,
93+ expr : & mut ScalarExpression ,
94+ is_select : bool ,
95+ ) -> Result < ( ) , BindError > {
9396 match expr {
9497 ScalarExpression :: AggCall {
9598 ty : return_type, ..
9699 } => {
97100 let ty = return_type. clone ( ) ;
98101 if is_select {
99102 let index = self . context . input_ref_index ( InputRefType :: AggCall ) ;
100- let input_ref = ScalarExpression :: InputRef {
101- index,
102- ty,
103- } ;
103+ let input_ref = ScalarExpression :: InputRef { index, ty } ;
104104 match std:: mem:: replace ( expr, input_ref) {
105105 ScalarExpression :: AggCall {
106106 kind,
107107 args,
108108 ty,
109- distinct
109+ distinct,
110110 } => {
111111 self . context . agg_calls . push ( ScalarExpression :: AggCall {
112112 distinct,
@@ -125,14 +125,13 @@ impl<S: Storage> Binder<S> {
125125 . find_position ( |agg_expr| agg_expr == & expr)
126126 . ok_or_else ( || BindError :: AggMiss ( format ! ( "{:?}" , expr) ) ) ?;
127127
128- let _ = std:: mem:: replace ( expr, ScalarExpression :: InputRef {
129- index,
130- ty,
131- } ) ;
128+ let _ = std:: mem:: replace ( expr, ScalarExpression :: InputRef { index, ty } ) ;
132129 }
133130 }
134131
135- ScalarExpression :: TypeCast { expr, .. } => self . visit_column_agg_expr ( expr, is_select) ?,
132+ ScalarExpression :: TypeCast { expr, .. } => {
133+ self . visit_column_agg_expr ( expr, is_select) ?
134+ }
136135 ScalarExpression :: IsNull { expr } => self . visit_column_agg_expr ( expr, is_select) ?,
137136 ScalarExpression :: Unary { expr, .. } => self . visit_column_agg_expr ( expr, is_select) ?,
138137 ScalarExpression :: Alias { expr, .. } => self . visit_column_agg_expr ( expr, is_select) ?,
@@ -185,7 +184,8 @@ impl<S: Storage> Binder<S> {
185184 group_raw_exprs. push ( expr) ;
186185 }
187186 }
188- let mut group_raw_set: HashSet < & ScalarExpression , RandomState > = HashSet :: from_iter ( group_raw_exprs. iter ( ) ) ;
187+ let mut group_raw_set: HashSet < & ScalarExpression , RandomState > =
188+ HashSet :: from_iter ( group_raw_exprs. iter ( ) ) ;
189189
190190 for expr in select_items {
191191 if expr. has_agg_call ( & self . context ) {
@@ -195,19 +195,17 @@ impl<S: Storage> Binder<S> {
195195 group_raw_set. remove ( expr) ;
196196
197197 if !group_raw_exprs. iter ( ) . contains ( expr) {
198- return Err ( BindError :: AggMiss (
199- format ! (
200- "{:?} must appear in the GROUP BY clause or be used in an aggregate function" ,
201- expr
202- )
203- ) ) ;
198+ return Err ( BindError :: AggMiss ( format ! (
199+ "{:?} must appear in the GROUP BY clause or be used in an aggregate function" ,
200+ expr
201+ ) ) ) ;
204202 }
205203 }
206204
207205 if !group_raw_set. is_empty ( ) {
208- return Err ( BindError :: AggMiss (
209- format ! ( "In the GROUP BY clause the field must be in the select clause" )
210- ) ) ;
206+ return Err ( BindError :: AggMiss ( format ! (
207+ "In the GROUP BY clause the field must be in the select clause"
208+ ) ) ) ;
211209 }
212210
213211 Ok ( ( ) )
0 commit comments