-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Implement FFI_PhysicalExpr and the structs it needs to support it. #18916
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
Open
timsaucer
wants to merge
9
commits into
apache:main
Choose a base branch
from
timsaucer:feat/1-ffi-implement-physical-expr
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,904
−201
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
4208bbd
Implement FFI_PhysicalExpr and the structs it needs to support it.
timsaucer d835958
Add additional unit tests
timsaucer 2f128e8
Remove stale code
timsaucer 23be5d8
Change variable name for clarity
timsaucer 6af870d
Wrap scalar values into array of length 1
timsaucer edb40d6
Standardize docstrings across enums and structs
timsaucer 99ffbd7
Check for double free during drop operations
timsaucer 88b7b91
Add FFI datafusion error type
timsaucer 78e78e3
Update all FFI results to use FFIResult
timsaucer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| // 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 abi_stable::StableAbi; | ||
| use datafusion_common::{DataFusionError, ScalarValue}; | ||
| use datafusion_expr::ColumnarValue; | ||
|
|
||
| use crate::arrow_wrappers::WrappedArray; | ||
|
|
||
| /// A stable struct for sharing [`ColumnarValue`] across FFI boundaries. | ||
| /// Scalar values are passed as an Arrow array of length 1. | ||
| #[repr(C)] | ||
| #[derive(Debug, StableAbi)] | ||
| #[allow(non_camel_case_types)] | ||
| pub enum FFI_ColumnarValue { | ||
| Array(WrappedArray), | ||
| Scalar(WrappedArray), | ||
| } | ||
|
|
||
| impl TryFrom<ColumnarValue> for FFI_ColumnarValue { | ||
| type Error = DataFusionError; | ||
| fn try_from(value: ColumnarValue) -> Result<Self, Self::Error> { | ||
| Ok(match value { | ||
| ColumnarValue::Array(v) => { | ||
| FFI_ColumnarValue::Array(WrappedArray::try_from(&v)?) | ||
| } | ||
| ColumnarValue::Scalar(v) => { | ||
| FFI_ColumnarValue::Scalar(WrappedArray::try_from(&v)?) | ||
| } | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| impl TryFrom<FFI_ColumnarValue> for ColumnarValue { | ||
| type Error = DataFusionError; | ||
| fn try_from(value: FFI_ColumnarValue) -> Result<Self, Self::Error> { | ||
| Ok(match value { | ||
| FFI_ColumnarValue::Array(v) => ColumnarValue::Array(v.try_into()?), | ||
| FFI_ColumnarValue::Scalar(v) => { | ||
| ColumnarValue::Scalar(ScalarValue::try_from(v)?) | ||
| } | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use arrow::array::create_array; | ||
| use datafusion_common::{DataFusionError, ScalarValue}; | ||
| use datafusion_expr::ColumnarValue; | ||
|
|
||
| use crate::expr::columnar_value::FFI_ColumnarValue; | ||
|
|
||
| #[test] | ||
| fn ffi_columnar_value_round_trip() -> Result<(), DataFusionError> { | ||
| let array = create_array!(Int32, [1, 2, 3, 4, 5]); | ||
|
|
||
| for original in [ | ||
| ColumnarValue::Array(array), | ||
| ColumnarValue::Scalar(ScalarValue::Int32(Some(1))), | ||
|
Contributor
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. maybe we could also consider a |
||
| ] { | ||
| let ffi_variant = FFI_ColumnarValue::try_from(original.clone())?; | ||
|
|
||
| let returned_value = ColumnarValue::try_from(ffi_variant)?; | ||
|
|
||
| assert_eq!(format!("{returned_value:?}"), format!("{original:?}")); | ||
| } | ||
|
|
||
| Ok(()) | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
In this and the following PRs I am introducing more of these crates, even when they are re-exported in
datafusioncore crate so that it will have a smaller PR when we remove the core crate at the end of this work epic.