datafusion_functions_window/lib.rs
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
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
//! Window Function packages for [DataFusion].
//!
//! This crate contains a collection of various window function packages for DataFusion,
//! implemented using the extension API.
//!
//! [DataFusion]: https://crates.io/crates/datafusion
//!
use std::sync::Arc;
use log::debug;
use datafusion_expr::registry::FunctionRegistry;
use datafusion_expr::WindowUDF;
#[macro_use]
pub mod macros;
pub mod cume_dist;
pub mod lead_lag;
pub mod ntile;
pub mod rank;
pub mod row_number;
mod utils;
/// Fluent-style API for creating `Expr`s
pub mod expr_fn {
pub use super::cume_dist::cume_dist;
pub use super::lead_lag::lag;
pub use super::lead_lag::lead;
pub use super::ntile::ntile;
pub use super::rank::{dense_rank, percent_rank, rank};
pub use super::row_number::row_number;
}
/// Returns all default window functions
pub fn all_default_window_functions() -> Vec<Arc<WindowUDF>> {
vec![
cume_dist::cume_dist_udwf(),
row_number::row_number_udwf(),
lead_lag::lead_udwf(),
lead_lag::lag_udwf(),
rank::rank_udwf(),
rank::dense_rank_udwf(),
rank::percent_rank_udwf(),
ntile::ntile_udwf(),
]
}
/// Registers all enabled packages with a [`FunctionRegistry`]
pub fn register_all(
registry: &mut dyn FunctionRegistry,
) -> datafusion_common::Result<()> {
let functions: Vec<Arc<WindowUDF>> = all_default_window_functions();
functions.into_iter().try_for_each(|fun| {
let existing_udwf = registry.register_udwf(fun)?;
if let Some(existing_udwf) = existing_udwf {
debug!("Overwrite existing UDWF: {}", existing_udwf.name());
}
Ok(()) as datafusion_common::Result<()>
})?;
Ok(())
}