Skip to content

Add Table Functions to FFI Crate #15581

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 5 commits into from
Apr 12, 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
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions datafusion-examples/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ bytes = { workspace = true }
dashmap = { workspace = true }
# note only use main datafusion crate for examples
datafusion = { workspace = true, default-features = true }
datafusion-ffi = { workspace = true }
datafusion-proto = { workspace = true }
env_logger = { workspace = true }
futures = { workspace = true }
Expand Down
1 change: 1 addition & 0 deletions datafusion/ffi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ crate-type = ["cdylib", "rlib"]
[dependencies]
abi_stable = "0.11.3"
arrow = { workspace = true, features = ["ffi"] }
arrow-schema = { workspace = true }
async-ffi = { version = "0.5.0", features = ["abi_stable"] }
async-trait = { workspace = true }
datafusion = { workspace = true, default-features = false }
Expand Down
1 change: 1 addition & 0 deletions datafusion/ffi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ pub mod session_config;
pub mod table_provider;
pub mod table_source;
pub mod udf;
pub mod udtf;
pub mod util;
pub mod volatility;

Expand Down
7 changes: 5 additions & 2 deletions datafusion/ffi/src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use abi_stable::{
};
use catalog::create_catalog_provider;

use crate::catalog_provider::FFI_CatalogProvider;
use crate::{catalog_provider::FFI_CatalogProvider, udtf::FFI_TableFunction};

use super::{table_provider::FFI_TableProvider, udf::FFI_ScalarUDF};
use arrow::array::RecordBatch;
Expand All @@ -37,7 +37,7 @@ use datafusion::{
common::record_batch,
};
use sync_provider::create_sync_table_provider;
use udf_udaf_udwf::{create_ffi_abs_func, create_ffi_random_func};
use udf_udaf_udwf::{create_ffi_abs_func, create_ffi_random_func, create_ffi_table_func};

mod async_provider;
pub mod catalog;
Expand All @@ -63,6 +63,8 @@ pub struct ForeignLibraryModule {

pub create_nullary_udf: extern "C" fn() -> FFI_ScalarUDF,

pub create_table_function: extern "C" fn() -> FFI_TableFunction,

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

Expand Down Expand Up @@ -109,6 +111,7 @@ pub fn get_foreign_library_module() -> ForeignLibraryModuleRef {
create_table: construct_table_provider,
create_scalar_udf: create_ffi_abs_func,
create_nullary_udf: create_ffi_random_func,
create_table_function: create_ffi_table_func,
version: super::version,
}
.leak_into_prefix()
Expand Down
10 changes: 9 additions & 1 deletion datafusion/ffi/src/tests/udf_udaf_udwf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@
// specific language governing permissions and limitations
// under the License.

use crate::udf::FFI_ScalarUDF;
use crate::{udf::FFI_ScalarUDF, udtf::FFI_TableFunction};
use datafusion::{
catalog::TableFunctionImpl,
functions::math::{abs::AbsFunc, random::RandomFunc},
functions_table::generate_series::RangeFunc,
logical_expr::ScalarUDF,
};

Expand All @@ -34,3 +36,9 @@ pub(crate) extern "C" fn create_ffi_random_func() -> FFI_ScalarUDF {

udf.into()
}

pub(crate) extern "C" fn create_ffi_table_func() -> FFI_TableFunction {
let udtf: Arc<dyn TableFunctionImpl> = Arc::new(RangeFunc {});

FFI_TableFunction::new(udtf, None)
}
Loading