common_function/scalars/
aggregate.rs1use std::sync::Arc;
23
24use common_query::logical_plan::AggregateFunctionCreatorRef;
25
26use crate::function_registry::FunctionRegistry;
27use crate::scalars::vector::product::VectorProductCreator;
28use crate::scalars::vector::sum::VectorSumCreator;
29
30type AggregatorCreatorFunction = Arc<dyn Fn() -> AggregateFunctionCreatorRef + Send + Sync>;
34
35#[derive(Clone)]
37pub struct AggregateFunctionMeta {
38 name: String,
39 args_count: u8,
40 creator: AggregatorCreatorFunction,
41}
42
43pub type AggregateFunctionMetaRef = Arc<AggregateFunctionMeta>;
44
45impl AggregateFunctionMeta {
46 pub fn new(name: &str, args_count: u8, creator: AggregatorCreatorFunction) -> Self {
47 Self {
48 name: name.to_string(),
49 args_count,
50 creator,
51 }
52 }
53
54 pub fn name(&self) -> String {
55 self.name.to_string()
56 }
57
58 pub fn args_count(&self) -> u8 {
59 self.args_count
60 }
61
62 pub fn create(&self) -> AggregateFunctionCreatorRef {
63 (self.creator)()
64 }
65}
66
67pub(crate) struct AggregateFunctions;
68
69impl AggregateFunctions {
70 pub fn register(registry: &FunctionRegistry) {
71 registry.register_aggregate_function(Arc::new(AggregateFunctionMeta::new(
72 "vec_sum",
73 1,
74 Arc::new(|| Arc::new(VectorSumCreator::default())),
75 )));
76 registry.register_aggregate_function(Arc::new(AggregateFunctionMeta::new(
77 "vec_product",
78 1,
79 Arc::new(|| Arc::new(VectorProductCreator::default())),
80 )));
81
82 #[cfg(feature = "geo")]
83 registry.register_aggregate_function(Arc::new(AggregateFunctionMeta::new(
84 "json_encode_path",
85 3,
86 Arc::new(|| Arc::new(super::geo::encoding::JsonPathEncodeFunctionCreator::default())),
87 )));
88 }
89}