viirya commented on code in PR #3258: URL: https://github.com/apache/arrow-rs/pull/3258#discussion_r1038414144
########## arrow/src/compute/util.rs: ########## @@ -1,243 +0,0 @@ -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -//! Common utilities for computation kernels. - -use crate::array::*; -use crate::buffer::{buffer_bin_and, Buffer}; -use crate::error::{ArrowError, Result}; - -/// Combines the null bitmaps of multiple arrays using a bitwise `and` operation. -/// -/// This function is useful when implementing operations on higher level arrays. -#[allow(clippy::unnecessary_wraps)] -pub(super) fn combine_option_bitmap( - arrays: &[&ArrayData], - len_in_bits: usize, -) -> Result<Option<Buffer>> { - arrays - .iter() - .map(|array| (array.null_buffer().cloned(), array.offset())) - .reduce(|acc, buffer_and_offset| match (acc, buffer_and_offset) { - ((None, _), (None, _)) => (None, 0), - ((Some(buffer), offset), (None, _)) | ((None, _), (Some(buffer), offset)) => { - (Some(buffer), offset) - } - ((Some(buffer_left), offset_left), (Some(buffer_right), offset_right)) => ( - Some(buffer_bin_and( - &buffer_left, - offset_left, - &buffer_right, - offset_right, - len_in_bits, - )), - 0, - ), - }) - .map_or( - Err(ArrowError::ComputeError( - "Arrays must not be empty".to_string(), - )), - |(buffer, offset)| { - Ok(buffer.map(|buffer| buffer.bit_slice(offset, len_in_bits))) - }, - ) -} - -#[cfg(test)] -pub(super) mod tests { - use super::*; - - use std::sync::Arc; - - use crate::array::ArrayData; - use crate::buffer::buffer_bin_or; - use crate::datatypes::DataType; - - /// Compares the null bitmaps of two arrays using a bitwise `or` operation. - /// - /// This function is useful when implementing operations on higher level arrays. - pub(super) fn compare_option_bitmap( Review Comment: Ok. Looks a bit weird to have this in `tests` although it looks like to be a utility function. -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
