use std::sync::Arc;
use vortex_error::VortexResult;
use vortex_session::VortexSession;
use crate::aggregate_fn::AggregateFn;
use crate::aggregate_fn::AggregateFnId;
use crate::aggregate_fn::AggregateFnRef;
use crate::aggregate_fn::AggregateFnVTable;
pub type AggregateFnPluginRef = Arc<dyn AggregateFnPlugin>;
pub trait AggregateFnPlugin: 'static + Send + Sync {
fn id(&self) -> AggregateFnId;
fn deserialize(&self, metadata: &[u8], session: &VortexSession)
-> VortexResult<AggregateFnRef>;
}
impl std::fmt::Debug for dyn AggregateFnPlugin {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_tuple("AggregateFnPlugin")
.field(&self.id())
.finish()
}
}
impl<V: AggregateFnVTable> AggregateFnPlugin for V {
fn id(&self) -> AggregateFnId {
AggregateFnVTable::id(self)
}
fn deserialize(
&self,
metadata: &[u8],
session: &VortexSession,
) -> VortexResult<AggregateFnRef> {
let options = AggregateFnVTable::deserialize(self, metadata, session)?;
Ok(AggregateFn::new(self.clone(), options).erased())
}
}