datafusion_functions_extra/
lib.rs

1// Licensed to the Apache Software Foundation (ASF) under one
2// or more contributor license agreements.  See the NOTICE file
3// distributed with this work for additional information
4// regarding copyright ownership.  The ASF licenses this file
5// to you under the Apache License, Version 2.0 (the
6// "License"); you may not use this file except in compliance
7// with the License.  You may obtain a copy of the License at
8//
9//   http://www.apache.org/licenses/LICENSE-2.0
10//
11// Unless required by applicable law or agreed to in writing,
12// software distributed under the License is distributed on an
13// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14// KIND, either express or implied.  See the License for the
15// specific language governing permissions and limitations
16// under the License.
17
18#![deny(warnings)]
19
20use datafusion::{common as df_common, error, execution, logical_expr};
21use log::debug;
22use mode::mode_udaf;
23use std::sync;
24
25#[macro_use]
26pub mod macros;
27pub mod common;
28pub mod kurtosis;
29pub mod kurtosis_pop;
30pub mod max_min_by;
31pub mod mode;
32pub mod skewness;
33pub mod expr_extra_fn {
34    pub use super::kurtosis::kurtosis;
35    pub use super::kurtosis_pop::kurtosis_pop;
36    pub use super::max_min_by::max_by;
37    pub use super::max_min_by::min_by;
38    pub use super::mode::mode;
39    pub use super::skewness::skewness;
40}
41
42pub fn all_extra_aggregate_functions() -> Vec<sync::Arc<logical_expr::AggregateUDF>> {
43    vec![
44        mode_udaf(),
45        max_min_by::max_by_udaf(),
46        max_min_by::min_by_udaf(),
47        kurtosis::kurtosis_udaf(),
48        skewness::skewness_udaf(),
49        kurtosis_pop::kurtosis_pop_udaf(),
50    ]
51}
52
53/// Registers all enabled packages with a [`FunctionRegistry`]
54pub fn register_all_extra_functions(
55    registry: &mut dyn execution::FunctionRegistry,
56) -> df_common::Result<()> {
57    let functions: Vec<sync::Arc<logical_expr::AggregateUDF>> = all_extra_aggregate_functions();
58
59    functions.into_iter().try_for_each(|udf| {
60        let existing_udaf = registry.register_udaf(udf)?;
61        if let Some(existing_udaf) = existing_udaf {
62            debug!("Overwrite existing UDAF: {}", existing_udaf.name());
63        }
64        Ok(()) as error::Result<()>
65    })?;
66
67    Ok(())
68}