Skip to content

Commit

Permalink
Simplify window using null array (#370)
Browse files Browse the repository at this point in the history
Co-authored-by: Daniel Heres <danielheres@MBP-van-Olaf.home>
  • Loading branch information
Dandandan and Daniel Heres authored May 29, 2021
1 parent 10100bb commit 60eb36e
Showing 1 changed file with 4 additions and 25 deletions.
29 changes: 4 additions & 25 deletions arrow/src/compute/kernels/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 60eb36e

Please sign in to comment.