Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 18 additions & 39 deletions arrow-arith/src/aggregate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
use arrow_array::cast::*;
use arrow_array::iterator::ArrayIter;
use arrow_array::*;
use arrow_buffer::{ArrowNativeType, NullBuffer};
use arrow_buffer::NullBuffer;
use arrow_data::bit_iterator::try_for_each_valid_idx;
use arrow_schema::*;
use std::borrow::BorrowMut;
Expand Down Expand Up @@ -541,11 +541,9 @@ pub fn min_string_view(array: &StringViewArray) -> Option<&str> {
///
/// This doesn't detect overflow. Once overflowing, the result will wrap around.
/// For an overflow-checking variant, use [`sum_array_checked`] instead.
pub fn sum_array<T, A: ArrayAccessor<Item = T::Native>>(array: A) -> Option<T::Native>
where
T: ArrowNumericType,
T::Native: ArrowNativeTypeOp,
{
pub fn sum_array<T: ArrowNumericType, A: ArrayAccessor<Item = T::Native>>(
array: A,
) -> Option<T::Native> {
match array.data_type() {
DataType::Dictionary(_, _) => {
let null_count = array.null_count();
Expand Down Expand Up @@ -583,13 +581,9 @@ where
/// use [`sum_array`] instead.
/// Additionally returns an `Err` on run-end-encoded arrays with a provided
/// values type parameter that is incorrect.
pub fn sum_array_checked<T, A: ArrayAccessor<Item = T::Native>>(
pub fn sum_array_checked<T: ArrowNumericType, A: ArrayAccessor<Item = T::Native>>(
array: A,
) -> Result<Option<T::Native>, ArrowError>
where
T: ArrowNumericType,
T::Native: ArrowNativeTypeOp,
{
) -> Result<Option<T::Native>, ArrowError> {
match array.data_type() {
DataType::Dictionary(_, _) => {
let null_count = array.null_count();
Expand Down Expand Up @@ -717,21 +711,17 @@ mod ree {

/// Returns the min of values in the array of `ArrowNumericType` type, or dictionary
/// array with value of `ArrowNumericType` type.
pub fn min_array<T, A: ArrayAccessor<Item = T::Native>>(array: A) -> Option<T::Native>
where
T: ArrowNumericType,
T::Native: ArrowNativeType,
{
pub fn min_array<T: ArrowNumericType, A: ArrayAccessor<Item = T::Native>>(
array: A,
) -> Option<T::Native> {
min_max_array_helper::<T, A, _, _>(array, |a, b| a.is_gt(*b), min)
}

/// Returns the max of values in the array of `ArrowNumericType` type, or dictionary
/// array with value of `ArrowNumericType` type.
pub fn max_array<T, A: ArrayAccessor<Item = T::Native>>(array: A) -> Option<T::Native>
where
T: ArrowNumericType,
T::Native: ArrowNativeTypeOp,
{
pub fn max_array<T: ArrowNumericType, A: ArrayAccessor<Item = T::Native>>(
array: A,
) -> Option<T::Native> {
min_max_array_helper::<T, A, _, _>(array, |a, b| a.is_lt(*b), max)
}

Expand Down Expand Up @@ -874,11 +864,9 @@ pub fn bool_or(array: &BooleanArray) -> Option<bool> {
///
/// 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>, ArrowError>
where
T: ArrowNumericType,
T::Native: ArrowNativeTypeOp,
{
pub fn sum_checked<T: ArrowNumericType>(
array: &PrimitiveArray<T>,
) -> Result<Option<T::Native>, ArrowError> {
let null_count = array.null_count();

if null_count == array.len() {
Expand Down Expand Up @@ -922,10 +910,7 @@ where
///
/// This doesn't detect overflow in release mode by default. Once overflowing, the result will
/// wrap around. For an overflow-checking variant, use [`sum_checked`] instead.
pub fn sum<T: ArrowNumericType>(array: &PrimitiveArray<T>) -> Option<T::Native>
where
T::Native: ArrowNativeTypeOp,
{
pub fn sum<T: ArrowNumericType>(array: &PrimitiveArray<T>) -> Option<T::Native> {
aggregate::<T::Native, T, SumAccumulator<T::Native>>(array)
}

Expand All @@ -940,10 +925,7 @@ where
/// let result = min(&array);
/// assert_eq!(result, Some(2));
/// ```
pub fn min<T: ArrowNumericType>(array: &PrimitiveArray<T>) -> Option<T::Native>
where
T::Native: PartialOrd,
{
pub fn min<T: ArrowNumericType>(array: &PrimitiveArray<T>) -> Option<T::Native> {
aggregate::<T::Native, T, MinAccumulator<T::Native>>(array)
}

Expand All @@ -958,10 +940,7 @@ where
/// let result = max(&array);
/// assert_eq!(result, Some(8));
/// ```
pub fn max<T: ArrowNumericType>(array: &PrimitiveArray<T>) -> Option<T::Native>
where
T::Native: PartialOrd,
{
pub fn max<T: ArrowNumericType>(array: &PrimitiveArray<T>) -> Option<T::Native> {
aggregate::<T::Native, T, MaxAccumulator<T::Native>>(array)
}

Expand Down
6 changes: 1 addition & 5 deletions arrow-arith/src/arithmetic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,11 +170,7 @@ pub fn multiply_fixed_point(
}

/// Divide a decimal native value by given divisor and round the result.
fn divide_and_round<I>(input: I::Native, div: I::Native) -> I::Native
where
I: DecimalType,
I::Native: ArrowNativeTypeOp,
{
fn divide_and_round<I: DecimalType>(input: I::Native, div: I::Native) -> I::Native {
let d = input.div_wrapping(div);
let r = input.mod_wrapping(div);

Expand Down
2 changes: 1 addition & 1 deletion arrow-cast/src/cast/decimal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -812,7 +812,7 @@ where
T: ArrowPrimitiveType,
<T as ArrowPrimitiveType>::Native: NumCast,
D: DecimalType + ArrowPrimitiveType,
<D as ArrowPrimitiveType>::Native: ArrowNativeTypeOp + ToPrimitive,
<D as ArrowPrimitiveType>::Native: ToPrimitive,
{
let array = array.as_primitive::<D>();

Expand Down
2 changes: 1 addition & 1 deletion arrow-cast/src/cast/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2287,7 +2287,7 @@ fn cast_from_decimal<D, F>(
) -> Result<ArrayRef, ArrowError>
where
D: DecimalType + ArrowPrimitiveType,
<D as ArrowPrimitiveType>::Native: ArrowNativeTypeOp + ToPrimitive,
<D as ArrowPrimitiveType>::Native: ToPrimitive,
F: Fn(D::Native) -> f64,
{
use DataType::*;
Expand Down
5 changes: 1 addition & 4 deletions arrow-ord/src/ord.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,7 @@ fn compare_primitive<T: ArrowPrimitiveType>(
left: &dyn Array,
right: &dyn Array,
opts: SortOptions,
) -> DynComparator
where
T::Native: ArrowNativeTypeOp,
{
) -> DynComparator {
let left = left.as_primitive::<T>();
let right = right.as_primitive::<T>();
let l_values = left.values().clone();
Expand Down
Loading