-
Notifications
You must be signed in to change notification settings - Fork 135
varbinview on device build skips validation #6358
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
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,12 @@ | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| // SPDX-FileCopyrightText: Copyright the Vortex contributors | ||
|
|
||
| use std::mem::size_of; | ||
| use std::sync::Arc; | ||
|
|
||
| use kernel::PARENT_KERNELS; | ||
| use vortex_buffer::Buffer; | ||
| use vortex_buffer::ByteBuffer; | ||
| use vortex_dtype::DType; | ||
| use vortex_error::VortexExpect; | ||
| use vortex_error::VortexResult; | ||
| use vortex_error::vortex_bail; | ||
| use vortex_error::vortex_err; | ||
|
|
@@ -80,20 +79,9 @@ impl VTable for VarBinViewVTable { | |
| buffers: &[BufferHandle], | ||
| children: &dyn ArrayChildren, | ||
| ) -> VortexResult<VarBinViewArray> { | ||
| if buffers.is_empty() { | ||
| vortex_bail!("Expected at least 1 buffer, got {}", buffers.len()); | ||
| } | ||
| let mut buffers: Vec<ByteBuffer> = buffers | ||
| .iter() | ||
| .map(|b| b.clone().try_to_host_sync()) | ||
| .collect::<VortexResult<Vec<_>>>()?; | ||
| let views = buffers.pop().vortex_expect("buffers non-empty"); | ||
|
|
||
| let views = Buffer::<BinaryView>::from_byte_buffer(views); | ||
|
|
||
| if views.len() != len { | ||
| vortex_bail!("Expected {} views, got {}", len, views.len()); | ||
| } | ||
| let Some((views_handle, data_handles)) = buffers.split_last() else { | ||
| vortex_bail!("Expected at least 1 buffer, got 0"); | ||
| }; | ||
|
|
||
| let validity = if children.is_empty() { | ||
| Validity::from(dtype.nullability()) | ||
|
|
@@ -104,7 +92,35 @@ impl VTable for VarBinViewVTable { | |
| vortex_bail!("Expected 0 or 1 children, got {}", children.len()); | ||
| }; | ||
|
|
||
| VarBinViewArray::try_new(views, Arc::from(buffers), dtype.clone(), validity) | ||
| let views_nbytes = views_handle.len(); | ||
| let expected_views_nbytes = len | ||
| .checked_mul(size_of::<BinaryView>()) | ||
| .ok_or_else(|| vortex_err!("views byte length overflow for len={len}"))?; | ||
| if views_nbytes != expected_views_nbytes { | ||
| vortex_bail!( | ||
| "Expected views buffer length {} bytes, got {} bytes", | ||
| expected_views_nbytes, | ||
| views_nbytes | ||
| ); | ||
| } | ||
|
|
||
| // If any buffer is on device, skip host validation and use try_new_handle. | ||
| if buffers.iter().any(|b| b.is_on_device()) { | ||
| return VarBinViewArray::try_new_handle( | ||
| views_handle.clone(), | ||
| Arc::from(data_handles.to_vec()), | ||
| dtype.clone(), | ||
| validity, | ||
| ); | ||
| } | ||
|
Comment on lines
+108
to
+115
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. can we not always use this path?
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.
|
||
|
|
||
| let data_buffers = data_handles | ||
| .iter() | ||
| .map(|b| b.as_host().clone()) | ||
| .collect::<Vec<_>>(); | ||
| let views = Buffer::<BinaryView>::from_byte_buffer(views_handle.clone().as_host().clone()); | ||
|
|
||
| VarBinViewArray::try_new(views, Arc::from(data_buffers), dtype.clone(), validity) | ||
| } | ||
|
|
||
| fn with_children(array: &mut Self::Array, children: Vec<ArrayRef>) -> VortexResult<()> { | ||
|
|
||
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.
nice