-
Notifications
You must be signed in to change notification settings - Fork 2.2k
feat(ffi): plumb simplify, expressions, reverse_expr, and documentation through FFI_WindowUDF
#22705
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
feat(ffi): plumb simplify, expressions, reverse_expr, and documentation through FFI_WindowUDF
#22705
Changes from 7 commits
b5fbd1d
dcb4320
763e559
027ea4b
f109752
ee3962c
9a24ce5
847a1c4
8561770
ea30a83
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| // 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::sync::Arc; | ||
|
|
||
| use arrow::ffi::FFI_ArrowSchema; | ||
| use arrow_schema::FieldRef; | ||
| use datafusion_common::{DataFusionError, Result}; | ||
| use datafusion_expr::function::ExpressionArgs; | ||
| use datafusion_physical_expr::PhysicalExpr; | ||
| use stabby::vec::Vec as SVec; | ||
|
|
||
| use crate::arrow_wrappers::WrappedSchema; | ||
| use crate::physical_expr::FFI_PhysicalExpr; | ||
| use crate::util::rvec_wrapped_to_vec_fieldref; | ||
|
|
||
| /// A stable struct for sharing [`ExpressionArgs`] across FFI boundaries. | ||
| #[repr(C)] | ||
| #[derive(Debug)] | ||
| pub struct FFI_ExpressionArgs { | ||
| input_exprs: SVec<FFI_PhysicalExpr>, | ||
| input_fields: SVec<WrappedSchema>, | ||
| } | ||
|
|
||
| impl TryFrom<ExpressionArgs<'_>> for FFI_ExpressionArgs { | ||
| type Error = DataFusionError; | ||
|
|
||
| fn try_from(args: ExpressionArgs) -> Result<Self> { | ||
| let input_exprs = args | ||
| .input_exprs() | ||
| .iter() | ||
| .map(Arc::clone) | ||
| .map(FFI_PhysicalExpr::from) | ||
| .collect(); | ||
|
|
||
| let input_fields = args | ||
| .input_fields() | ||
| .iter() | ||
| .map(|field| FFI_ArrowSchema::try_from(field.as_ref()).map(WrappedSchema)) | ||
| .collect::<Result<Vec<_>, _>>()? | ||
| .into_iter() | ||
| .collect(); | ||
|
|
||
| Ok(Self { | ||
| input_exprs, | ||
| input_fields, | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| pub struct ForeignExpressionArgs { | ||
| input_exprs: Vec<Arc<dyn PhysicalExpr>>, | ||
| input_fields: Vec<FieldRef>, | ||
| } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why have a If that's the case then I think we should follow the naming convention like
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You're correct it exists because ExpressionArgs<'_> holds borrows, so we need an owned struct to carry the data across the FFI boundary before constructing the borrow-based view. i will rename it to follow the existing naming convention like OwnedExpressionArgs |
||
|
|
||
| impl TryFrom<FFI_ExpressionArgs> for ForeignExpressionArgs { | ||
| type Error = DataFusionError; | ||
|
|
||
| fn try_from(value: FFI_ExpressionArgs) -> Result<Self> { | ||
| let input_exprs = value.input_exprs.iter().map(Into::into).collect(); | ||
|
|
||
| let input_fields = rvec_wrapped_to_vec_fieldref(&value.input_fields)?; | ||
|
|
||
| Ok(Self { | ||
| input_exprs, | ||
| input_fields, | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| impl<'a> From<&'a ForeignExpressionArgs> for ExpressionArgs<'a> { | ||
| fn from(value: &'a ForeignExpressionArgs) -> Self { | ||
| ExpressionArgs::new(&value.input_exprs, &value.input_fields) | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are these changes necessary? They seem unrelated to the current PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These changes were added accidentally during development to fix a transient Docker pull failure in my fork. They are unrelated to this PR and will be reverted.