ntjohnson1 commented on code in PR #18918:
URL: https://github.com/apache/datafusion/pull/18918#discussion_r2566234506
##########
datafusion/ffi/src/session_config.rs:
##########
@@ -142,24 +136,22 @@ impl Drop for FFI_SessionConfig {
}
}
-/// A wrapper struct for accessing [`SessionConfig`] across a FFI boundary.
-/// The [`SessionConfig`] will be generated from a hash map of the config
-/// options in the provider and will be reconstructed on this side of the
-/// interface.s
-pub struct ForeignSessionConfig(pub SessionConfig);
-
-impl TryFrom<&FFI_SessionConfig> for ForeignSessionConfig {
Review Comment:
It feels like maybe a note that the from_string approach allows directly
converting rather than extracting with Foreign. This breaks a little bit from
the pattern but definitely seems nicer here.
##########
datafusion/ffi/src/session_config.rs:
##########
@@ -15,17 +15,13 @@
// specific language governing permissions and limitations
// under the License.
-use abi_stable::{
- std_types::{RHashMap, RString},
- StableAbi,
-};
-use datafusion::{config::ConfigOptions, error::Result};
-use datafusion::{error::DataFusionError, prelude::SessionConfig};
-use std::sync::Arc;
-use std::{
- collections::HashMap,
- ffi::{c_char, c_void, CString},
-};
+use std::collections::HashMap;
+use std::ffi::c_void;
+
+use abi_stable::std_types::{RHashMap, RString};
+use abi_stable::StableAbi;
+use datafusion_common::error::{DataFusionError, Result};
+use datafusion_execution::config::SessionConfig;
/// A stable struct for sharing [`SessionConfig`] across FFI boundaries.
/// Instead of attempting to expose the entire SessionConfig interface, we
Review Comment:
Hmm this is no longer strong ConfigOptions as private data. So this doc
string doesn't seem to be totally correct. It still uses config options to go
from FFI_ to SessionConfig but doesn't convert to config options to get into FFI
##########
datafusion/ffi/src/execution/task_ctx_provider.rs:
##########
@@ -0,0 +1,213 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+use std::ffi::c_void;
+use std::sync::{Arc, Weak};
+
+use abi_stable::std_types::{RResult, RString};
+use abi_stable::StableAbi;
+use datafusion_common::{exec_datafusion_err, DataFusionError};
+use datafusion_execution::{TaskContext, TaskContextProvider};
+
+use crate::execution::task_ctx::FFI_TaskContext;
+use crate::{df_result, rresult};
+
+/// Struct for accessing the [`TaskContext`]. This method contains a weak
+/// reference, so there are no guarantees that the [`TaskContext`] remains
+/// valid. This is used primarily for protobuf encoding and decoding of
+/// data passed across the FFI boundary. See the crate README for
+/// additional information.
+#[repr(C)]
+#[derive(Debug, StableAbi)]
+#[allow(non_camel_case_types)]
+pub struct FFI_TaskContextProvider {
+ pub task_ctx: unsafe extern "C" fn(&Self) -> RResult<FFI_TaskContext,
RString>,
+
+ /// Used to create a clone on the task context accessor. This should
+ /// only need to be called by the receiver of the plan.
+ pub clone: unsafe extern "C" fn(plan: &Self) -> Self,
+
+ /// Release the memory of the private data when it is no longer being used.
+ pub release: unsafe extern "C" fn(arg: &mut Self),
+
+ /// Internal data. This is only to be accessed by the provider of the plan.
+ /// The foreign library should never attempt to access this data.
+ pub private_data: *mut c_void,
+
+ /// Utility to identify when FFI objects are accessed locally through
+ /// the foreign interface. See [`crate::get_library_marker_id`] and
+ /// the crate's `README.md` for more information.
+ pub library_marker_id: extern "C" fn() -> usize,
+}
+
+unsafe impl Send for FFI_TaskContextProvider {}
+unsafe impl Sync for FFI_TaskContextProvider {}
+
+struct TaskContextProviderPrivateData {
+ ctx: Weak<dyn TaskContextProvider>,
Review Comment:
Similarly ok if it makes more sense to look at in follow up PR note here. Do
you have a concrete code snippet example for the circular reference this
breaks? I feel like a small comment with that might make this clearer for the
future.
##########
datafusion/ffi/src/execution/task_ctx_provider.rs:
##########
@@ -0,0 +1,213 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+use std::ffi::c_void;
+use std::sync::{Arc, Weak};
+
+use abi_stable::std_types::{RResult, RString};
+use abi_stable::StableAbi;
+use datafusion_common::{exec_datafusion_err, DataFusionError};
+use datafusion_execution::{TaskContext, TaskContextProvider};
+
+use crate::execution::task_ctx::FFI_TaskContext;
+use crate::{df_result, rresult};
+
+/// Struct for accessing the [`TaskContext`]. This method contains a weak
+/// reference, so there are no guarantees that the [`TaskContext`] remains
+/// valid. This is used primarily for protobuf encoding and decoding of
+/// data passed across the FFI boundary. See the crate README for
+/// additional information.
+#[repr(C)]
+#[derive(Debug, StableAbi)]
+#[allow(non_camel_case_types)]
+pub struct FFI_TaskContextProvider {
Review Comment:
You mentioned this is used primarily for data coming across protobuf so
should this be set more internally? Ex. pub(crate) or something. You mentioned
usage in follow up so can review this point in context there if that makes more
sense.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]