-
Notifications
You must be signed in to change notification settings - Fork 1.2k
[Variant] remove BorrowedShreddingState
#9791
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
Merged
+41
−110
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
c5c282a
remove `BorrowedShreddingState`
sdf-jkl 14662dd
Remove dead code
sdf-jkl 5b7d1e9
return lifetimes
sdf-jkl 1926160
Merge branch 'main' of https://github.com/apache/arrow-rs into remove…
sdf-jkl 8aadf40
Cow the shredding state
sdf-jkl cde17de
Revert "Cow the shredding state"
sdf-jkl 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
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 |
|---|---|---|
|
|
@@ -64,7 +64,7 @@ pub(crate) fn variant_from_arrays_at<'m, 'v>( | |
| } | ||
|
|
||
| /// Validates that an array has a binary-like data type. | ||
| fn validate_binary_array(array: &dyn Array, field_name: &str) -> Result<()> { | ||
| pub(crate) fn validate_binary_array(array: &dyn Array, field_name: &str) -> Result<()> { | ||
| match array.data_type() { | ||
| DataType::Binary | DataType::LargeBinary | DataType::BinaryView => Ok(()), | ||
| _ => Err(ArrowError::InvalidArgumentError(format!( | ||
|
|
@@ -843,14 +843,6 @@ impl ShreddingState { | |
| self.typed_value.as_ref() | ||
| } | ||
|
|
||
| /// Returns a borrowed version of this shredding state | ||
| pub fn borrow(&self) -> BorrowedShreddingState<'_> { | ||
| BorrowedShreddingState { | ||
| value: self.value_field(), | ||
| typed_value: self.typed_value_field(), | ||
| } | ||
| } | ||
|
|
||
| /// Slice all the underlying arrays | ||
| pub fn slice(&self, offset: usize, length: usize) -> Self { | ||
| Self { | ||
|
|
@@ -860,74 +852,19 @@ impl ShreddingState { | |
| } | ||
| } | ||
|
|
||
| /// Similar to [`ShreddingState`] except it holds borrowed references of the target arrays. Useful | ||
| /// for avoiding clone operations when the caller does not need a self-standing shredding state. | ||
| #[derive(Clone, Debug)] | ||
| pub struct BorrowedShreddingState<'a> { | ||
| value: Option<&'a ArrayRef>, | ||
| typed_value: Option<&'a ArrayRef>, | ||
| } | ||
|
|
||
| impl<'a> BorrowedShreddingState<'a> { | ||
| /// Create a new `BorrowedShreddingState` from the given `value` and `typed_value` fields | ||
| /// | ||
| /// Note you can create a `BorrowedShreddingState` from a &[`StructArray`] using | ||
| /// `BorrowedShreddingState::try_from(&struct_array)`, for example: | ||
| /// | ||
| /// ```no_run | ||
| /// # use arrow::array::StructArray; | ||
| /// # use parquet_variant_compute::BorrowedShreddingState; | ||
| /// # fn get_struct_array() -> StructArray { | ||
| /// # unimplemented!() | ||
| /// # } | ||
| /// let struct_array: StructArray = get_struct_array(); | ||
| /// let shredding_state = BorrowedShreddingState::try_from(&struct_array).unwrap(); | ||
| /// ``` | ||
| pub fn new(value: Option<&'a ArrayRef>, typed_value: Option<&'a ArrayRef>) -> Self { | ||
| Self { value, typed_value } | ||
| } | ||
|
|
||
| /// Return a reference to the value field, if present | ||
| pub fn value_field(&self) -> Option<&'a ArrayRef> { | ||
| self.value | ||
| } | ||
|
|
||
| /// Return a reference to the typed_value field, if present | ||
| pub fn typed_value_field(&self) -> Option<&'a ArrayRef> { | ||
| self.typed_value | ||
| } | ||
| } | ||
|
|
||
| impl<'a> TryFrom<&'a StructArray> for BorrowedShreddingState<'a> { | ||
| impl TryFrom<&StructArray> for ShreddingState { | ||
| type Error = ArrowError; | ||
|
|
||
| fn try_from(inner_struct: &'a StructArray) -> Result<Self> { | ||
| fn try_from(inner_struct: &StructArray) -> Result<Self> { | ||
| // The `value` column need not exist, but if it does it must be a binary type. | ||
| let value = if let Some(value_col) = inner_struct.column_by_name("value") { | ||
| validate_binary_array(value_col.as_ref(), "value")?; | ||
| Some(value_col) | ||
| Some(value_col.clone()) | ||
| } else { | ||
| None | ||
| }; | ||
|
Comment on lines
860
to
865
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. aside: isn't this just a let value = inner_struct
.column_by_name("value")
.map(|value| {
validate_binary_array(...)?;
Ok(Cow::Borrowed(value))
}
.transpose()?; (tho it's not shorter, so meh) |
||
| let typed_value = inner_struct.column_by_name("typed_value"); | ||
| Ok(BorrowedShreddingState::new(value, typed_value)) | ||
| } | ||
| } | ||
|
|
||
| impl TryFrom<&StructArray> for ShreddingState { | ||
| type Error = ArrowError; | ||
|
|
||
| fn try_from(inner_struct: &StructArray) -> Result<Self> { | ||
| Ok(BorrowedShreddingState::try_from(inner_struct)?.into()) | ||
| } | ||
| } | ||
|
|
||
| impl From<BorrowedShreddingState<'_>> for ShreddingState { | ||
| fn from(state: BorrowedShreddingState<'_>) -> Self { | ||
| ShreddingState { | ||
| value: state.value_field().cloned(), | ||
| typed_value: state.typed_value_field().cloned(), | ||
| } | ||
| let typed_value = inner_struct.column_by_name("typed_value").cloned(); | ||
| Ok(ShreddingState::new(value, typed_value)) | ||
| } | ||
| } | ||
|
|
||
|
|
||
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
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.
aside: Was this already an unused import? I wonder why clippy didn't flag it when it became unused?
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.
bump?
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.
pub usemakes it visible to all outside crates and clippy can't know if someone else uses it.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.
so this is technically a breaking API change