datafusion_ffi/udwf/
partition_evaluator_args.rs1use std::sync::Arc;
19
20use abi_stable::StableAbi;
21use abi_stable::std_types::RVec;
22use arrow::error::ArrowError;
23use arrow::ffi::FFI_ArrowSchema;
24use arrow_schema::FieldRef;
25use datafusion_common::{DataFusionError, Result};
26use datafusion_expr::function::PartitionEvaluatorArgs;
27use datafusion_physical_plan::PhysicalExpr;
28
29use crate::arrow_wrappers::WrappedSchema;
30use crate::physical_expr::FFI_PhysicalExpr;
31use crate::util::rvec_wrapped_to_vec_fieldref;
32
33#[repr(C)]
37#[derive(Debug, StableAbi)]
38pub struct FFI_PartitionEvaluatorArgs {
39 input_exprs: RVec<FFI_PhysicalExpr>,
40 input_fields: RVec<WrappedSchema>,
41 is_reversed: bool,
42 ignore_nulls: bool,
43}
44
45impl TryFrom<PartitionEvaluatorArgs<'_>> for FFI_PartitionEvaluatorArgs {
46 type Error = DataFusionError;
47
48 fn try_from(args: PartitionEvaluatorArgs) -> Result<Self, DataFusionError> {
49 let input_exprs = args
50 .input_exprs()
51 .iter()
52 .map(Arc::clone)
53 .map(FFI_PhysicalExpr::from)
54 .collect();
55
56 let input_fields = args
57 .input_fields()
58 .iter()
59 .map(|input_type| FFI_ArrowSchema::try_from(input_type).map(WrappedSchema))
60 .collect::<Result<Vec<_>, ArrowError>>()?
61 .into();
62
63 Ok(Self {
64 input_exprs,
65 input_fields,
66 is_reversed: args.is_reversed(),
67 ignore_nulls: args.ignore_nulls(),
68 })
69 }
70}
71
72pub struct ForeignPartitionEvaluatorArgs {
77 input_exprs: Vec<Arc<dyn PhysicalExpr>>,
78 input_fields: Vec<FieldRef>,
79 is_reversed: bool,
80 ignore_nulls: bool,
81}
82
83impl TryFrom<FFI_PartitionEvaluatorArgs> for ForeignPartitionEvaluatorArgs {
84 type Error = DataFusionError;
85
86 fn try_from(value: FFI_PartitionEvaluatorArgs) -> Result<Self> {
87 let input_exprs = value.input_exprs.iter().map(Into::into).collect();
88
89 let input_fields = rvec_wrapped_to_vec_fieldref(&value.input_fields)?;
90
91 Ok(Self {
92 input_exprs,
93 input_fields,
94 is_reversed: value.is_reversed,
95 ignore_nulls: value.ignore_nulls,
96 })
97 }
98}
99
100impl<'a> From<&'a ForeignPartitionEvaluatorArgs> for PartitionEvaluatorArgs<'a> {
101 fn from(value: &'a ForeignPartitionEvaluatorArgs) -> Self {
102 PartitionEvaluatorArgs::new(
103 &value.input_exprs,
104 &value.input_fields,
105 value.is_reversed,
106 value.ignore_nulls,
107 )
108 }
109}
110
111#[cfg(test)]
112mod tests {}