Skip to content

feat: Add Window UDFs to FFI Crate #16261

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions datafusion/ffi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ pub mod table_source;
pub mod udaf;
pub mod udf;
pub mod udtf;
pub mod udwf;
pub mod util;
pub mod volatility;

Expand Down
9 changes: 7 additions & 2 deletions datafusion/ffi/src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ use crate::{catalog_provider::FFI_CatalogProvider, udtf::FFI_TableFunction};

use crate::udaf::FFI_AggregateUDF;

use crate::udwf::FFI_WindowUDF;

use super::{table_provider::FFI_TableProvider, udf::FFI_ScalarUDF};
use arrow::array::RecordBatch;
use async_provider::create_async_table_provider;
Expand All @@ -40,8 +42,8 @@ use datafusion::{
};
use sync_provider::create_sync_table_provider;
use udf_udaf_udwf::{
create_ffi_abs_func, create_ffi_random_func, create_ffi_stddev_func,
create_ffi_sum_func, create_ffi_table_func,
create_ffi_abs_func, create_ffi_random_func, create_ffi_rank_func,
create_ffi_stddev_func, create_ffi_sum_func, create_ffi_table_func,
};

mod async_provider;
Expand Down Expand Up @@ -76,6 +78,8 @@ pub struct ForeignLibraryModule {
/// Createa grouping UDAF using stddev
pub create_stddev_udaf: extern "C" fn() -> FFI_AggregateUDF,

pub create_rank_udwf: extern "C" fn() -> FFI_WindowUDF,

pub version: extern "C" fn() -> u64,
}

Expand Down Expand Up @@ -125,6 +129,7 @@ pub fn get_foreign_library_module() -> ForeignLibraryModuleRef {
create_table_function: create_ffi_table_func,
create_sum_udaf: create_ffi_sum_func,
create_stddev_udaf: create_ffi_stddev_func,
create_rank_udwf: create_ffi_rank_func,
version: super::version,
}
.leak_into_prefix()
Expand Down
20 changes: 18 additions & 2 deletions datafusion/ffi/src/tests/udf_udaf_udwf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,17 @@
// specific language governing permissions and limitations
// under the License.

use crate::{udaf::FFI_AggregateUDF, udf::FFI_ScalarUDF, udtf::FFI_TableFunction};
use crate::{
udaf::FFI_AggregateUDF, udf::FFI_ScalarUDF, udtf::FFI_TableFunction,
udwf::FFI_WindowUDF,
};
use datafusion::{
catalog::TableFunctionImpl,
functions::math::{abs::AbsFunc, random::RandomFunc},
functions_aggregate::{stddev::Stddev, sum::Sum},
functions_table::generate_series::RangeFunc,
logical_expr::{AggregateUDF, ScalarUDF},
functions_window::rank::Rank,
logical_expr::{AggregateUDF, ScalarUDF, WindowUDF},
};

use std::sync::Arc;
Expand Down Expand Up @@ -55,3 +59,15 @@ pub(crate) extern "C" fn create_ffi_stddev_func() -> FFI_AggregateUDF {

udaf.into()
}

pub(crate) extern "C" fn create_ffi_rank_func() -> FFI_WindowUDF {
let udwf: Arc<WindowUDF> = Arc::new(
Rank::new(
"rank_demo".to_string(),
datafusion::functions_window::rank::RankType::Basic,
)
.into(),
);

udwf.into()
}
Loading