HaoYang670 commented on code in PR #1633:
URL: https://github.com/apache/arrow-rs/pull/1633#discussion_r863602781
##########
arrow/src/compute/kernels/substring.rs:
##########
@@ -86,6 +86,52 @@ fn binary_substring<OffsetSize: BinaryOffsetSizeTrait>(
Ok(make_array(data))
}
+fn fixed_size_binary_substring(
+ array: &FixedSizeBinaryArray,
+ old_len: i32,
+ start: i32,
+ length: Option<i32>,
+) -> Result<ArrayRef> {
+ let new_start = if start >= 0 {
+ start.min(old_len)
+ } else {
+ (old_len + start).max(0)
+ };
+ let new_len = match length {
+ Some(len) => len.min(old_len - new_start),
+ None => old_len - new_start,
+ };
+
+ // build value buffer
+ let num_of_elements = array.len();
+ let values = array.value_data();
+ let data = values.as_slice();
+ let mut new_values = MutableBuffer::new(num_of_elements * (new_len as
usize));
+ (0..num_of_elements)
+ .map(|idx| {
+ let offset = array.value_offset(idx);
+ (
+ (offset + new_start) as usize,
+ (offset + new_start + new_len) as usize,
+ )
+ })
+ .for_each(|(start, end)|
new_values.extend_from_slice(&data[start..end]));
+
+ let array_data = unsafe {
+ ArrayData::new_unchecked(
+ DataType::FixedSizeBinary(new_len),
+ num_of_elements,
+ None,
+ array.data_ref().null_buffer().cloned(),
+ 0,
Review Comment:
Thank you very much for finding the bug. I have fixed it by getting the
`bit_slice` of `null_buffer`. Also a corresponding test is added.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]