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

Split out arrow-arith (#2594) #3384

Merged
merged 7 commits into from
Dec 21, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
[workspace]
members = [
"arrow",
"arrow-arith",
"arrow-array",
"arrow-buffer",
"arrow-cast",
Expand Down
57 changes: 57 additions & 0 deletions arrow-arith/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# 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.

[package]
name = "arrow-arith"
version = "29.0.0"
description = "Arrow arithmetic kernels"
homepage = "https://github.com/apache/arrow-rs"
repository = "https://github.com/apache/arrow-rs"
authors = ["Apache Arrow <dev@arrow.apache.org>"]
license = "Apache-2.0"
keywords = ["arrow"]
include = [
"benches/*.rs",
"src/**/*.rs",
"Cargo.toml",
]
edition = "2021"
rust-version = "1.62"

[lib]
name = "arrow_arith"
path = "src/lib.rs"
bench = false

[dependencies]
arrow-array = { version = "29.0.0", path = "../arrow-array" }
arrow-buffer = { version = "29.0.0", path = "../arrow-buffer" }
arrow-data = { version = "29.0.0", path = "../arrow-data" }
arrow-schema = { version = "29.0.0", path = "../arrow-schema" }
chrono = { version = "0.4.23", default-features = false }
half = { version = "2.1", default-features = false }
multiversion = { version = "0.6.1", default-features = false }
num = { version = "0.4", default-features = false, features = ["std"] }

[dev-dependencies]

[package.metadata.docs.rs]
features = ["dyn_arith_dict"]

[features]
dyn_arith_dict = []
simd = ["arrow-array/simd"]
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,16 @@

//! Defines aggregations over Arrow arrays.

use arrow_data::bit_iterator::try_for_each_valid_idx;
use arrow_schema::ArrowError;
use multiversion::multiversion;
#[allow(unused_imports)]
use std::ops::{Add, Deref};

use crate::array::{
as_primitive_array, Array, ArrayAccessor, ArrayIter, BooleanArray,
GenericBinaryArray, GenericStringArray, OffsetSizeTrait, PrimitiveArray,
};
use crate::datatypes::{ArrowNativeType, ArrowNativeTypeOp, ArrowNumericType, DataType};
use crate::error::Result;
use crate::util::bit_iterator::BitIndexIterator;
use arrow_array::cast::*;
use arrow_array::iterator::ArrayIter;
use arrow_array::*;
use arrow_buffer::ArrowNativeType;
use arrow_data::bit_iterator::try_for_each_valid_idx;
use arrow_data::bit_iterator::BitIndexIterator;
use arrow_schema::ArrowError;
use arrow_schema::*;

/// Generic test for NaN, the optimizer should be able to remove this for integer types.
#[inline]
Expand Down Expand Up @@ -63,10 +60,8 @@ where
/// Returns the minimum value in the boolean array.
///
/// ```
/// use arrow::{
/// array::BooleanArray,
/// compute::min_boolean,
/// };
/// # use arrow_array::BooleanArray;
/// # use arrow_arith::aggregate::min_boolean;
///
/// let a = BooleanArray::from(vec![Some(true), None, Some(false)]);
/// assert_eq!(min_boolean(&a), Some(false))
Expand All @@ -88,10 +83,8 @@ pub fn min_boolean(array: &BooleanArray) -> Option<bool> {
/// Returns the maximum value in the boolean array
///
/// ```
/// use arrow::{
/// array::BooleanArray,
/// compute::max_boolean,
/// };
/// # use arrow_array::BooleanArray;
/// # use arrow_arith::aggregate::max_boolean;
///
/// let a = BooleanArray::from(vec![Some(true), None, Some(false)]);
/// assert_eq!(max_boolean(&a), Some(true))
Expand Down Expand Up @@ -205,7 +198,7 @@ where
/// use `sum_array` instead.
pub fn sum_array_checked<T, A: ArrayAccessor<Item = T::Native>>(
array: A,
) -> Result<Option<T::Native>>
) -> Result<Option<T::Native>, ArrowError>
where
T: ArrowNumericType,
T::Native: ArrowNativeTypeOp,
Expand Down Expand Up @@ -345,7 +338,7 @@ where
///
/// This detects overflow and returns an `Err` for that. For an non-overflow-checking variant,
/// use `sum` instead.
pub fn sum_checked<T>(array: &PrimitiveArray<T>) -> Result<Option<T::Native>>
pub fn sum_checked<T>(array: &PrimitiveArray<T>) -> Result<Option<T::Native>, ArrowError>
where
T: ArrowNumericType,
T::Native: ArrowNativeTypeOp,
Expand Down Expand Up @@ -375,7 +368,7 @@ where
array.len(),
array.offset(),
null_count,
Some(buffer.deref()),
Some(buffer.as_slice()),
|idx| {
unsafe { sum = sum.add_checked(array.value_unchecked(idx))? };
Ok::<_, ArrowError>(())
Expand All @@ -390,8 +383,7 @@ where
#[cfg(feature = "simd")]
mod simd {
use super::is_nan;
use crate::array::{Array, PrimitiveArray};
use crate::datatypes::{ArrowNativeTypeOp, ArrowNumericType};
use arrow_array::*;
use std::marker::PhantomData;

pub(super) trait SimdAggregate<T: ArrowNumericType> {
Expand Down Expand Up @@ -771,10 +763,8 @@ where
#[cfg(test)]
mod tests {
use super::*;
use crate::array::*;
use crate::compute::add;
use crate::datatypes::{Float32Type, Int32Type, Int8Type};
use arrow_array::types::Float64Type;
use crate::arithmetic::add;
use arrow_array::types::*;

#[test]
fn test_primitive_array_sum() {
Expand Down