use std::sync::{Arc, LazyLock};
use datafusion::logical_expr::AggregateUDF;
use crate::functions::navigation_common::NavigationKind;
use navigation::NavigationAgg;
pub(crate) mod navigation;
#[cfg(test)]
pub use datafusion_functions_aggregate::first_last::first_value_udaf as mr_first_udaf;
#[cfg(test)]
pub use datafusion_functions_aggregate::first_last::last_value_udaf as mr_last_udaf;
fn new_navigation_udaf(kind: NavigationKind) -> Arc<AggregateUDF> {
Arc::new(AggregateUDF::from(NavigationAgg::new(kind)))
}
pub fn mr_first_offset_udaf() -> Arc<AggregateUDF> {
static INSTANCE: LazyLock<Arc<AggregateUDF>> =
LazyLock::new(|| new_navigation_udaf(NavigationKind::First));
Arc::clone(&INSTANCE)
}
pub fn mr_last_offset_udaf() -> Arc<AggregateUDF> {
static INSTANCE: LazyLock<Arc<AggregateUDF>> =
LazyLock::new(|| new_navigation_udaf(NavigationKind::Last));
Arc::clone(&INSTANCE)
}
pub fn mr_prev_udaf() -> Arc<AggregateUDF> {
static INSTANCE: LazyLock<Arc<AggregateUDF>> =
LazyLock::new(|| new_navigation_udaf(NavigationKind::Prev));
Arc::clone(&INSTANCE)
}
pub fn mr_next_udaf() -> Arc<AggregateUDF> {
static INSTANCE: LazyLock<Arc<AggregateUDF>> =
LazyLock::new(|| new_navigation_udaf(NavigationKind::Next));
Arc::clone(&INSTANCE)
}
pub fn functions() -> Vec<Arc<AggregateUDF>> {
vec![
mr_first_offset_udaf(),
mr_last_offset_udaf(),
mr_prev_udaf(),
mr_next_udaf(),
]
}