@@ -10,15 +10,20 @@ use std::hash::Hash;
1010use std:: hash:: Hasher ;
1111use std:: sync:: Arc ;
1212
13+ use arcref:: ArcRef ;
1314use vortex_error:: VortexExpect ;
1415use vortex_error:: VortexResult ;
16+ use vortex_error:: vortex_bail;
17+ use vortex_error:: vortex_err;
18+ use vortex_session:: VortexSession ;
1519use vortex_utils:: debug_with:: DebugWith ;
1620
1721use crate :: aggregate_fn:: AccumulatorRef ;
1822use crate :: aggregate_fn:: AggregateFnId ;
1923use crate :: aggregate_fn:: AggregateFnVTable ;
2024use crate :: aggregate_fn:: GroupedAccumulatorRef ;
2125use crate :: aggregate_fn:: options:: AggregateFnOptions ;
26+ use crate :: aggregate_fn:: session:: AggregateFnSessionExt ;
2227use crate :: aggregate_fn:: typed:: AggregateFnInner ;
2328use crate :: aggregate_fn:: typed:: DynAggregateFn ;
2429use crate :: dtype:: DType ;
@@ -34,6 +39,37 @@ use crate::dtype::DType;
3439pub struct AggregateFnRef ( pub ( super ) Arc < dyn DynAggregateFn > ) ;
3540
3641impl AggregateFnRef {
42+ /// Deserialize an aggregate function from its ID and serialized metadata bytes.
43+ ///
44+ /// Looks up the aggregate function plugin by ID in the session's registry
45+ /// and delegates deserialization to it.
46+ pub fn deserialize ( id : & str , metadata : & [ u8 ] , session : & VortexSession ) -> VortexResult < Self > {
47+ let agg_fn_id: AggregateFnId = ArcRef :: new_arc ( Arc :: from ( id) ) ;
48+ let plugin = session
49+ . aggregate_fns ( )
50+ . registry ( )
51+ . find ( & agg_fn_id)
52+ . ok_or_else ( || vortex_err ! ( "unknown aggregate function id: {}" , id) ) ?;
53+ let agg_fn = plugin. deserialize ( metadata, session) ?;
54+
55+ if agg_fn. id ( ) != agg_fn_id {
56+ vortex_bail ! (
57+ "Aggregate function ID mismatch: expected {}, got {}" ,
58+ agg_fn_id,
59+ agg_fn. id( )
60+ ) ;
61+ }
62+
63+ Ok ( agg_fn)
64+ }
65+
66+ /// Serialize this aggregate function's options to bytes.
67+ ///
68+ /// Returns `Ok(None)` if the function is not serializable.
69+ pub fn serialize ( & self ) -> VortexResult < Option < Vec < u8 > > > {
70+ self . 0 . options_serialize ( )
71+ }
72+
3773 /// Returns the ID of this aggregate function.
3874 pub fn id ( & self ) -> AggregateFnId {
3975 self . 0 . id ( )
0 commit comments