Skip to content

Commit

Permalink
Split out arrow-arith (apache#2594) (apache#3384)
Browse files Browse the repository at this point in the history
* Split out arrow-arith (apache#2594)

* Update CI

* Fix clippy

* Update docs

* Feature flag

* Fix CI

* Cleanup dependencies
  • Loading branch information
tustvold authored Dec 21, 2022
1 parent 13e0b87 commit e7fc073
Show file tree
Hide file tree
Showing 14 changed files with 398 additions and 343 deletions.
9 changes: 8 additions & 1 deletion .github/workflows/arrow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ on:
pull_request:
paths:
- .github/**
- arrow-arith/**
- arrow-array/**
- arrow-buffer/**
- arrow-cast/**
Expand Down Expand Up @@ -77,6 +78,8 @@ jobs:
run: cargo test -p arrow-string --all-features
- name: Test arrow-ord with all features except SIMD
run: cargo test -p arrow-ord --features dyn_cmp_dict
- name: Test arrow-arith with all features except SIMD
run: cargo test -p arrow-arith --features dyn_arith_dict
- name: Test arrow-row with all features
run: cargo test -p arrow-row --all-features
- name: Test arrow-integration-test with all features
Expand Down Expand Up @@ -140,6 +143,8 @@ jobs:
run: cargo test -p arrow-array --features simd
- name: Test arrow-ord with SIMD
run: cargo test -p arrow-ord --features simd
- name: Test arrow-arith with SIMD
run: cargo test -p arrow-arith --features simd
- name: Test arrow with SIMD
run: cargo test -p arrow --features simd
- name: Check compilation --features simd --all-targets
Expand Down Expand Up @@ -199,7 +204,9 @@ jobs:
run: cargo clippy -p arrow-string --all-targets --all-features -- -D warnings
- name: Clippy arrow-ord with all features except SIMD
run: cargo clippy -p arrow-ord --all-targets --features dyn_cmp_dict -- -D warnings
- name: Clippy arrow-arith with all features except SIMD
run: cargo clippy -p arrow-arith --all-targets --features dyn_arith_dict -- -D warnings
- name: Clippy arrow-row with all features
run: cargo clippy -p arrow-row --all-targets --all-features -- -D warnings
- name: Clippy arrow
- name: Clippy arrow with all features except SIMD
run: cargo clippy -p arrow --features=prettyprint,csv,ipc,test_utils,ffi,ipc_compression,dyn_cmp_dict,dyn_arith_dict,chrono-tz --all-targets -- -D warnings
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 <[email protected]>"]
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
Loading

0 comments on commit e7fc073

Please sign in to comment.