This is an automated email from the ASF dual-hosted git repository.
mbrobbel pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow-rs.git
The following commit(s) were added to refs/heads/main by this push:
new eb36450bc6 Migrate `arrow-arith` to Rust 2024 (#8449)
eb36450bc6 is described below
commit eb36450bc6a122be15ff10ec9b897e6d3d2a6701
Author: Matthijs Brobbel <[email protected]>
AuthorDate: Fri Sep 26 15:49:48 2025 +0200
Migrate `arrow-arith` to Rust 2024 (#8449)
# Which issue does this PR close?
- Contribute to #6827
# Rationale for this change
Splitting up #8227.
# What changes are included in this PR?
Migrate `arrow-arith` to Rust 2024
# Are these changes tested?
CI
# Are there any user-facing changes?
Yes
---
arrow-arith/Cargo.toml | 2 +-
arrow-arith/src/aggregate.rs | 24 ++++--------------------
arrow-arith/src/arithmetic.rs | 23 +++++++++++++++--------
arrow-arith/src/arity.rs | 2 +-
arrow-arith/src/boolean.rs | 2 +-
arrow-arith/src/numeric.rs | 9 ++++++---
arrow-arith/src/temporal.rs | 7 ++++---
7 files changed, 32 insertions(+), 37 deletions(-)
diff --git a/arrow-arith/Cargo.toml b/arrow-arith/Cargo.toml
index f2a4604c11..6816eab8df 100644
--- a/arrow-arith/Cargo.toml
+++ b/arrow-arith/Cargo.toml
@@ -25,7 +25,7 @@ authors = { workspace = true }
license = { workspace = true }
keywords = { workspace = true }
include = { workspace = true }
-edition = { workspace = true }
+edition = "2024"
rust-version = { workspace = true }
[lib]
diff --git a/arrow-arith/src/aggregate.rs b/arrow-arith/src/aggregate.rs
index 9a19b5d8a1..91623bc22b 100644
--- a/arrow-arith/src/aggregate.rs
+++ b/arrow-arith/src/aggregate.rs
@@ -45,11 +45,7 @@ trait NumericAccumulator<T: ArrowNativeTypeOp>: Copy +
Default {
/// After verifying the generated assembly this can be a simple `if`.
#[inline(always)]
fn select<T: Copy>(m: bool, a: T, b: T) -> T {
- if m {
- a
- } else {
- b
- }
+ if m { a } else { b }
}
#[derive(Clone, Copy)]
@@ -451,11 +447,7 @@ where
let idx = nulls.valid_indices().reduce(|acc_idx, idx| {
let acc = array.value_unchecked(acc_idx);
let item = array.value_unchecked(idx);
- if cmp(&acc, &item) {
- idx
- } else {
- acc_idx
- }
+ if cmp(&acc, &item) { idx } else { acc_idx }
});
idx.map(|idx| array.value_unchecked(idx))
}
@@ -477,11 +469,7 @@ fn min_max_view_helper<T: ByteViewType>(
let target_idx = (0..array.len()).reduce(|acc, item| {
// SAFETY: array's length is correct so item is within bounds
let cmp = unsafe { GenericByteViewArray::compare_unchecked(array,
item, array, acc) };
- if cmp == swap_cond {
- item
- } else {
- acc
- }
+ if cmp == swap_cond { item } else { acc }
});
// SAFETY: idx came from valid range `0..array.len()`
unsafe { target_idx.map(|idx| array.value_unchecked(idx)) }
@@ -491,11 +479,7 @@ fn min_max_view_helper<T: ByteViewType>(
let target_idx = nulls.valid_indices().reduce(|acc_idx, idx| {
let cmp =
unsafe { GenericByteViewArray::compare_unchecked(array, idx,
array, acc_idx) };
- if cmp == swap_cond {
- idx
- } else {
- acc_idx
- }
+ if cmp == swap_cond { idx } else { acc_idx }
});
// SAFETY: idx came from valid range `0..array.len()`
diff --git a/arrow-arith/src/arithmetic.rs b/arrow-arith/src/arithmetic.rs
index 768fd798c0..27efed6fcd 100644
--- a/arrow-arith/src/arithmetic.rs
+++ b/arrow-arith/src/arithmetic.rs
@@ -25,8 +25,8 @@
use crate::arity::*;
use arrow_array::types::*;
use arrow_array::*;
-use arrow_buffer::i256;
use arrow_buffer::ArrowNativeType;
+use arrow_buffer::i256;
use arrow_schema::*;
use std::cmp::min;
use std::sync::Arc;
@@ -208,9 +208,11 @@ mod tests {
.unwrap();
let err = mul(&a, &b).unwrap_err();
- assert!(err
- .to_string()
- .contains("Overflow happened on: 123456789000000000000000000 *
10000000000000000000"));
+ assert!(
+ err.to_string().contains(
+ "Overflow happened on: 123456789000000000000000000 *
10000000000000000000"
+ )
+ );
// Allow precision loss.
let result = multiply_fixed_point_checked(&a, &b, 28).unwrap();
@@ -278,9 +280,11 @@ mod tests {
// Required scale cannot be larger than the product of the input
scales.
let result = multiply_fixed_point_checked(&a, &b, 5).unwrap_err();
- assert!(result
- .to_string()
- .contains("Required scale 5 is greater than product scale 4"));
+ assert!(
+ result
+ .to_string()
+ .contains("Required scale 5 is greater than product scale 4")
+ );
}
#[test]
@@ -322,7 +326,10 @@ mod tests {
// `multiply` overflows on this case.
let err = mul(&a, &b).unwrap_err();
- assert_eq!(err.to_string(), "Arithmetic overflow: Overflow happened
on: 123456789000000000000000000 * 10000000000000000000");
+ assert_eq!(
+ err.to_string(),
+ "Arithmetic overflow: Overflow happened on:
123456789000000000000000000 * 10000000000000000000"
+ );
// Avoid overflow by reducing the scale.
let result = multiply_fixed_point(&a, &b, 28).unwrap();
diff --git a/arrow-arith/src/arity.rs b/arrow-arith/src/arity.rs
index d1bf1abcb2..b9f7a82963 100644
--- a/arrow-arith/src/arity.rs
+++ b/arrow-arith/src/arity.rs
@@ -19,9 +19,9 @@
use arrow_array::builder::BufferBuilder;
use arrow_array::*;
-use arrow_buffer::buffer::NullBuffer;
use arrow_buffer::ArrowNativeType;
use arrow_buffer::MutableBuffer;
+use arrow_buffer::buffer::NullBuffer;
use arrow_data::ArrayData;
use arrow_schema::ArrowError;
diff --git a/arrow-arith/src/boolean.rs b/arrow-arith/src/boolean.rs
index d8c7cc1932..d94df49de2 100644
--- a/arrow-arith/src/boolean.rs
+++ b/arrow-arith/src/boolean.rs
@@ -24,7 +24,7 @@
use arrow_array::*;
use arrow_buffer::buffer::{bitwise_bin_op_helper,
bitwise_quaternary_op_helper};
-use arrow_buffer::{buffer_bin_and_not, BooleanBuffer, NullBuffer};
+use arrow_buffer::{BooleanBuffer, NullBuffer, buffer_bin_and_not};
use arrow_schema::ArrowError;
/// Logical 'and' boolean values with Kleene logic
diff --git a/arrow-arith/src/numeric.rs b/arrow-arith/src/numeric.rs
index 198447b4db..022a3bb641 100644
--- a/arrow-arith/src/numeric.rs
+++ b/arrow-arith/src/numeric.rs
@@ -519,7 +519,7 @@ fn timestamp_op<T: TimestampOp>(
"Invalid timestamp arithmetic operation: {} {op} {}",
l.data_type(),
r.data_type()
- )))
+ )));
}
};
Ok(Arc::new(array.with_timezone_opt(l.timezone())))
@@ -941,7 +941,7 @@ fn decimal_op<T: DecimalType>(
mod tests {
use super::*;
use arrow_array::temporal_conversions::{as_date, as_datetime};
- use arrow_buffer::{i256, ScalarBuffer};
+ use arrow_buffer::{ScalarBuffer, i256};
use chrono::{DateTime, NaiveDate};
fn test_neg_primitive<T: ArrowPrimitiveType>(
@@ -1263,7 +1263,10 @@ mod tests {
.with_precision_and_scale(37, 37)
.unwrap();
let err = mul(&a, &b).unwrap_err().to_string();
- assert_eq!(err, "Invalid argument error: Output scale of Decimal128(3,
3) * Decimal128(37, 37) would exceed max scale of 38");
+ assert_eq!(
+ err,
+ "Invalid argument error: Output scale of Decimal128(3, 3) *
Decimal128(37, 37) would exceed max scale of 38"
+ );
let a = Decimal128Array::from(vec![1])
.with_precision_and_scale(3, -2)
diff --git a/arrow-arith/src/temporal.rs b/arrow-arith/src/temporal.rs
index 83e1e7f1b5..faff59bc30 100644
--- a/arrow-arith/src/temporal.rs
+++ b/arrow-arith/src/temporal.rs
@@ -24,9 +24,10 @@ use cast::as_primitive_array;
use chrono::{Datelike, TimeZone, Timelike, Utc};
use arrow_array::temporal_conversions::{
- date32_to_datetime, date64_to_datetime, timestamp_ms_to_datetime,
timestamp_ns_to_datetime,
- timestamp_s_to_datetime, timestamp_us_to_datetime, MICROSECONDS,
MICROSECONDS_IN_DAY,
- MILLISECONDS, MILLISECONDS_IN_DAY, NANOSECONDS, NANOSECONDS_IN_DAY,
SECONDS_IN_DAY,
+ MICROSECONDS, MICROSECONDS_IN_DAY, MILLISECONDS, MILLISECONDS_IN_DAY,
NANOSECONDS,
+ NANOSECONDS_IN_DAY, SECONDS_IN_DAY, date32_to_datetime, date64_to_datetime,
+ timestamp_ms_to_datetime, timestamp_ns_to_datetime,
timestamp_s_to_datetime,
+ timestamp_us_to_datetime,
};
use arrow_array::timezone::Tz;
use arrow_array::types::*;