From 78c115ee37216fad6d44608c7dec039979f797a3 Mon Sep 17 00:00:00 2001 From: Raphael Taylor-Davies Date: Sat, 26 Nov 2022 13:30:20 +0000 Subject: [PATCH] Move zip and shift kernels to arrow-select --- arrow-select/src/lib.rs | 2 ++ .../kernels => arrow-select/src}/window.rs | 18 +++++++----------- .../kernels => arrow-select/src}/zip.rs | 9 +++++---- arrow/src/compute/kernels/mod.rs | 4 +--- 4 files changed, 15 insertions(+), 18 deletions(-) rename {arrow/src/compute/kernels => arrow-select/src}/window.rs (94%) rename {arrow/src/compute/kernels => arrow-select/src}/zip.rs (94%) diff --git a/arrow-select/src/lib.rs b/arrow-select/src/lib.rs index 5249b5c4c323..cf887dfca47c 100644 --- a/arrow-select/src/lib.rs +++ b/arrow-select/src/lib.rs @@ -21,3 +21,5 @@ pub mod concat; pub mod filter; pub mod interleave; pub mod take; +pub mod window; +pub mod zip; diff --git a/arrow/src/compute/kernels/window.rs b/arrow-select/src/window.rs similarity index 94% rename from arrow/src/compute/kernels/window.rs rename to arrow-select/src/window.rs index 54b11c3b2747..70ac86857db2 100644 --- a/arrow/src/compute/kernels/window.rs +++ b/arrow-select/src/window.rs @@ -17,12 +17,9 @@ //! Defines windowing functions, like `shift`ing -use crate::array::{Array, ArrayRef}; -use crate::error::Result; -use crate::{ - array::{make_array, new_null_array}, - compute::concat, -}; +use crate::concat::concat; +use arrow_array::{make_array, new_null_array, Array, ArrayRef}; +use arrow_schema::ArrowError; use num::abs; /// Shifts array by defined number of items (to left or right) @@ -30,9 +27,8 @@ use num::abs; /// a negative value shifts the array to the left. /// # Examples /// ``` -/// use arrow::array::Int32Array; -/// use arrow::error::Result; -/// use arrow::compute::shift; +/// # use arrow_array::Int32Array; +/// # use arrow_select::window::shift; /// /// let a: Int32Array = vec![Some(1), None, Some(4)].into(); /// @@ -56,7 +52,7 @@ use num::abs; /// let expected: Int32Array = vec![None, None, None].into(); /// assert_eq!(res.as_ref(), &expected); /// ``` -pub fn shift(array: &dyn Array, offset: i64) -> Result { +pub fn shift(array: &dyn Array, offset: i64) -> Result { let value_len = array.len() as i64; if offset == 0 { Ok(make_array(array.data_ref().clone())) @@ -86,7 +82,7 @@ pub fn shift(array: &dyn Array, offset: i64) -> Result { #[cfg(test)] mod tests { use super::*; - use crate::array::{Float64Array, Int32Array, Int32DictionaryArray}; + use arrow_array::{Float64Array, Int32Array, Int32DictionaryArray}; #[test] fn test_shift_neg() { diff --git a/arrow/src/compute/kernels/zip.rs b/arrow-select/src/zip.rs similarity index 94% rename from arrow/src/compute/kernels/zip.rs rename to arrow-select/src/zip.rs index c28529cf6762..e5d0f25e8fdb 100644 --- a/arrow/src/compute/kernels/zip.rs +++ b/arrow-select/src/zip.rs @@ -15,9 +15,10 @@ // specific language governing permissions and limitations // under the License. -use crate::array::*; -use crate::compute::SlicesIterator; -use crate::error::{ArrowError, Result}; +use crate::filter::SlicesIterator; +use arrow_array::*; +use arrow_data::transform::MutableArrayData; +use arrow_schema::ArrowError; /// Zip two arrays by some boolean mask. Where the mask evaluates `true` values of `truthy` /// are taken, where the mask evaluates `false` values of `falsy` are taken. @@ -30,7 +31,7 @@ pub fn zip( mask: &BooleanArray, truthy: &dyn Array, falsy: &dyn Array, -) -> Result { +) -> Result { if truthy.data_type() != falsy.data_type() { return Err(ArrowError::InvalidArgumentError( "arguments need to have the same data type".into(), diff --git a/arrow/src/compute/kernels/mod.rs b/arrow/src/compute/kernels/mod.rs index 9ffa53eb2db7..0eebb701232a 100644 --- a/arrow/src/compute/kernels/mod.rs +++ b/arrow/src/compute/kernels/mod.rs @@ -31,9 +31,7 @@ pub mod regexp; pub mod sort; pub mod substring; pub mod temporal; -pub mod window; -pub mod zip; pub use arrow_cast::cast; pub use arrow_cast::parse as cast_utils; -pub use arrow_select::{concat, filter, interleave, take}; +pub use arrow_select::{concat, filter, interleave, take, window, zip};