-
Notifications
You must be signed in to change notification settings - Fork 1.1k
[Variant] VariantArray::value supports shredded struct access #8446
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
Draft
scovich
wants to merge
5
commits into
apache:main
Choose a base branch
from
scovich:variant-array-value-struct
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.
Draft
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
a55c543
[Variant] VariantArray::value can return owned bytes now
scovich 79b3181
self review + fmt
scovich 7143267
Merge remote-tracking branch 'oss/main' into variant-as-cow
scovich 229d2f1
[Variant] VariantArray::value supports shredded structs
scovich f356c85
add fallible VariantArray::try_value
scovich 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
Prev
Previous commit
add fallible VariantArray::try_value
- Loading branch information
commit f356c855967c664c87ca670b1ce50b6ae5381bc9
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -467,6 +467,29 @@ impl VariantArray { | |
| /// | ||
| /// # Panics | ||
| /// * if the index is out of bounds | ||
| /// * if variant construction failed | ||
| /// | ||
| /// If this is a shredded variant but has no value at the shredded location, it | ||
| /// will return [`Variant::Null`]. | ||
| /// | ||
| /// # Performance Note | ||
| /// | ||
| /// This is certainly not the most efficient way to access values in a | ||
| /// `VariantArray`, but it is useful for testing and debugging. | ||
| /// | ||
| /// Note: Does not do deep validation of the [`Variant`], so it is up to the | ||
| /// caller to ensure that the metadata and value were constructed correctly. | ||
| pub fn value(&self, index: usize) -> VariantArrayValue<'_, '_> { | ||
| self.try_value(index).unwrap() | ||
| } | ||
|
|
||
| /// Try to return the [`Variant`] instance stored at the given row | ||
| /// | ||
| /// Note: This method does not check for nulls and the value is arbitrary | ||
| /// (but still well-defined) if [`is_null`](Self::is_null) returns true for the index. | ||
| /// | ||
| /// # Panics | ||
| /// * if the index is out of bounds | ||
| /// * if the array value is null | ||
| /// | ||
| /// If this is a shredded variant but has no value at the shredded location, it | ||
|
|
@@ -480,29 +503,27 @@ impl VariantArray { | |
| /// | ||
| /// Note: Does not do deep validation of the [`Variant`], so it is up to the | ||
| /// caller to ensure that the metadata and value were constructed correctly. | ||
| pub fn value(&self, index: usize) -> VariantArrayValue<'_, '_> { | ||
| match (self.typed_value_field(), self.value_field()) { | ||
| pub fn try_value(&self, index: usize) -> Result<VariantArrayValue<'_, '_>, ArrowError> { | ||
| let value = match (self.typed_value_field(), self.value_field()) { | ||
| // Always prefer typed_value, if available | ||
| (Some(typed_value), value) if typed_value.is_valid(index) => { | ||
| let metadata = VariantMetadata::new(self.metadata.value(index)); | ||
| let mut builder = SingleValueVariantBuilder::new(metadata.clone()); | ||
| let Err(err) = | ||
| typed_value_to_variant(typed_value, value, index, &metadata, &mut builder) | ||
| else { | ||
| let value_bytes = builder.into_bytes(); | ||
| return VariantArrayValue::owned(metadata.clone(), value_bytes); | ||
| }; | ||
| debug_assert!(false, "typed_value_to_variant failed: {err}"); | ||
| Variant::Null.into() | ||
| typed_value_to_variant(typed_value, value, index, &metadata, &mut builder)?; | ||
| return Ok(VariantArrayValue::owned( | ||
|
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. I think I see -- this is the core conundrum. If we want to return a |
||
| metadata.clone(), | ||
| builder.into_bytes(), | ||
| )); | ||
| } | ||
| // Otherwise fall back to value, if available | ||
| (_, Some(value)) if value.is_valid(index) => { | ||
| Variant::new(self.metadata.value(index), value.value(index)).into() | ||
| Variant::new(self.metadata.value(index), value.value(index)) | ||
| } | ||
| // It is technically invalid for neither value nor typed_value fields to be available, | ||
| // but the spec specifically requires readers to return Variant::Null in this case. | ||
| _ => Variant::Null.into(), | ||
| } | ||
| _ => Variant::Null, | ||
| }; | ||
| Ok(value.into()) | ||
| } | ||
|
|
||
| /// Return a reference to the metadata field of the [`StructArray`] | ||
|
|
||
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.