Skip to content

Commit 6f64b0f

Browse files
timsauceralamb
andauthored
Add Table Functions to FFI Crate (#15581)
* Initial commit adding user defined table functions to FFI crate * Minor format change * Remove duplicate test * Remove unused imports --------- Co-authored-by: Andrew Lamb <[email protected]>
1 parent 263222e commit 6f64b0f

File tree

8 files changed

+404
-3
lines changed

8 files changed

+404
-3
lines changed

Cargo.lock

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

datafusion-examples/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ bytes = { workspace = true }
6262
dashmap = { workspace = true }
6363
# note only use main datafusion crate for examples
6464
datafusion = { workspace = true, default-features = true }
65+
datafusion-ffi = { workspace = true }
6566
datafusion-proto = { workspace = true }
6667
env_logger = { workspace = true }
6768
futures = { workspace = true }

datafusion/ffi/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ crate-type = ["cdylib", "rlib"]
4040
[dependencies]
4141
abi_stable = "0.11.3"
4242
arrow = { workspace = true, features = ["ffi"] }
43+
arrow-schema = { workspace = true }
4344
async-ffi = { version = "0.5.0", features = ["abi_stable"] }
4445
async-trait = { workspace = true }
4546
datafusion = { workspace = true, default-features = false }

datafusion/ffi/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ pub mod session_config;
3535
pub mod table_provider;
3636
pub mod table_source;
3737
pub mod udf;
38+
pub mod udtf;
3839
pub mod util;
3940
pub mod volatility;
4041

datafusion/ffi/src/tests/mod.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use abi_stable::{
2727
};
2828
use catalog::create_catalog_provider;
2929

30-
use crate::catalog_provider::FFI_CatalogProvider;
30+
use crate::{catalog_provider::FFI_CatalogProvider, udtf::FFI_TableFunction};
3131

3232
use super::{table_provider::FFI_TableProvider, udf::FFI_ScalarUDF};
3333
use arrow::array::RecordBatch;
@@ -37,7 +37,7 @@ use datafusion::{
3737
common::record_batch,
3838
};
3939
use sync_provider::create_sync_table_provider;
40-
use udf_udaf_udwf::{create_ffi_abs_func, create_ffi_random_func};
40+
use udf_udaf_udwf::{create_ffi_abs_func, create_ffi_random_func, create_ffi_table_func};
4141

4242
mod async_provider;
4343
pub mod catalog;
@@ -63,6 +63,8 @@ pub struct ForeignLibraryModule {
6363

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

66+
pub create_table_function: extern "C" fn() -> FFI_TableFunction,
67+
6668
pub version: extern "C" fn() -> u64,
6769
}
6870

@@ -109,6 +111,7 @@ pub fn get_foreign_library_module() -> ForeignLibraryModuleRef {
109111
create_table: construct_table_provider,
110112
create_scalar_udf: create_ffi_abs_func,
111113
create_nullary_udf: create_ffi_random_func,
114+
create_table_function: create_ffi_table_func,
112115
version: super::version,
113116
}
114117
.leak_into_prefix()

datafusion/ffi/src/tests/udf_udaf_udwf.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,11 @@
1515
// specific language governing permissions and limitations
1616
// under the License.
1717

18-
use crate::udf::FFI_ScalarUDF;
18+
use crate::{udf::FFI_ScalarUDF, udtf::FFI_TableFunction};
1919
use datafusion::{
20+
catalog::TableFunctionImpl,
2021
functions::math::{abs::AbsFunc, random::RandomFunc},
22+
functions_table::generate_series::RangeFunc,
2123
logical_expr::ScalarUDF,
2224
};
2325

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

3537
udf.into()
3638
}
39+
40+
pub(crate) extern "C" fn create_ffi_table_func() -> FFI_TableFunction {
41+
let udtf: Arc<dyn TableFunctionImpl> = Arc::new(RangeFunc {});
42+
43+
FFI_TableFunction::new(udtf, None)
44+
}

0 commit comments

Comments
 (0)