You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by al...@apache.org on 2021/06/05 13:14:04 UTC

[arrow-rs] branch active_release updated: Simplify window using null array (#370) (#402)

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

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


The following commit(s) were added to refs/heads/active_release by this push:
     new e3d6792  Simplify window using null array (#370) (#402)
e3d6792 is described below

commit e3d679222c4aa4dfcfdff7459033b81a57c85ed0
Author: Andrew Lamb <an...@nerdnetworks.org>
AuthorDate: Sat Jun 5 09:13:57 2021 -0400

    Simplify window using null array (#370) (#402)
    
    Co-authored-by: Daniel Heres <da...@MBP-van-Olaf.home>
    
    Co-authored-by: Daniƫl Heres <da...@gmail.com>
    Co-authored-by: Daniel Heres <da...@MBP-van-Olaf.home>
---
 arrow/src/compute/kernels/window.rs | 29 ++++-------------------------
 1 file changed, 4 insertions(+), 25 deletions(-)

diff --git a/arrow/src/compute/kernels/window.rs b/arrow/src/compute/kernels/window.rs
index 82e712c..3de5849 100644
--- a/arrow/src/compute/kernels/window.rs
+++ b/arrow/src/compute/kernels/window.rs
@@ -17,18 +17,11 @@
 
 //! Defines windowing functions, like `shift`ing
 
-use crate::compute::concat;
+use crate::{array::new_null_array, compute::concat};
 use num::{abs, clamp};
 
-use crate::{
-    array::{make_array, ArrayData, PrimitiveArray},
-    datatypes::ArrowPrimitiveType,
-    error::Result,
-};
-use crate::{
-    array::{Array, ArrayRef},
-    buffer::MutableBuffer,
-};
+use crate::array::{Array, ArrayRef};
+use crate::{array::PrimitiveArray, datatypes::ArrowPrimitiveType, error::Result};
 
 /// Shifts array by defined number of items (to left or right)
 /// A positive value for `offset` shifts the array to the right
@@ -57,23 +50,9 @@ where
     // Generate array with remaining `null` items
     let nulls = abs(offset as i64) as usize;
 
-    let mut null_array = MutableBuffer::new(nulls);
-    let mut null_data = MutableBuffer::new(nulls * T::get_byte_width());
-    null_array.extend_zeros(nulls);
-    null_data.extend_zeros(nulls * T::get_byte_width());
-
-    let null_data = ArrayData::new(
-        T::DATA_TYPE,
-        nulls as usize,
-        Some(nulls),
-        Some(null_array.into()),
-        0,
-        vec![null_data.into()],
-        vec![],
-    );
+    let null_arr = new_null_array(&T::DATA_TYPE, nulls);
 
     // Concatenate both arrays, add nulls after if shift > 0 else before
-    let null_arr = make_array(null_data);
     if offset > 0 {
         concat(&[null_arr.as_ref(), slice.as_ref()])
     } else {