You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2022/12/02 16:59:23 UTC
[GitHub] [arrow-rs] tustvold opened a new pull request, #3258: Add BooleanArray::from_unary and BooleanArray::from_binary
tustvold opened a new pull request, #3258:
URL: https://github.com/apache/arrow-rs/pull/3258
# Which issue does this PR close?
<!--
We generally require a GitHub issue to be filed for all bug fixes and enhancements and this helps us generate change logs for our releases. You can link an issue to this PR using the GitHub syntax. For example `Closes #123` indicates that this PR will close issue #123.
-->
Closes #.
# Rationale for this change
<!--
Why are you proposing this change? If this is already explained clearly in the issue then this section is not needed.
Explaining clearly why changes are proposed helps reviewers understand your changes and offer better suggestions for fixes.
-->
# What changes are included in this PR?
<!--
There is no need to duplicate the description in the issue here but it is sometimes worth providing a summary of the individual changes in this PR.
-->
# Are there any user-facing changes?
<!--
If there are user-facing changes then we may require documentation to be updated before approving the PR.
-->
<!---
If there are any breaking changes to public APIs, please add the `breaking change` label.
-->
--
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: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow-rs] tustvold commented on pull request #3258: Add BooleanArray::from_unary and BooleanArray::from_binary
Posted by GitBox <gi...@apache.org>.
tustvold commented on PR #3258:
URL: https://github.com/apache/arrow-rs/pull/3258#issuecomment-1335567490
I've confirmed this makes no difference to the comparison benchmarks
--
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: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow-rs] tustvold commented on a diff in pull request #3258: Add BooleanArray::from_unary and BooleanArray::from_binary
Posted by GitBox <gi...@apache.org>.
tustvold commented on code in PR #3258:
URL: https://github.com/apache/arrow-rs/pull/3258#discussion_r1038396774
##########
arrow-data/src/bit_mask.rs:
##########
@@ -62,9 +65,42 @@ pub fn set_bits(
null_count as usize
}
+/// Combines the null bitmaps of multiple arrays using a bitwise `and` operation.
+///
+/// This function is useful when implementing operations on higher level arrays.
+pub fn combine_option_bitmap(
Review Comment:
Previously this would return an error if called with an empty `arrays`.
In practice no codepaths could hit this, and so I removed it as it seemed unnecessary
--
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: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow-rs] tustvold merged pull request #3258: Add BooleanArray::from_unary and BooleanArray::from_binary
Posted by GitBox <gi...@apache.org>.
tustvold merged PR #3258:
URL: https://github.com/apache/arrow-rs/pull/3258
--
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: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow-rs] ursabot commented on pull request #3258: Add BooleanArray::from_unary and BooleanArray::from_binary
Posted by GitBox <gi...@apache.org>.
ursabot commented on PR #3258:
URL: https://github.com/apache/arrow-rs/pull/3258#issuecomment-1335720361
Benchmark runs are scheduled for baseline = 9abdb5572bcaf4d594514d58410a812f3a490c55 and contender = ecbb8c23765ff6530ca32b5b3139713d6aaebfed. ecbb8c23765ff6530ca32b5b3139713d6aaebfed is a master commit associated with this PR. Results will be available as each benchmark for each run completes.
Conbench compare runs links:
[Skipped :warning: Benchmarking of arrow-rs-commits is not supported on ec2-t3-xlarge-us-east-2] [ec2-t3-xlarge-us-east-2](https://conbench.ursa.dev/compare/runs/24506ebab6be41bdaa68dc63c62ad48c...ddb02b5ddc8c4a95ad5534cf64756f7f/)
[Skipped :warning: Benchmarking of arrow-rs-commits is not supported on test-mac-arm] [test-mac-arm](https://conbench.ursa.dev/compare/runs/16d4710ff32e4593b561e8d3ccabad7c...261414ed2cd94a95aa1c1553d482492b/)
[Skipped :warning: Benchmarking of arrow-rs-commits is not supported on ursa-i9-9960x] [ursa-i9-9960x](https://conbench.ursa.dev/compare/runs/2718a730019b4962996290a2fee69192...dac2a494ce8e409b8d06a2b1c8e1e996/)
[Skipped :warning: Benchmarking of arrow-rs-commits is not supported on ursa-thinkcentre-m75q] [ursa-thinkcentre-m75q](https://conbench.ursa.dev/compare/runs/e55a3c5ef59c453ea88c7be750e875fa...8104d8c788c048a28e92121f364b6659/)
Buildkite builds:
Supported benchmarks:
ec2-t3-xlarge-us-east-2: Supported benchmark langs: Python, R. Runs only benchmarks with cloud = True
test-mac-arm: Supported benchmark langs: C++, Python, R
ursa-i9-9960x: Supported benchmark langs: Python, R, JavaScript
ursa-thinkcentre-m75q: Supported benchmark langs: C++, Java
--
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: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow-rs] tustvold commented on a diff in pull request #3258: Add BooleanArray::from_unary and BooleanArray::from_binary
Posted by GitBox <gi...@apache.org>.
tustvold commented on code in PR #3258:
URL: https://github.com/apache/arrow-rs/pull/3258#discussion_r1038402887
##########
arrow-array/src/array/boolean_array.rs:
##########
@@ -173,6 +174,92 @@ impl BooleanArray {
) -> impl Iterator<Item = Option<bool>> + 'a {
indexes.map(|opt_index| opt_index.map(|index| self.value_unchecked(index)))
}
+
+ /// Create a [`BooleanArray`] by evaluating the operation for
+ /// each element of the provided array
+ ///
+ /// ```
+ /// # use arrow_array::{BooleanArray, Int32Array};
+ ///
+ /// let array = Int32Array::from(vec![1, 2, 3, 4, 5]);
+ /// let r = BooleanArray::from_unary(&array, |x| x > 2);
+ /// assert_eq!(&r, &BooleanArray::from(vec![false, false, true, true, true]));
+ /// ```
+ pub fn from_unary<T: ArrayAccessor, F>(left: T, mut op: F) -> Self
+ where
+ F: FnMut(T::Item) -> bool,
+ {
+ let null_bit_buffer = left
+ .data()
+ .null_buffer()
+ .map(|b| b.bit_slice(left.offset(), left.len()));
+
+ let buffer = MutableBuffer::collect_bool(left.len(), |i| unsafe {
+ // SAFETY: i in range 0..len
+ op(left.value_unchecked(i))
+ });
+
+ let data = unsafe {
+ ArrayData::new_unchecked(
+ DataType::Boolean,
+ left.len(),
+ None,
+ null_bit_buffer,
+ 0,
+ vec![Buffer::from(buffer)],
+ vec![],
+ )
+ };
+ Self::from(data)
+ }
+
+ /// Create a [`BooleanArray`] by evaluating the binary operation for
+ /// each element of the provided arrays
+ ///
+ /// ```
+ /// # use arrow_array::{BooleanArray, Int32Array};
+ ///
+ /// let a = Int32Array::from(vec![1, 2, 3, 4, 5]);
+ /// let b = Int32Array::from(vec![1, 2, 0, 2, 5]);
+ /// let r = BooleanArray::from_binary(&a, &b, |a, b| a == b).unwrap();
+ /// assert_eq!(&r, &BooleanArray::from(vec![true, true, false, false, true]));
+ /// ```
+ ///
+ /// # Panics
+ ///
+ /// This function panics if left and right are not the same length
Review Comment:
I specifically want this to be infallible, because I want a future `try_from_binary` to be able to return a user-provided error, instead of bundling it up in `ArrowError`.
--
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: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow-rs] viirya commented on a diff in pull request #3258: Add BooleanArray::from_unary and BooleanArray::from_binary
Posted by GitBox <gi...@apache.org>.
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: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow-rs] tustvold commented on a diff in pull request #3258: Add BooleanArray::from_unary and BooleanArray::from_binary
Posted by GitBox <gi...@apache.org>.
tustvold commented on code in PR #3258:
URL: https://github.com/apache/arrow-rs/pull/3258#discussion_r1038399562
##########
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:
This function wasn't being used anywhere - so I opted to just remove it
--
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: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org