|
| 1 | +// Licensed to the Apache Software Foundation (ASF) under one |
| 2 | +// or more contributor license agreements. See the NOTICE file |
| 3 | +// distributed with this work for additional information |
| 4 | +// regarding copyright ownership. The ASF licenses this file |
| 5 | +// to you under the Apache License, Version 2.0 (the |
| 6 | +// "License"); you may not use this file except in compliance |
| 7 | +// with the License. You may obtain a copy of the License at |
| 8 | +// |
| 9 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +// |
| 11 | +// Unless required by applicable law or agreed to in writing, |
| 12 | +// software distributed under the License is distributed on an |
| 13 | +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 14 | +// KIND, either express or implied. See the License for the |
| 15 | +// specific language governing permissions and limitations |
| 16 | +// under the License. |
| 17 | + |
| 18 | +use std::ffi::c_void; |
| 19 | +use std::sync::Arc; |
| 20 | +use stabby::stabby; |
| 21 | +use stabby::string::String as SString; |
| 22 | +use datafusion::physical_optimizer::PhysicalOptimizerRule; |
| 23 | +use crate::config::FFI_ConfigOptions; |
| 24 | +use crate::execution_plan::FFI_ExecutionPlan; |
| 25 | +use crate::util::FFIResult; |
| 26 | + |
| 27 | +#[repr(C)] |
| 28 | +pub struct FFI_PhysicalOptimizerRule { |
| 29 | + |
| 30 | + /// FFI equivalent to the `name` of a [`PhysicalOptimizerRule`] |
| 31 | + pub name: unsafe extern "C" fn(rule : &Self) -> SString, |
| 32 | + pub schema_check: unsafe extern "C" fn(rule : &Self) -> bool, |
| 33 | + pub optimize: unsafe extern "C" fn ( |
| 34 | + rule: &Self, |
| 35 | + plan: FFI_ExecutionPlan, |
| 36 | + config: FFI_ConfigOptions, |
| 37 | + ) -> FFIResult<FFI_ExecutionPlan>, |
| 38 | + |
| 39 | + pub clone: unsafe extern "C" fn(rule: &Self) -> Self, |
| 40 | + pub release: unsafe extern "C" fn(rule: &mut Self), |
| 41 | + pub private_data: *mut c_void, |
| 42 | + |
| 43 | +} |
| 44 | + |
| 45 | +unsafe impl Send for FFI_PhysicalOptimizerRule {} |
| 46 | +unsafe impl Sync for FFI_PhysicalOptimizerRule {} |
| 47 | + |
| 48 | +struct PhysicalOptimizerRulePrivateData { |
| 49 | + rule: Arc<dyn PhysicalOptimizerRule + Send + Sync>, |
| 50 | +} |
0 commit comments