Skip to content

Commit 99f089c

Browse files
author
B Vadlamani
committed
rename_traits
1 parent e83292b commit 99f089c

25 files changed

Lines changed: 1542 additions & 258 deletions

datafusion/ffi/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,8 @@ We intentionally use `#[repr(C)]` for our struct definitions instead of stabby's
9090
3. **Arrow types**: Arrow's FFI types like `FFI_ArrowSchema` do not implement
9191
`IStable`, and adding such implementations would be laborious and error-prone.
9292

93-
4. **FFI_Option and FFIResult**: We provide our own `FFI_Option<T>` and
94-
`FFIResult<T>` types using `#[repr(C, u8)]` because stabby's `Option`
93+
4. **FFI_Option and FFI_Result**: We provide our own `FFI_Option<T>` and
94+
`FFI_Result<T>` types using `#[repr(C, u8)]` because stabby's `Option`
9595
and `Result` require inner types to be `IStable`.
9696

9797
Instead, we use stabby for its convenient ABI-stable collection types like

datafusion/ffi/src/catalog_provider.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ use tokio::runtime::Handle;
3030
use crate::execution::FFI_TaskContextProvider;
3131
use crate::proto::logical_extension_codec::FFI_LogicalExtensionCodec;
3232
use crate::schema_provider::{FFI_SchemaProvider, ForeignSchemaProvider};
33-
use crate::util::{FFI_Option, FFIResult};
33+
use crate::util::{FFI_Option, FFI_Result};
3434
use crate::{df_result, sresult_return};
3535

3636
/// A stable struct for sharing [`CatalogProvider`] across FFI boundaries.
@@ -49,14 +49,14 @@ pub struct FFI_CatalogProvider {
4949
provider: &Self,
5050
name: SString,
5151
schema: &FFI_SchemaProvider,
52-
) -> FFIResult<FFI_Option<FFI_SchemaProvider>>,
52+
) -> FFI_Result<FFI_Option<FFI_SchemaProvider>>,
5353

5454
pub deregister_schema:
5555
unsafe extern "C" fn(
5656
provider: &Self,
5757
name: SString,
5858
cascade: bool,
59-
) -> FFIResult<FFI_Option<FFI_SchemaProvider>>,
59+
) -> FFI_Result<FFI_Option<FFI_SchemaProvider>>,
6060

6161
pub logical_codec: FFI_LogicalExtensionCodec,
6262

@@ -135,7 +135,7 @@ unsafe extern "C" fn register_schema_fn_wrapper(
135135
provider: &FFI_CatalogProvider,
136136
name: SString,
137137
schema: &FFI_SchemaProvider,
138-
) -> FFIResult<FFI_Option<FFI_SchemaProvider>> {
138+
) -> FFI_Result<FFI_Option<FFI_SchemaProvider>> {
139139
unsafe {
140140
let runtime = provider.runtime();
141141
let inner_provider = provider.inner();
@@ -152,23 +152,23 @@ unsafe extern "C" fn register_schema_fn_wrapper(
152152
})
153153
.into();
154154

155-
FFIResult::Ok(returned_schema)
155+
FFI_Result::Ok(returned_schema)
156156
}
157157
}
158158

