1515// specific language governing permissions and limitations
1616// under the License.
1717
18- use std :: any :: Any ;
18+ use crate :: { AvgDecimal , EvalMode } ;
1919use arrow:: array:: { ArrayRef , BooleanArray } ;
2020use arrow:: datatypes:: { DataType , FieldRef } ;
2121use datafusion:: common:: { DataFusionError , Result as DFResult , ScalarValue } ;
22- use datafusion:: logical_expr:: { Accumulator , AggregateUDFImpl , EmitTo , GroupsAccumulator , ReversedUDAF , Signature } ;
2322use datafusion:: logical_expr:: function:: { AccumulatorArgs , StateFieldsArgs } ;
2423use datafusion:: logical_expr:: type_coercion:: aggregates:: avg_return_type;
2524use datafusion:: logical_expr:: Volatility :: Immutable ;
26- use crate :: { AvgDecimal , EvalMode } ;
25+ use datafusion:: logical_expr:: {
26+ Accumulator , AggregateUDFImpl , EmitTo , GroupsAccumulator , ReversedUDAF , Signature ,
27+ } ;
28+ use std:: any:: Any ;
2729
2830#[ derive( Debug , Clone , PartialEq , Eq , Hash ) ]
2931pub struct AvgInt {
@@ -34,13 +36,13 @@ pub struct AvgInt {
3436impl AvgInt {
3537 pub fn try_new ( data_type : DataType , eval_mode : EvalMode ) -> DFResult < Self > {
3638 match data_type {
37- DataType :: Int8 | DataType :: Int16 | DataType :: Int32 | DataType :: Int64 => {
38- Ok ( Self {
39+ DataType :: Int8 | DataType :: Int16 | DataType :: Int32 | DataType :: Int64 => Ok ( Self {
3940 signature : Signature :: user_defined ( Immutable ) ,
40- eval_mode
41- } )
42- } ,
43- _ => { Err ( DataFusionError :: Internal ( "inalid data type for AvgInt" . to_string ( ) ) ) }
41+ eval_mode,
42+ } ) ,
43+ _ => Err ( DataFusionError :: Internal (
44+ "inalid data type for AvgInt" . to_string ( ) ,
45+ ) ) ,
4446 }
4547 }
4648}
@@ -58,7 +60,7 @@ impl AggregateUDFImpl for AvgInt {
5860 ReversedUDAF :: Identical
5961 }
6062
61- fn signature ( & self ) -> & Signature {
63+ fn signature ( & self ) -> & Signature {
6264 & self . signature
6365 }
6466
@@ -70,7 +72,10 @@ impl AggregateUDFImpl for AvgInt {
7072 true
7173 }
7274
73- fn accumulator ( & self , acc_args : AccumulatorArgs ) -> datafusion:: common:: Result < Box < dyn Accumulator > > {
75+ fn accumulator (
76+ & self ,
77+ acc_args : AccumulatorArgs ,
78+ ) -> datafusion:: common:: Result < Box < dyn Accumulator > > {
7479 todo ! ( )
7580 }
7681
@@ -82,7 +87,10 @@ impl AggregateUDFImpl for AvgInt {
8287 false
8388 }
8489
85- fn create_groups_accumulator ( & self , _args : AccumulatorArgs ) -> datafusion:: common:: Result < Box < dyn GroupsAccumulator > > {
90+ fn create_groups_accumulator (
91+ & self ,
92+ _args : AccumulatorArgs ,
93+ ) -> datafusion:: common:: Result < Box < dyn GroupsAccumulator > > {
8694 Ok ( Box :: new ( AvgIntGroupsAccumulator :: new ( self . eval_mode ) ) )
8795 }
8896
@@ -91,37 +99,36 @@ impl AggregateUDFImpl for AvgInt {
9199 }
92100}
93101
94- struct AvgIntegerAccumulator {
102+ struct AvgIntegerAccumulator {
95103 sum : Option < i64 > ,
96104 count : u64 ,
97105 eval_mode : EvalMode ,
98106}
99107
100108impl AvgIntegerAccumulator {
101109 fn new ( eval_mode : EvalMode ) -> Self {
102- Self {
103- sum : Some ( 0 ) ,
110+ Self {
111+ sum : Some ( 0 ) ,
104112 count : 0 ,
105- eval_mode
113+ eval_mode,
106114 }
107115 }
108116}
109117
110- impl Accumulator for AvgIntegerAccumulator {
111-
112- }
118+ impl Accumulator for AvgIntegerAccumulator { }
113119
114- struct AvgIntGroupsAccumulator {
115-
116- }
117-
118- impl AvgIntGroupsAccumulator {
119-
120- }
120+ struct AvgIntGroupsAccumulator { }
121121
122+ impl AvgIntGroupsAccumulator { }
122123
123124impl GroupsAccumulator for AvgIntGroupsAccumulator {
124- fn update_batch ( & mut self , values : & [ ArrayRef ] , group_indices : & [ usize ] , opt_filter : Option < & BooleanArray > , total_num_groups : usize ) -> datafusion:: common:: Result < ( ) > {
125+ fn update_batch (
126+ & mut self ,
127+ values : & [ ArrayRef ] ,
128+ group_indices : & [ usize ] ,
129+ opt_filter : Option < & BooleanArray > ,
130+ total_num_groups : usize ,
131+ ) -> datafusion:: common:: Result < ( ) > {
125132 todo ! ( )
126133 }
127134
@@ -133,11 +140,17 @@ impl GroupsAccumulator for AvgIntGroupsAccumulator {
133140 todo ! ( )
134141 }
135142
136- fn merge_batch ( & mut self , values : & [ ArrayRef ] , group_indices : & [ usize ] , opt_filter : Option < & BooleanArray > , total_num_groups : usize ) -> datafusion:: common:: Result < ( ) > {
143+ fn merge_batch (
144+ & mut self ,
145+ values : & [ ArrayRef ] ,
146+ group_indices : & [ usize ] ,
147+ opt_filter : Option < & BooleanArray > ,
148+ total_num_groups : usize ,
149+ ) -> datafusion:: common:: Result < ( ) > {
137150 todo ! ( )
138151 }
139152
140153 fn size ( & self ) -> usize {
141154 todo ! ( )
142155 }
143- }
156+ }
0 commit comments