Rich-T-kid commented on code in PR #11732:
URL: https://github.com/apache/arrow-rs/pull/11732#discussion_r4339008205


##########
arrow-select/src/coalesce/boolean.rs:
##########
@@ -0,0 +1,217 @@
+// 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.
+
+use super::InProgressArray;
+use crate::filter::{FilterPredicate, FilterSelection};
+use arrow_array::cast::AsArray;
+use arrow_array::{Array, ArrayRef, BooleanArray};
+use arrow_buffer::{BooleanBuffer, BooleanBufferBuilder, NullBufferBuilder};
+use arrow_schema::ArrowError;
+use std::sync::Arc;
+
+#[derive(Debug)]
+pub(crate) struct InProgressBooleanArray {
+    source: Option<ArrayRef>,
+    batch_size: usize,
+    values: Option<BooleanBufferBuilder>,
+    nulls: NullBufferBuilder,
+}
+
+impl InProgressBooleanArray {
+    pub(crate) fn new(batch_size: usize) -> Self {
+        Self {
+            source: None,
+            batch_size,
+            values: None,
+            nulls: NullBufferBuilder::new(batch_size),
+        }
+    }
+
+    fn values(&mut self) -> &mut BooleanBufferBuilder {
+        self.values
+            .get_or_insert_with(|| BooleanBufferBuilder::new(self.batch_size))
+    }
+
+    fn append_array(&mut self, array: &BooleanArray) {
+        self.values().append_buffer(array.values());
+        if let Some(nulls) = array.nulls() {
+            self.nulls.append_buffer(nulls);
+        } else {
+            self.nulls.append_n_non_nulls(array.len());
+        }
+    }
+}
+
+impl InProgressArray for InProgressBooleanArray {
+    fn set_source(&mut self, source: Option<ArrayRef>) {
+        self.source = source;
+    }
+
+    fn copy_rows(&mut self, offset: usize, len: usize) -> Result<(), 
ArrowError> {
+        let source = self.source.as_ref().ok_or_else(|| {
+            ArrowError::InvalidArgumentError(
+                "Internal Error: InProgressBooleanArray: source not 
set".to_string(),
+            )
+        })?;
+        let array = source.as_boolean().slice(offset, len);
+        self.append_array(&array);
+        Ok(())
+    }
+
+    fn copy_rows_by_filter_from(
+        &mut self,
+        source: ArrayRef,
+        filter: &FilterPredicate,
+    ) -> Result<(), ArrowError> {
+        // Benchmarks show per-bit copying only wins at selectivities at or 
below 1/128.

Review Comment:
   created https://github.com/apache/arrow-rs/pull/11772 for this



-- 
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]

Reply via email to