You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2022/10/21 19:27:07 UTC

[GitHub] [arrow-rs] tustvold commented on a diff in pull request #2898: Specialize interleave integer

tustvold commented on code in PR #2898:
URL: https://github.com/apache/arrow-rs/pull/2898#discussion_r1002122586


##########
arrow-select/src/interleave.rs:
##########
@@ -70,9 +83,51 @@ pub fn interleave(
         return Ok(new_empty_array(data_type));
     }
 
-    // TODO: Add specialized implementations (#2864)
+    downcast_primitive! {
+        data_type => (primitive_helper, values, indices, data_type),
+        _ => interleave_fallback(values, indices)
+    }
+}
+
+fn interleave_primitive<T: ArrowPrimitiveType>(
+    values: &[&dyn Array],
+    indices: &[(usize, usize)],
+    data_type: &DataType,
+) -> Result<ArrayRef, ArrowError> {
+    let mut has_nulls = false;
+    let cast: Vec<_> = values
+        .iter()
+        .map(|x| {
+            has_nulls = has_nulls || x.null_count() != 0;
+            as_primitive_array::<T>(*x)
+        })
+        .collect();
+
+    let mut values = BufferBuilder::<T::Native>::new(indices.len());
+    for (a, b) in indices {
+        let v = cast[*a].value(*b);
+        values.append(v)
+    }
+
+    let mut null_count = 0;
+    let nulls = has_nulls.then(|| {
+        let mut builder = BooleanBufferBuilder::new(indices.len());
+        for (a, b) in indices {
+            let v = cast[*a].is_valid(*b);
+            null_count += !v as usize;
+            builder.append(v)
+        }

Review Comment:
   I tried this, but it actually appears to make the performance worse. So leaving as is for now



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org