datafusion_functions_window/
lib.rs1#![cfg_attr(test, allow(clippy::needless_pass_by_value))]
19#![doc(
20 html_logo_url = "https://raw.githubusercontent.com/apache/datafusion/19fe44cf2f30cbdd63d4a4f52c74055163c6cc38/docs/logos/standalone_logo/logo_original.svg",
21 html_favicon_url = "https://raw.githubusercontent.com/apache/datafusion/19fe44cf2f30cbdd63d4a4f52c74055163c6cc38/docs/logos/standalone_logo/logo_original.svg"
22)]
23#![cfg_attr(docsrs, feature(doc_cfg))]
24#![cfg_attr(not(test), deny(clippy::clone_on_ref_ptr))]
27#![deny(clippy::allow_attributes)]
29
30use std::sync::Arc;
38
39use log::debug;
40
41use datafusion_expr::WindowUDF;
42use datafusion_expr::registry::FunctionRegistry;
43
44#[macro_use]
45pub mod macros;
46
47pub mod cume_dist;
48pub mod lead_lag;
49pub mod nth_value;
50pub mod ntile;
51pub mod rank;
52pub mod row_number;
53
54pub mod planner;
55
56mod utils;
57
58pub mod expr_fn {
60 pub use super::cume_dist::cume_dist;
61 pub use super::lead_lag::lag;
62 pub use super::lead_lag::lead;
63 pub use super::nth_value::{first_value, last_value, nth_value};
64 pub use super::ntile::ntile;
65 pub use super::rank::{dense_rank, percent_rank, rank};
66 pub use super::row_number::row_number;
67}
68
69pub fn all_default_window_functions() -> Vec<Arc<WindowUDF>> {
71 vec![
72 cume_dist::cume_dist_udwf(),
73 row_number::row_number_udwf(),
74 lead_lag::lead_udwf(),
75 lead_lag::lag_udwf(),
76 rank::rank_udwf(),
77 rank::dense_rank_udwf(),
78 rank::percent_rank_udwf(),
79 ntile::ntile_udwf(),
80 nth_value::first_value_udwf(),
81 nth_value::last_value_udwf(),
82 nth_value::nth_value_udwf(),
83 ]
84}
85pub fn register_all(
87 registry: &mut dyn FunctionRegistry,
88) -> datafusion_common::Result<()> {
89 let functions: Vec<Arc<WindowUDF>> = all_default_window_functions();
90
91 functions.into_iter().try_for_each(|fun| {
92 let existing_udwf = registry.register_udwf(fun)?;
93 if let Some(existing_udwf) = existing_udwf {
94 debug!("Overwrite existing UDWF: {}", existing_udwf.name());
95 }
96 Ok(()) as datafusion_common::Result<()>
97 })?;
98
99 Ok(())
100}