-
Notifications
You must be signed in to change notification settings - Fork 180
Expand file tree
/
Copy pathsession.rs
More file actions
125 lines (108 loc) · 4.36 KB
/
Copy pathsession.rs
File metadata and controls
125 lines (108 loc) · 4.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: Copyright the Vortex contributors
use std::any::Any;
use std::sync::Arc;
use parking_lot::RwLock;
use vortex_session::Ref;
use vortex_session::SessionExt;
use vortex_session::SessionVar;
use vortex_session::registry::Registry;
use vortex_utils::aliases::hash_map::HashMap;
use crate::aggregate_fn::AggregateFnId;
use crate::aggregate_fn::AggregateFnPluginRef;
use crate::aggregate_fn::AggregateFnVTable;
use crate::aggregate_fn::fns::all_non_distinct::AllNonDistinct;
use crate::aggregate_fn::fns::first::First;
use crate::aggregate_fn::fns::is_constant::IsConstant;
use crate::aggregate_fn::fns::is_sorted::IsSorted;
use crate::aggregate_fn::fns::last::Last;
use crate::aggregate_fn::fns::min_max::MinMax;
use crate::aggregate_fn::fns::nan_count::NanCount;
use crate::aggregate_fn::fns::null_count::NullCount;
use crate::aggregate_fn::fns::sum::Sum;
use crate::aggregate_fn::fns::uncompressed_size_in_bytes::UncompressedSizeInBytes;
use crate::aggregate_fn::kernels::DynAggregateKernel;
use crate::aggregate_fn::kernels::DynGroupedAggregateKernel;
use crate::array::ArrayId;
use crate::array::VTable;
use crate::arrays::Chunked;
use crate::arrays::Dict;
use crate::arrays::chunked::compute::aggregate::ChunkedArrayAggregate;
use crate::arrays::dict::compute::is_constant::DictIsConstantKernel;
use crate::arrays::dict::compute::is_sorted::DictIsSortedKernel;
use crate::arrays::dict::compute::min_max::DictMinMaxKernel;
/// Registry of aggregate function vtables.
pub type AggregateFnRegistry = Registry<AggregateFnPluginRef>;
/// Session state for aggregate function vtables.
#[derive(Debug)]
pub struct AggregateFnSession {
registry: AggregateFnRegistry,
pub(super) kernels: RwLock<HashMap<KernelKey, &'static dyn DynAggregateKernel>>,
pub(super) grouped_kernels: RwLock<HashMap<KernelKey, &'static dyn DynGroupedAggregateKernel>>,
}
impl SessionVar for AggregateFnSession {
fn as_any(&self) -> &dyn Any {
self
}
fn as_any_mut(&mut self) -> &mut dyn Any {
self
}
}
type KernelKey = (ArrayId, Option<AggregateFnId>);
impl Default for AggregateFnSession {
fn default() -> Self {
let this = Self {
registry: AggregateFnRegistry::default(),
kernels: RwLock::new(HashMap::default()),
grouped_kernels: RwLock::new(HashMap::default()),
};
// Register the built-in aggregate functions
this.register(AllNonDistinct);
this.register(First);
this.register(IsConstant);
this.register(IsSorted);
this.register(Last);
this.register(MinMax);
this.register(NanCount);
this.register(NullCount);
this.register(Sum);
this.register(UncompressedSizeInBytes);
// Register the built-in aggregate kernels.
this.register_aggregate_kernel(Chunked.id(), None::<AggregateFnId>, &ChunkedArrayAggregate);
this.register_aggregate_kernel(Dict.id(), Some(MinMax.id()), &DictMinMaxKernel);
this.register_aggregate_kernel(Dict.id(), Some(IsConstant.id()), &DictIsConstantKernel);
this.register_aggregate_kernel(Dict.id(), Some(IsSorted.id()), &DictIsSortedKernel);
this
}
}
impl AggregateFnSession {
/// Returns the aggregate function registry.
pub fn registry(&self) -> &AggregateFnRegistry {
&self.registry
}
/// Register an aggregate function vtable in the session, replacing any existing vtable with
/// the same ID.
pub fn register<V: AggregateFnVTable>(&self, vtable: V) {
self.registry
.register(vtable.id(), Arc::new(vtable) as AggregateFnPluginRef);
}
/// Register an aggregate function kernel for a specific aggregate function and array type.
pub fn register_aggregate_kernel(
&self,
array_id: impl Into<ArrayId>,
agg_fn_id: Option<impl Into<AggregateFnId>>,
kernel: &'static dyn DynAggregateKernel,
) {
self.kernels
.write()
.insert((array_id.into(), agg_fn_id.map(|id| id.into())), kernel);
}
}
/// Extension trait for accessing aggregate function session data.
pub trait AggregateFnSessionExt: SessionExt {
/// Returns the aggregate function vtable registry.
fn aggregate_fns(&self) -> Ref<'_, AggregateFnSession> {
self.get::<AggregateFnSession>()
}
}
impl<S: SessionExt> AggregateFnSessionExt for S {}