Skip to content

Commit 486bf06

Browse files
committed
Add documentation
1 parent e595ba1 commit 486bf06

File tree

5 files changed

+98
-41
lines changed

5 files changed

+98
-41
lines changed

datafusion/ffi/src/plan_properties.rs

+40-33
Original file line numberDiff line numberDiff line change
@@ -43,55 +43,32 @@ use prost::Message;
4343

4444
use crate::arrow_wrappers::WrappedSchema;
4545

46-
// TODO: should we just make ExecutionMode repr(C)?
47-
#[repr(C)]
48-
#[allow(non_camel_case_types)]
49-
#[derive(Clone, StableAbi)]
50-
pub enum FFI_ExecutionMode {
51-
Bounded,
52-
Unbounded,
53-
PipelineBreaking,
54-
}
55-
56-
impl From<ExecutionMode> for FFI_ExecutionMode {
57-
fn from(value: ExecutionMode) -> Self {
58-
match value {
59-
ExecutionMode::Bounded => FFI_ExecutionMode::Bounded,
60-
ExecutionMode::Unbounded => FFI_ExecutionMode::Unbounded,
61-
ExecutionMode::PipelineBreaking => FFI_ExecutionMode::PipelineBreaking,
62-
}
63-
}
64-
}
65-
66-
impl From<FFI_ExecutionMode> for ExecutionMode {
67-
fn from(value: FFI_ExecutionMode) -> Self {
68-
match value {
69-
FFI_ExecutionMode::Bounded => ExecutionMode::Bounded,
70-
FFI_ExecutionMode::Unbounded => ExecutionMode::Unbounded,
71-
FFI_ExecutionMode::PipelineBreaking => ExecutionMode::PipelineBreaking,
72-
}
73-
}
74-
}
75-
46+
/// A stable struct for sharing [`PlanProperties`] across FFI boundaries.
7647
#[repr(C)]
7748
#[derive(Debug, StableAbi)]
78-
#[allow(missing_docs)]
7949
#[allow(non_camel_case_types)]
8050
pub struct FFI_PlanProperties {
81-
// Returns protobuf serialized bytes of the partitioning
51+
/// The output partitioning is a [`Partitioning`] protobuf message serialized
52+
/// into bytes to pass across the FFI boundary.
8253
pub output_partitioning:
8354
unsafe extern "C" fn(plan: &Self) -> RResult<RVec<u8>, RStr<'static>>,
8455

56+
/// Return the execution mode of the plan.
8557
pub execution_mode: unsafe extern "C" fn(plan: &Self) -> FFI_ExecutionMode,
8658

87-
// PhysicalSortExprNodeCollection proto
59+
/// The output ordering is a [`PhysicalSortExprNodeCollection`] protobuf message
60+
/// serialized into bytes to pass across the FFI boundary.
8861
pub output_ordering:
8962
unsafe extern "C" fn(plan: &Self) -> RResult<RVec<u8>, RStr<'static>>,
9063

64+
/// Return the schema of the plan.
9165
pub schema: unsafe extern "C" fn(plan: &Self) -> WrappedSchema,
9266

67+
/// Release the memory of the private data when it is no longer being used.
9368
pub release: unsafe extern "C" fn(arg: &mut Self),
9469

70+
/// Internal data. This is only to be accessed by the provider of the plan.
71+
/// The foreign library should never attempt to access this data.
9572
pub private_data: *mut c_void,
9673
}
9774

@@ -261,6 +238,36 @@ impl TryFrom<FFI_PlanProperties> for PlanProperties {
261238
}
262239
}
263240

