You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by tu...@apache.org on 2022/10/28 06:09:48 UTC

[arrow-rs] branch master updated: Fix take string on sliced indices (#2960)

This is an automated email from the ASF dual-hosted git repository.

tustvold pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow-rs.git


The following commit(s) were added to refs/heads/master by this push:
     new 87ac05bca Fix take string on sliced indices (#2960)
87ac05bca is described below

commit 87ac05bcafd343d3d8ad3b519631d83090afeb1c
Author: Raphael Taylor-Davies <17...@users.noreply.github.com>
AuthorDate: Fri Oct 28 19:09:43 2022 +1300

    Fix take string on sliced indices (#2960)
---
 arrow-select/src/take.rs | 28 +++++++++++++++++++---------
 1 file changed, 19 insertions(+), 9 deletions(-)

diff --git a/arrow-select/src/take.rs b/arrow-select/src/take.rs
index 77a1147ad..ad1cfe4da 100644
--- a/arrow-select/src/take.rs
+++ b/arrow-select/src/take.rs
@@ -21,9 +21,7 @@ use std::{ops::AddAssign, sync::Arc};
 
 use arrow_array::types::*;
 use arrow_array::*;
-use arrow_buffer::{
-    bit_util, buffer::buffer_bin_and, ArrowNativeType, Buffer, MutableBuffer,
-};
+use arrow_buffer::{bit_util, ArrowNativeType, Buffer, MutableBuffer};
 use arrow_data::{ArrayData, ArrayDataBuilder};
 use arrow_schema::{ArrowError, DataType, Field};
 
@@ -675,12 +673,7 @@ where
             *offset = length_so_far;
         }
 
-        nulls = match indices.data_ref().null_buffer() {
-            Some(buffer) => {
-                Some(buffer_bin_and(buffer, 0, &null_buf.into(), 0, data_len))
-            }
-            None => Some(null_buf.into()),
-        };
+        nulls = Some(null_buf.into())
     }
 
     let array_data = ArrayData::builder(GenericStringArray::<OffsetSize>::DATA_TYPE)
@@ -1547,6 +1540,23 @@ mod tests {
         _test_take_string::<LargeStringArray>()
     }
 
+    #[test]
+    fn test_take_slice_string() {
+        let strings =
+            StringArray::from(vec![Some("hello"), None, Some("world"), None, Some("hi")]);
+        let indices = Int32Array::from(vec![Some(0), Some(1), None, Some(0), Some(2)]);
+        let indices_slice = indices.slice(1, 4);
+        let indices_slice = indices_slice
+            .as_ref()
+            .as_any()
+            .downcast_ref::<Int32Array>()
+            .unwrap();
+
+        let expected = StringArray::from(vec![None, None, Some("hello"), Some("world")]);
+        let result = take(&strings, indices_slice, None).unwrap();
+        assert_eq!(result.as_ref(), &expected);
+    }
+
     macro_rules! test_take_list {
         ($offset_type:ty, $list_data_type:ident, $list_array_type:ident) => {{
             // Construct a value array, [[0,0,0], [-1,-2,-1], [2,3]]