Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cherry pick Simplify shift kernel using new_null_array to active_release #402

Merged
merged 1 commit into from
Jun 5, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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