241+
/// FFI safe version of [`ExecutionMode`].
242+
#[repr(C)]
243+
#[allow(non_camel_case_types)]
244+
#[derive(Clone, StableAbi)]
245+
pub enum FFI_ExecutionMode {
246+
Bounded,
247+
Unbounded,
248+
PipelineBreaking,
249+
}
250+
251+
impl From<ExecutionMode> for FFI_ExecutionMode {
252+
fn from(value: ExecutionMode) -> Self {
253+
match value {
254+
ExecutionMode::Bounded => FFI_ExecutionMode::Bounded,
255+
ExecutionMode::Unbounded => FFI_ExecutionMode::Unbounded,
256+
ExecutionMode::PipelineBreaking => FFI_ExecutionMode::PipelineBreaking,
257+
}
258+
}
259+
}
260+
261+
impl From<FFI_ExecutionMode> for ExecutionMode {
262+
fn from(value: FFI_ExecutionMode) -> Self {
263+
match value {
264+
FFI_ExecutionMode::Bounded => ExecutionMode::Bounded,
265+
FFI_ExecutionMode::Unbounded => ExecutionMode::Unbounded,
266+
FFI_ExecutionMode::PipelineBreaking => ExecutionMode::PipelineBreaking,
267+
}
268+
}
269+
}
270+
264271
#[cfg(test)]
265272
mod tests {
266273
use datafusion::physical_plan::Partitioning;

datafusion/ffi/src/record_batch_stream.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -36,19 +36,25 @@ use futures::{Stream, TryStreamExt};
3636

3737
use crate::arrow_wrappers::{WrappedArray, WrappedSchema};
3838

39+
/// A stable struct for sharing [`RecordBatchStream`] across FFI boundaries.
40+
/// We use the async-ffi crate for handling async calls across libraries.
3941
#[repr(C)]
4042
#[derive(Debug, StableAbi)]
41-
#[allow(missing_docs)]
4243
#[allow(non_camel_case_types)]
4344
pub struct FFI_RecordBatchStream {
45+
/// This mirrors the `poll_next` of [`RecordBatchStream`] but does so
46+
/// in a FFI safe manner.
4447
pub poll_next:
4548
unsafe extern "C" fn(
4649
stream: &Self,
4750
cx: &mut FfiContext,
4851
) -> FfiPoll<ROption<RResult<WrappedArray, RString>>>,
4952

53+
/// Return the schema of the record batch
5054
pub schema: unsafe extern "C" fn(stream: &Self) -> WrappedSchema,
5155

56+
/// Internal data. This is only to be accessed by the provider of the plan.
57+
/// The foreign library should never attempt to access this data.
5258
pub private_data: *mut c_void,
5359
}
5460

datafusion/ffi/src/session_config.rs

+23-3
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,35 @@ use abi_stable::{
2727
use datafusion::{config::ConfigOptions, error::Result};
2828
use datafusion::{error::DataFusionError, prelude::SessionConfig};
2929

30+
/// A stable struct for sharing [`SessionConfig`] across FFI boundaries.
31+
/// Instead of attempting to expose the entire SessionConfig interface, we
32+
/// convert the config options into a map from a string to string and pass
33+
/// those values across the FFI boundary. On the receiver side, we
34+
/// reconstruct a SessionConfig from those values.
35+
///
36+
/// It is possible that using different versions of DataFusion across the
37+
/// FFI boundary could have differing expectations of the config options.
38+
/// This is a limitation of this approach, but exposing the entire
39+
/// SessionConfig via a FFI interface would be extensive and provide limited
40+
/// value over this version.
3041
#[repr(C)]
3142
#[derive(Debug, StableAbi)]
32-
#[allow(missing_docs)]
3343
#[allow(non_camel_case_types)]
3444
pub struct FFI_SessionConfig {
45+
/// Return a hash map from key to value of the config options represented
46+
/// by string values.
3547
pub config_options: unsafe extern "C" fn(config: &Self) -> RHashMap<RString, RString>,
3648

49+
/// Used to create a clone on the provider of the execution plan. This should
50+
/// only need to be called by the receiver of the plan.
51+
pub clone: unsafe extern "C" fn(plan: &Self) -> Self,
52+
53+
/// Release the memory of the private data when it is no longer being used.
54+
pub release: unsafe extern "C" fn(arg: &mut Self),
55+
56+
/// Internal data. This is only to be accessed by the provider of the plan.
57+
/// A [`ForeignSessionConfig`] should never attempt to access this data.
3758
pub private_data: *mut c_void,
38-
pub clone: unsafe extern "C" fn(&Self) -> Self,
39-
pub release: unsafe extern "C" fn(config: &mut Self),
4059
}
4160

4261
unsafe impl Send for FFI_SessionConfig {}
@@ -125,6 +144,7 @@ impl Drop for FFI_SessionConfig {
125144
}
126145
}
127146

147+
/// A wrapper struct for accessing [`SessionConfig`] across a FFI boundary
128148
pub struct ForeignSessionConfig(pub SessionConfig);
129149

130150
impl TryFrom<&FFI_SessionConfig> for ForeignSessionConfig {

datafusion/ffi/src/table_provider.rs

+26-2
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,25 @@ use super::{
5353
};
5454
use datafusion::error::Result;
5555

56-
/// A stable interface for creating a DataFusion TableProvider.
56+
/// A stable struct for sharing [`TableProvider`] across FFI boundaries.
5757
#[repr(C)]
5858
#[derive(Debug, StableAbi)]
5959
#[allow(non_camel_case_types)]
6060
pub struct FFI_TableProvider {
61+
/// Return the table schema
6162
pub schema: unsafe extern "C" fn(provider: &Self) -> WrappedSchema,
63+
64+
/// Perform a scan on the table. See [`TableProvider`] for detailed usage information.
65+
///
66+
/// # Arguments
67+
///
68+
/// * `provider` - the table provider
69+
/// * `session_config` - session configuration
70+
/// * `projections` - if specified, only a subset of the columns are returned
71+
/// * `filters_serialized` - filters to apply to the scan, which are a
72+
/// [`LogicalExprList`] protobuf message serialized into bytes to pass
73+
/// across the FFI boundary.
74+
/// * `limit` - if specified, limit the number of rows returned
6275
pub scan: unsafe extern "C" fn(
6376
provider: &Self,
6477
session_config: &FFI_SessionConfig,
@@ -67,8 +80,12 @@ pub struct FFI_TableProvider {
6780
limit: ROption<usize>,
6881
) -> FfiFuture<RResult<FFI_ExecutionPlan, RString>>,
6982

83+
/// Return the type of table. See [`TableType`] for options.
7084
pub table_type: unsafe extern "C" fn(provider: &Self) -> FFI_TableType,
7185

86+
/// Based upon the input filters, identify which are supported. The filters
87+
/// are a [`LogicalExprList`] protobuf message serialized into bytes to pass
88+
/// across the FFI boundary.
7289
pub supports_filters_pushdown: Option<
7390
unsafe extern "C" fn(
7491
provider: &FFI_TableProvider,
@@ -77,8 +94,15 @@ pub struct FFI_TableProvider {
7794
-> RResult<RVec<FFI_TableProviderFilterPushDown>, RString>,
7895
>,
7996

80-
pub clone: unsafe extern "C" fn(provider: &Self) -> Self,
97+
/// Used to create a clone on the provider of the execution plan. This should
98+
/// only need to be called by the receiver of the plan.
99+
pub clone: unsafe extern "C" fn(plan: &Self) -> Self,
100+
101+
/// Release the memory of the private data when it is no longer being used.
81102
pub release: unsafe extern "C" fn(arg: &mut Self),
103+
104+
/// Internal data. This is only to be accessed by the provider of the plan.
105+
/// A [`ForeignExecutionPlan`] should never attempt to access this data.
82106
pub private_data: *mut c_void,
83107
}
84108

datafusion/ffi/src/table_source.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
use abi_stable::StableAbi;
1919
use datafusion::{datasource::TableType, logical_expr::TableProviderFilterPushDown};
2020

21-
// TODO Should we just define TableProviderFilterPushDown as repr(C)?
21+
/// FFI safe version of [`TableProviderFilterPushDown`].
2222
#[repr(C)]
2323
#[derive(StableAbi)]
2424
#[allow(non_camel_case_types)]
@@ -56,7 +56,7 @@ impl From<&TableProviderFilterPushDown> for FFI_TableProviderFilterPushDown {
5656
}
5757
}
5858

59-
// TODO Should we just define FFI_TableType as repr(C)?
59+
/// FFI safe version of [`TableType`].
6060
#[repr(C)]
6161
#[allow(non_camel_case_types)]
6262
#[derive(Debug, Clone, Copy, PartialEq, Eq, StableAbi)]

0 commit comments

Comments
 (0)