@@ -60,22 +60,102 @@ impl AggregateFnRef {
6060#[ cfg( test) ]
6161mod tests {
6262 use prost:: Message ;
63+ use vortex_error:: VortexResult ;
64+ use vortex_error:: vortex_panic;
6365 use vortex_proto:: expr as pb;
6466 use vortex_session:: VortexSession ;
6567
68+ use crate :: ArrayRef ;
69+ use crate :: Columnar ;
70+ use crate :: ExecutionCtx ;
71+ use crate :: aggregate_fn:: AggregateFnId ;
6672 use crate :: aggregate_fn:: AggregateFnRef ;
73+ use crate :: aggregate_fn:: AggregateFnVTable ;
6774 use crate :: aggregate_fn:: AggregateFnVTableExt ;
6875 use crate :: aggregate_fn:: EmptyOptions ;
69- use crate :: aggregate_fn:: fns:: sum:: Sum ;
7076 use crate :: aggregate_fn:: session:: AggregateFnSession ;
7177 use crate :: aggregate_fn:: session:: AggregateFnSessionExt ;
78+ use crate :: dtype:: DType ;
79+ use crate :: scalar:: Scalar ;
80+
81+ /// A minimal serializable aggregate function used solely to exercise the serde round-trip.
82+ #[ derive( Clone , Debug ) ]
83+ struct TestAgg ;
84+
85+ impl AggregateFnVTable for TestAgg {
86+ type Options = EmptyOptions ;
87+ type Partial = ( ) ;
88+
89+ fn id ( & self ) -> AggregateFnId {
90+ AggregateFnId :: new_ref ( "vortex.test.proto" )
91+ }
92+
93+ fn serialize ( & self , _options : & Self :: Options ) -> VortexResult < Option < Vec < u8 > > > {
94+ Ok ( Some ( vec ! [ ] ) )
95+ }
96+
97+ fn deserialize (
98+ & self ,
99+ _metadata : & [ u8 ] ,
100+ _session : & VortexSession ,
101+ ) -> VortexResult < Self :: Options > {
102+ Ok ( EmptyOptions )
103+ }
104+
105+ fn return_dtype ( & self , _options : & Self :: Options , input_dtype : & DType ) -> Option < DType > {
106+ Some ( input_dtype. clone ( ) )
107+ }
108+
109+ fn partial_dtype ( & self , options : & Self :: Options , input_dtype : & DType ) -> Option < DType > {
110+ self . return_dtype ( options, input_dtype)
111+ }
112+
113+ fn empty_partial (
114+ & self ,
115+ _options : & Self :: Options ,
116+ _input_dtype : & DType ,
117+ ) -> VortexResult < Self :: Partial > {
118+ Ok ( ( ) )
119+ }
120+
121+ fn combine_partials (
122+ & self ,
123+ _partial : & mut Self :: Partial ,
124+ _other : Scalar ,
125+ ) -> VortexResult < ( ) > {
126+ Ok ( ( ) )
127+ }
128+
129+ fn to_scalar ( & self , _partial : & Self :: Partial ) -> VortexResult < Scalar > {
130+ vortex_panic ! ( "TestAgg is for serde tests only" ) ;
131+ }
132+
133+ fn reset ( & self , _partial : & mut Self :: Partial ) { }
134+
135+ fn is_saturated ( & self , _partial : & Self :: Partial ) -> bool {
136+ true
137+ }
138+
139+ fn accumulate (
140+ & self ,
141+ _state : & mut Self :: Partial ,
142+ _batch : & Columnar ,
143+ _ctx : & mut ExecutionCtx ,
144+ ) -> VortexResult < ( ) > {
145+ Ok ( ( ) )
146+ }
147+
148+ fn finalize ( & self , partials : ArrayRef ) -> VortexResult < ArrayRef > {
149+ Ok ( partials)
150+ }
151+ }
72152
73153 #[ test]
74154 fn aggregate_fn_serde ( ) {
75155 let session = VortexSession :: empty ( ) . with :: < AggregateFnSession > ( ) ;
76- session. aggregate_fns ( ) . register ( Sum ) ;
156+ session. aggregate_fns ( ) . register ( TestAgg ) ;
77157
78- let agg_fn = Sum . bind ( EmptyOptions ) ;
158+ let agg_fn = TestAgg . bind ( EmptyOptions ) ;
79159
80160 let serialized = agg_fn. serialize_proto ( ) . unwrap ( ) ;
81161 let buf = serialized. encode_to_vec ( ) ;
0 commit comments