159159
unsafe extern "C" fn deregister_schema_fn_wrapper(
160160
provider: &FFI_CatalogProvider,
161161
name: SString,
162162
cascade: bool,
163-
) -> FFIResult<FFI_Option<FFI_SchemaProvider>> {
163+
) -> FFI_Result<FFI_Option<FFI_SchemaProvider>> {
164164
unsafe {
165165
let runtime = provider.runtime();
166166
let inner_provider = provider.inner();
167167

168168
let maybe_schema =
169169
sresult_return!(inner_provider.deregister_schema(name.as_str(), cascade));
170170

171-
FFIResult::Ok(
171+
FFI_Result::Ok(
172172
maybe_schema
173173
.map(|schema| {
174174
FFI_SchemaProvider::new_with_ffi_codec(

datafusion/ffi/src/config/extension_options.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use stabby::string::String as SString;
2727
use stabby::vec::Vec as SVec;
2828

2929
use crate::df_result;
30-
use crate::util::FFIResult;
30+
use crate::util::FFI_Result;
3131

3232
/// A stable struct for sharing [`ExtensionOptions`] across FFI boundaries.
3333
///
@@ -47,7 +47,7 @@ pub struct FFI_ExtensionOptions {
4747
pub cloned: unsafe extern "C" fn(&Self) -> FFI_ExtensionOptions,
4848

4949
/// Set the given `key`, `value` pair
50-
pub set: unsafe extern "C" fn(&mut Self, key: SStr, value: SStr) -> FFIResult<()>,
50+
pub set: unsafe extern "C" fn(&mut Self, key: SStr, value: SStr) -> FFI_Result<()>,
5151

5252
/// Returns the [`ConfigEntry`] stored in this [`ExtensionOptions`]
5353
pub entries: unsafe extern "C" fn(&Self) -> SVec<(SString, SString)>,
@@ -95,11 +95,11 @@ unsafe extern "C" fn set_fn_wrapper(
9595
options: &mut FFI_ExtensionOptions,
9696
key: SStr,
9797
value: SStr,
98-
) -> FFIResult<()> {
98+
) -> FFI_Result<()> {
9999
let _ = options
100100
.inner_mut()
101101
.insert(key.as_str().into(), value.as_str().into());
102-
FFIResult::Ok(())
102+
FFI_Result::Ok(())
103103
}
104104

105105
unsafe extern "C" fn entries_fn_wrapper(

datafusion/ffi/src/execution/task_ctx_provider.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use datafusion_common::{DataFusionError, ffi_datafusion_err};
2222
use datafusion_execution::{TaskContext, TaskContextProvider};
2323

2424
use crate::execution::task_ctx::FFI_TaskContext;
25-
use crate::util::FFIResult;
25+
use crate::util::FFI_Result;
2626
use crate::{df_result, sresult};
2727

2828
/// Struct for accessing the [`TaskContext`]. This method contains a weak
@@ -37,7 +37,7 @@ pub struct FFI_TaskContextProvider {
3737
/// gone out of scope. This function will return an error if the weakly
3838
/// held reference to the underlying [`TaskContextProvider`] is no longer
3939
/// available.
40-
pub task_ctx: unsafe extern "C" fn(&Self) -> FFIResult<FFI_TaskContext>,
40+
pub task_ctx: unsafe extern "C" fn(&Self) -> FFI_Result<FFI_TaskContext>,
4141

4242
/// Used to create a clone on the task context accessor. This should
4343
/// only need to be called by the receiver of the plan.
@@ -74,7 +74,7 @@ impl FFI_TaskContextProvider {
7474

7575
unsafe extern "C" fn task_ctx_fn_wrapper(
7676
ctx_provider: &FFI_TaskContextProvider,
77-
) -> FFIResult<FFI_TaskContext> {
77+
) -> FFI_Result<FFI_TaskContext> {
7878
unsafe {
7979
sresult!(
8080
ctx_provider

datafusion/ffi/src/execution_plan.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ use crate::config::FFI_ConfigOptions;
3434
use crate::execution::FFI_TaskContext;
3535
use crate::plan_properties::FFI_PlanProperties;
3636
use crate::record_batch_stream::FFI_RecordBatchStream;
37-
use crate::util::{FFI_Option, FFIResult};
37+
use crate::util::{FFI_Option, FFI_Result};
3838
use crate::{df_result, sresult, sresult_return};
3939

4040
/// A stable struct for sharing a [`ExecutionPlan`] across FFI boundaries.
@@ -48,7 +48,7 @@ pub struct FFI_ExecutionPlan {
4848
pub children: unsafe extern "C" fn(plan: &Self) -> SVec<FFI_ExecutionPlan>,
4949

5050
pub with_new_children:
51-
unsafe extern "C" fn(plan: &Self, children: SVec<Self>) -> FFIResult<Self>,
51+
unsafe extern "C" fn(plan: &Self, children: SVec<Self>) -> FFI_Result<Self>,
5252

5353
/// Return the plan name.
5454
pub name: unsafe extern "C" fn(plan: &Self) -> SString,
@@ -59,14 +59,14 @@ pub struct FFI_ExecutionPlan {
5959
plan: &Self,
6060
partition: usize,
6161
context: FFI_TaskContext,
62-
) -> FFIResult<FFI_RecordBatchStream>,
62+
) -> FFI_Result<FFI_RecordBatchStream>,
6363

6464
pub repartitioned: unsafe extern "C" fn(
6565
plan: &Self,
6666
target_partitions: usize,
6767
config: FFI_ConfigOptions,
6868
)
69-
-> FFIResult<FFI_Option<FFI_ExecutionPlan>>,
69+
-> FFI_Result<FFI_Option<FFI_ExecutionPlan>>,
7070

7171
/// Used to create a clone on the provider of the execution plan. This should
7272
/// only need to be called by the receiver of the plan.
@@ -125,7 +125,7 @@ unsafe extern "C" fn children_fn_wrapper(
125125
unsafe extern "C" fn with_new_children_fn_wrapper(
126126
plan: &FFI_ExecutionPlan,
127127
children: SVec<FFI_ExecutionPlan>,
128-
) -> FFIResult<FFI_ExecutionPlan> {
128+
) -> FFI_Result<FFI_ExecutionPlan> {
129129
let runtime = plan.runtime();
130130
let inner_plan = Arc::clone(plan.inner());
131131

@@ -137,14 +137,14 @@ unsafe extern "C" fn with_new_children_fn_wrapper(
137137
let children = sresult_return!(children);
138138
let new_plan = sresult_return!(inner_plan.with_new_children(children));
139139

140-
FFIResult::Ok(FFI_ExecutionPlan::new(new_plan, runtime))
140+
FFI_Result::Ok(FFI_ExecutionPlan::new(new_plan, runtime))
141141
}
142142

143143
unsafe extern "C" fn execute_fn_wrapper(
144144
plan: &FFI_ExecutionPlan,
145145
partition: usize,
146146
context: FFI_TaskContext,
147-
) -> FFIResult<FFI_RecordBatchStream> {
147+
) -> FFI_Result<FFI_RecordBatchStream> {
148148
let ctx = context.into();
149149
let runtime = plan.runtime();
150150
let plan = plan.inner();
@@ -161,7 +161,7 @@ unsafe extern "C" fn repartitioned_fn_wrapper(
161161
plan: &FFI_ExecutionPlan,
162162
target_partitions: usize,
163163
config: FFI_ConfigOptions,
164-
) -> FFIResult<FFI_Option<FFI_ExecutionPlan>> {
164+
) -> FFI_Result<FFI_Option<FFI_ExecutionPlan>> {
165165
let maybe_config: Result<ConfigOptions, DataFusionError> = config.try_into();
166166
let config = sresult_return!(maybe_config);
167167
let runtime = plan.runtime();

datafusion/ffi/src/ffi_option.rs

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -73,31 +73,31 @@ impl<T> FFI_Option<T> {
7373
/// An FFI-safe result type with SString as the error type.
7474
#[repr(C, u8)]
7575
#[derive(Debug, Clone)]
76-
pub enum FFIResult<T> {
76+
pub enum FFI_Result<T> {
7777
Ok(T),
7878
Err(SString),
7979
}
8080

81-
impl<T> FFIResult<T> {
81+
impl<T> FFI_Result<T> {
8282
pub fn is_ok(&self) -> bool {
83-
matches!(self, FFIResult::Ok(_))
83+
matches!(self, FFI_Result::Ok(_))
8484
}
8585

8686
pub fn is_err(&self) -> bool {
87-
matches!(self, FFIResult::Err(_))
87+
matches!(self, FFI_Result::Err(_))
8888
}
8989

9090
pub fn unwrap_err(self) -> SString {
9191
match self {
92-
FFIResult::Err(e) => e,
93-
FFIResult::Ok(_) => panic!("called unwrap_err on Ok"),
92+
FFI_Result::Err(e) => e,
93+
FFI_Result::Ok(_) => panic!("called unwrap_err on Ok"),
9494
}
9595
}
9696

97-
pub fn map<U, F: FnOnce(T) -> U>(self, f: F) -> FFIResult<U> {
97+
pub fn map<U, F: FnOnce(T) -> U>(self, f: F) -> FFI_Result<U> {
9898
match self {
99-
FFIResult::Ok(v) => FFIResult::Ok(f(v)),
100-
FFIResult::Err(e) => FFIResult::Err(e),
99+
FFI_Result::Ok(v) => FFI_Result::Ok(f(v)),
100+
FFI_Result::Err(e) => FFI_Result::Err(e),
101101
}
102102
}
103103

@@ -106,29 +106,29 @@ impl<T> FFIResult<T> {
106106
}
107107
}
108108

109-
impl<T> From<FFIResult<T>> for Result<T, SString> {
110-
fn from(res: FFIResult<T>) -> Self {
109+
impl<T> From<FFI_Result<T>> for Result<T, SString> {
110+
fn from(res: FFI_Result<T>) -> Self {
111111
match res {
112-
FFIResult::Ok(v) => Ok(v),
113-
FFIResult::Err(e) => Err(e),
112+
FFI_Result::Ok(v) => Ok(v),
113+
FFI_Result::Err(e) => Err(e),
114114
}
115115
}
116116
}
117117

118-
impl<T, E: ToString> From<Result<T, E>> for FFIResult<T> {
118+
impl<T, E: ToString> From<Result<T, E>> for FFI_Result<T> {
119119
fn from(res: Result<T, E>) -> Self {
120120
match res {
121-
Ok(v) => FFIResult::Ok(v),
122-
Err(e) => FFIResult::Err(SString::from(e.to_string().as_str())),
121+
Ok(v) => FFI_Result::Ok(v),
122+
Err(e) => FFI_Result::Err(SString::from(e.to_string().as_str())),
123123
}
124124
}
125125
}
126126

127-
impl<T: PartialEq> PartialEq for FFIResult<T> {
127+
impl<T: PartialEq> PartialEq for FFI_Result<T> {
128128
fn eq(&self, other: &Self) -> bool {
129129
match (self, other) {
130-
(FFIResult::Ok(a), FFIResult::Ok(b)) => a == b,
131-
(FFIResult::Err(a), FFIResult::Err(b)) => a == b,
130+
(FFI_Result::Ok(a), FFI_Result::Ok(b)) => a == b,
131+
(FFI_Result::Err(a), FFI_Result::Err(b)) => a == b,
132132
_ => false,
133133
}
134134
}

0 commit comments

Comments
 (0)