From 6ed11efa463ee7a8f5191126b90a9181427c499b Mon Sep 17 00:00:00 2001 From: Andrew Lamb Date: Tue, 1 Dec 2026 16:42:07 -0500 Subject: [PATCH 1/7] docs: document datafusion-ffi version compatibility Co-Authored-By: Claude Fable 5.2 --- datafusion/ffi/README.md | 39 +++++++++++++++++++++++++++++++-------- 1 file changed, 31 insertions(+), 8 deletions(-) diff --git a/datafusion/ffi/README.md b/datafusion/ffi/README.md index dae140904f966..61a33853ae9da 100644 --- a/datafusion/ffi/README.md +++ b/datafusion/ffi/README.md @@ -7,8 +7,7 @@ SPDX-FileContributor: Licensed to the Apache Software Foundation (ASF) under one # Apache DataFusion Foreign Function Interface This crate contains code to allow interoperability of [Apache DataFusion] with -functions from other libraries and/or DataFusion versions using a stable -interface. +functions from other libraries using a stable interface. One of the limitations of the Rust programming language is that there is no stable [Rust ABI] (Application Binary Interface). If a library is compiled with @@ -18,16 +17,40 @@ can access the data structures. In order to share code between libraries loaded at runtime, you need to use Rust's [FFI] (Foreign Function Interface (FFI)). The purpose of this crate is to define interfaces between DataFusion libraries -that will remain stable across different versions of DataFusion. This allows -users to write libraries that can interface between each other at runtime rather -than require compiling all of the code into a single executable. +that do not depend on the Rust compiler version or compiler settings. This +allows users to write libraries that can interface between each other at runtime +rather than require compiling all of the code into a single executable. -In general, it is recommended to run the same version of DataFusion by both the -producer and consumer of the data and functions shared across the [FFI], but -this is not strictly required. +Both sides of the [FFI] boundary must use the same major version of this crate. +See [Version Compatibility](#version-compatibility) for details. See [API Docs] for details and examples. +## Version Compatibility + +The interfaces in this crate are stable across Rust compiler versions, but they +are **not** stable across major versions of DataFusion. The producer and the +consumer of any struct shared across the [FFI] boundary must be built against +the same major version of `datafusion-ffi`. + +The `FFI_*` structs are `#[repr(C)]` structs made of function pointers and +data. Their layout changes whenever a DataFusion release adds, removes, or +changes the signature of one of those function pointers, which happens +regularly as the underlying traits such as `TableProvider` and `ExecutionPlan` +evolve. Nothing checks the layout at runtime, so exchanging these structs +between libraries built against different major versions is undefined behavior +and typically results in a crash or incorrect results rather than an error. + +When you upgrade DataFusion to a new major version, rebuild every library that +shares structs across the [FFI] boundary against that version. + +To detect a mismatch, a library can expose the `datafusion_ffi::version` +function, which returns the major version of this crate, and the application +that loads the library can compare the result with its own before using +anything else from the library. Because the layout of the `FFI_*` structs is +not guaranteed to match, perform this check through a plain `extern "C"` +function rather than through a field of one of those structs. + ## Use Cases Two use cases have been identified for this crate, but they are not intended to From bf0704c110b8f42cfbd4394307246e817f424dfe Mon Sep 17 00:00:00 2001 From: Andrew Lamb Date: Tue, 1 Dec 2026 16:51:42 -0500 Subject: [PATCH 2/7] trim --- datafusion/ffi/README.md | 31 ++++++++++++------------------- 1 file changed, 12 insertions(+), 19 deletions(-) diff --git a/datafusion/ffi/README.md b/datafusion/ffi/README.md index 61a33853ae9da..be57231e9cf48 100644 --- a/datafusion/ffi/README.md +++ b/datafusion/ffi/README.md @@ -16,10 +16,9 @@ program compiled by a different Rust compiler, there is no guarantee that you can access the data structures. In order to share code between libraries loaded at runtime, you need to use Rust's [FFI] (Foreign Function Interface (FFI)). -The purpose of this crate is to define interfaces between DataFusion libraries -that do not depend on the Rust compiler version or compiler settings. This -allows users to write libraries that can interface between each other at runtime -rather than require compiling all of the code into a single executable. +The purpose of this crate is to pass DataFusion runtime structures between libraries +running in the same process without being compiled into a single executable, such +as in different Python modules in different dynamically loaded libraries. Both sides of the [FFI] boundary must use the same major version of this crate. See [Version Compatibility](#version-compatibility) for details. @@ -28,28 +27,22 @@ See [API Docs] for details and examples. ## Version Compatibility -The interfaces in this crate are stable across Rust compiler versions, but they -are **not** stable across major versions of DataFusion. The producer and the +The interfaces in this crate are **not** stable across major versions of DataFusion, +though they are stable across Rust compiler versions. Both the producer and consumer of any struct shared across the [FFI] boundary must be built against the same major version of `datafusion-ffi`. -The `FFI_*` structs are `#[repr(C)]` structs made of function pointers and -data. Their layout changes whenever a DataFusion release adds, removes, or -changes the signature of one of those function pointers, which happens -regularly as the underlying traits such as `TableProvider` and `ExecutionPlan` -evolve. Nothing checks the layout at runtime, so exchanging these structs -between libraries built against different major versions is undefined behavior -and typically results in a crash or incorrect results rather than an error. +The `FFI_*` structs can and do change between major versions. Nothing checks the +layout at runtime, so exchanging these structs between libraries built against +different major versions is undefined behavior and can results in a crash +or incorrect results. When you upgrade DataFusion to a new major version, rebuild every library that shares structs across the [FFI] boundary against that version. -To detect a mismatch, a library can expose the `datafusion_ffi::version` -function, which returns the major version of this crate, and the application -that loads the library can compare the result with its own before using -anything else from the library. Because the layout of the `FFI_*` structs is -not guaranteed to match, perform this check through a plain `extern "C"` -function rather than through a field of one of those structs. +To detect a mismatch, it is recommended that libraries expose a way to get the +`datafusion_ffi::version`, and applications that load the library compare the +result with its own. ## Use Cases From 75416e0d2d839f9fb6741668ecd813f6e7696270 Mon Sep 17 00:00:00 2001 From: Andrew Lamb Date: Tue, 1 Dec 2026 16:52:24 -0500 Subject: [PATCH 3/7] link to docs.rs for datafusion_ffi::version Co-Authored-By: Claude Fable 5.2 --- datafusion/ffi/README.md | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/datafusion/ffi/README.md b/datafusion/ffi/README.md index be57231e9cf48..45f764f055ec2 100644 --- a/datafusion/ffi/README.md +++ b/datafusion/ffi/README.md @@ -17,8 +17,8 @@ can access the data structures. In order to share code between libraries loaded at runtime, you need to use Rust's [FFI] (Foreign Function Interface (FFI)). The purpose of this crate is to pass DataFusion runtime structures between libraries -running in the same process without being compiled into a single executable, such -as in different Python modules in different dynamically loaded libraries. +running in the same process without being compiled into a single executable, such +as in different Python modules in different dynamically loaded libraries. Both sides of the [FFI] boundary must use the same major version of this crate. See [Version Compatibility](#version-compatibility) for details. @@ -28,28 +28,28 @@ See [API Docs] for details and examples. ## Version Compatibility The interfaces in this crate are **not** stable across major versions of DataFusion, -though they are stable across Rust compiler versions. Both the producer and +though they are stable across Rust compiler versions. Both the producer and consumer of any struct shared across the [FFI] boundary must be built against the same major version of `datafusion-ffi`. The `FFI_*` structs can and do change between major versions. Nothing checks the layout at runtime, so exchanging these structs between libraries built against -different major versions is undefined behavior and can results in a crash +different major versions is undefined behavior and can result in a crash or incorrect results. When you upgrade DataFusion to a new major version, rebuild every library that shares structs across the [FFI] boundary against that version. To detect a mismatch, it is recommended that libraries expose a way to get the -`datafusion_ffi::version`, and applications that load the library compare the -result with its own. +[`datafusion_ffi::version`], and applications that load the library compare the +result with its own. ## Use Cases Two use cases have been identified for this crate, but they are not intended to be all inclusive. -1. [`datafusion-python`] which will use the FFI to provide external services such +1. [`datafusion-python`] which uses the FFI to provide external services such as a `TableProvider` without needing to re-export the entire `datafusion-python` code base. With `datafusion-ffi` these packages do not need `datafusion-python` as a dependency at all. @@ -223,6 +223,7 @@ and it is easy to implement on any struct that implements `Session`. [apache datafusion]: https://datafusion.apache.org/ [api docs]: http://docs.rs/datafusion-ffi/latest +[`datafusion_ffi::version`]: https://docs.rs/datafusion-ffi/latest/datafusion_ffi/fn.version.html [rust abi]: https://doc.rust-lang.org/reference/abi.html [ffi]: https://doc.rust-lang.org/nomicon/ffi.html [stabby]: https://crates.io/crates/stabby From 01343a4f0c5893f22385e1f62c3352e08410e4f4 Mon Sep 17 00:00:00 2001 From: Andrew Lamb Date: Tue, 1 Dec 2026 16:53:41 -0500 Subject: [PATCH 4/7] trim --- datafusion/ffi/README.md | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/datafusion/ffi/README.md b/datafusion/ffi/README.md index 45f764f055ec2..8f57b08788b31 100644 --- a/datafusion/ffi/README.md +++ b/datafusion/ffi/README.md @@ -49,11 +49,10 @@ result with its own. Two use cases have been identified for this crate, but they are not intended to be all inclusive. -1. [`datafusion-python`] which uses the FFI to provide external services such +1. [`datafusion-python`] which uses FFI to provide external services such as a `TableProvider` without needing to re-export the entire `datafusion-python` - code base. With `datafusion-ffi` these packages do not need `datafusion-python` - as a dependency at all. -2. Users may want to create a modular interface that allows runtime loading of + code base. +2. Create a modular interface for dynamically loading runtime libraries. For example, you may wish to design a program that only uses the built in table sources, but also allows for extension from the community led [datafusion-contrib] repositories. You could enable module loading so that From 886bd8eb012301d27c5290385707e7d86c4f028e Mon Sep 17 00:00:00 2001 From: Andrew Lamb Date: Tue, 1 Dec 2026 16:55:46 -0500 Subject: [PATCH 5/7] trim --- datafusion/ffi/README.md | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/datafusion/ffi/README.md b/datafusion/ffi/README.md index 8f57b08788b31..112bf3920796b 100644 --- a/datafusion/ffi/README.md +++ b/datafusion/ffi/README.md @@ -16,9 +16,10 @@ program compiled by a different Rust compiler, there is no guarantee that you can access the data structures. In order to share code between libraries loaded at runtime, you need to use Rust's [FFI] (Foreign Function Interface (FFI)). -The purpose of this crate is to pass DataFusion runtime structures between libraries -running in the same process without being compiled into a single executable, such -as in different Python modules in different dynamically loaded libraries. +The purpose of this crate is to pass DataFusion runtime structures between +libraries running in the same process without being compiled into a single +executable, such as Python modules that are each a separate dynamically loaded +library. Both sides of the [FFI] boundary must use the same major version of this crate. See [Version Compatibility](#version-compatibility) for details. @@ -27,22 +28,22 @@ See [API Docs] for details and examples. ## Version Compatibility -The interfaces in this crate are **not** stable across major versions of DataFusion, -though they are stable across Rust compiler versions. Both the producer and -consumer of any struct shared across the [FFI] boundary must be built against -the same major version of `datafusion-ffi`. +The interfaces in this crate are **not** stable across major versions of +DataFusion, though they are stable across Rust compiler versions. Both the +producer and consumer of any struct shared across the [FFI] boundary must be +built against the same major version of `datafusion-ffi`. The `FFI_*` structs can and do change between major versions. Nothing checks the layout at runtime, so exchanging these structs between libraries built against -different major versions is undefined behavior and can result in a crash -or incorrect results. +different major versions is undefined behavior and can result in a crash or +incorrect results. When you upgrade DataFusion to a new major version, rebuild every library that shares structs across the [FFI] boundary against that version. To detect a mismatch, it is recommended that libraries expose a way to get the [`datafusion_ffi::version`], and applications that load the library compare the -result with its own. +result with their own. ## Use Cases @@ -51,9 +52,9 @@ be all inclusive. 1. [`datafusion-python`] which uses FFI to provide external services such as a `TableProvider` without needing to re-export the entire `datafusion-python` - code base. -2. Create a modular interface for dynamically loading runtime - libraries. For example, you may wish to design a program that only uses the + code base. +2. Users may want to create a modular interface that loads libraries at + runtime. For example, you may wish to design a program that only uses the built in table sources, but also allows for extension from the community led [datafusion-contrib] repositories. You could enable module loading so that users could at runtime load a library to access additional data sources. From e3ad39c1469d0dbc015c16422af862891bdcca0f Mon Sep 17 00:00:00 2001 From: Andrew Lamb Date: Tue, 1 Dec 2026 17:00:26 -0500 Subject: [PATCH 6/7] add library docs g --- datafusion/ffi/src/lib.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/datafusion/ffi/src/lib.rs b/datafusion/ffi/src/lib.rs index 8ee65288d1f8c..c0cf0de470e84 100644 --- a/datafusion/ffi/src/lib.rs +++ b/datafusion/ffi/src/lib.rs @@ -2,6 +2,22 @@ // SPDX-FileCopyrightText: See the NOTICE file distributed with this work for additional information regarding copyright ownership // SPDX-FileContributor: Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements +//! Stable interfaces for sharing [Apache DataFusion] structures such as +//! `TableProvider`s and user defined functions between libraries loaded at +//! runtime. +//! +//! # Version Compatibility +//! +//! The `FFI_*` structs in this crate are **not** stable across major versions +//! of DataFusion. Both sides of FFI boundary must be built against the same +//! major version of this crate. +//! +//! You can use [`version`] to determine if a loaded library is compatible. See +//! the [README] for more details. +//! +//! [Apache DataFusion]: https://datafusion.apache.org/ +//! [README]: https://github.com/apache/datafusion/blob/main/datafusion/ffi/README.md + #![doc( html_logo_url = "https://raw.githubusercontent.com/apache/datafusion/19fe44cf2f30cbdd63d4a4f52c74055163c6cc38/docs/logos/standalone_logo/logo_original.svg", html_favicon_url = "https://raw.githubusercontent.com/apache/datafusion/19fe44cf2f30cbdd63d4a4f52c74055163c6cc38/docs/logos/standalone_logo/logo_original.svg" From c37ea994a4a78fa6265d97cdfbea6b51547c1f22 Mon Sep 17 00:00:00 2001 From: Andrew Lamb Date: Tue, 1 Dec 2026 17:00:57 -0500 Subject: [PATCH 7/7] typo --- datafusion/ffi/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/datafusion/ffi/src/lib.rs b/datafusion/ffi/src/lib.rs index c0cf0de470e84..901c339969e7e 100644 --- a/datafusion/ffi/src/lib.rs +++ b/datafusion/ffi/src/lib.rs @@ -9,8 +9,8 @@ //! # Version Compatibility //! //! The `FFI_*` structs in this crate are **not** stable across major versions -//! of DataFusion. Both sides of FFI boundary must be built against the same -//! major version of this crate. +//! of DataFusion. Both sides of the FFI boundary must be built against the +//! same major version of this crate. //! //! You can use [`version`] to determine if a loaded library is compatible. See //! the [README] for more details.