nathanb9 commented on code in PR #22584:
URL: https://github.com/apache/datafusion/pull/22584#discussion_r3356576532
##########
datafusion/ffi/src/physical_optimizer.rs:
##########
@@ -31,6 +32,99 @@ use crate::execution_plan::FFI_ExecutionPlan;
use crate::util::FFI_Result;
use crate::{df_result, sresult_return};
+/// A stable struct for sharing [`PhysicalOptimizerContext`] across FFI
boundaries.
+///
+/// This provides access to configuration options and an optional statistics
registry
+/// for optimizer rules that need extended context.
+#[repr(C)]
+#[derive(Debug)]
+pub struct FFI_PhysicalOptimizerContext {
+ pub config_options:
+ unsafe extern "C" fn(&FFI_PhysicalOptimizerContext) ->
FFI_ConfigOptions,
+
+ /// Returns true if a statistics registry is available.
+ pub has_statistics_registry:
+ unsafe extern "C" fn(&FFI_PhysicalOptimizerContext) -> bool,
+
+ /// Release the memory of the private data.
+ pub release: unsafe extern "C" fn(&mut FFI_PhysicalOptimizerContext),
+
+ /// Internal data. Only accessed by the provider.
+ pub private_data: *const c_void,
+}
+
+unsafe impl Send for FFI_PhysicalOptimizerContext {}
+unsafe impl Sync for FFI_PhysicalOptimizerContext {}
+
+struct OptimizerContextPrivateData {
+ config: ConfigOptions,
+ statistics_registry: Option<StatisticsRegistry>,
+}
+
+impl FFI_PhysicalOptimizerContext {
+ pub fn new(context: &dyn PhysicalOptimizerContext) -> Self {
+ let private_data = Box::new(OptimizerContextPrivateData {
+ config: context.config_options().clone(),
+ statistics_registry: context.statistics_registry().cloned(),
+ });
+ let private_data = Box::into_raw(private_data) as *const c_void;
+
Review Comment:
No allocation ive removed the field entirely from
`OptimizerContextPrivateData`
--
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]