vortex_array/aggregate_fn/
session.rs1use std::sync::Arc;
5
6use parking_lot::RwLock;
7use vortex_session::Ref;
8use vortex_session::SessionExt;
9use vortex_session::registry::Registry;
10use vortex_utils::aliases::hash_map::HashMap;
11
12use crate::aggregate_fn::AggregateFnId;
13use crate::aggregate_fn::AggregateFnPluginRef;
14use crate::aggregate_fn::AggregateFnVTable;
15use crate::aggregate_fn::kernels::DynAggregateKernel;
16use crate::aggregate_fn::kernels::DynGroupedAggregateKernel;
17use crate::arrays::ChunkedVTable;
18use crate::arrays::chunked::compute::aggregate::ChunkedArrayAggregate;
19use crate::vtable::ArrayId;
20
21pub type AggregateFnRegistry = Registry<AggregateFnPluginRef>;
23
24#[derive(Debug)]
26pub struct AggregateFnSession {
27 registry: AggregateFnRegistry,
28
29 pub(super) kernels: RwLock<HashMap<KernelKey, &'static dyn DynAggregateKernel>>,
30 pub(super) grouped_kernels: RwLock<HashMap<KernelKey, &'static dyn DynGroupedAggregateKernel>>,
31}
32
33type KernelKey = (ArrayId, Option<AggregateFnId>);
34
35impl Default for AggregateFnSession {
36 fn default() -> Self {
37 let this = Self {
38 registry: AggregateFnRegistry::default(),
39 kernels: RwLock::new(HashMap::default()),
40 grouped_kernels: RwLock::new(HashMap::default()),
41 };
42
43 this.register_aggregate_kernel(ChunkedVTable::ID, None, &ChunkedArrayAggregate);
45
46 this
47 }
48}
49
50impl AggregateFnSession {
51 pub fn registry(&self) -> &AggregateFnRegistry {
53 &self.registry
54 }
55
56 pub fn register<V: AggregateFnVTable>(&self, vtable: V) {
59 self.registry
60 .register(vtable.id(), Arc::new(vtable) as AggregateFnPluginRef);
61 }
62
63 pub fn register_aggregate_kernel(
65 &self,
66 array_id: ArrayId,
67 agg_fn_id: Option<AggregateFnId>,
68 kernel: &'static dyn DynAggregateKernel,
69 ) {
70 self.kernels.write().insert((array_id, agg_fn_id), kernel);
71 }
72}
73
74pub trait AggregateFnSessionExt: SessionExt {
76 fn aggregate_fns(&self) -> Ref<'_, AggregateFnSession> {
78 self.get::<AggregateFnSession>()
79 }
80}
81impl<S: SessionExt> AggregateFnSessionExt for S {}