Skip to content

Commit 5015797

Browse files
committed
fix: used ArrowType
1 parent b3e1fb0 commit 5015797

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

datafusion/functions/src/math/power.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ use crate::utils::{calculate_binary_decimal_math, calculate_binary_math};
2424
use arrow::array::{Array, ArrayRef};
2525
use arrow::datatypes::i256;
2626
use arrow::datatypes::{
27-
ArrowNativeTypeOp, DataType, Decimal32Type, Decimal64Type, Decimal128Type,
28-
Decimal256Type, Float64Type, Int64Type,
27+
ArrowNativeType, ArrowNativeTypeOp, DataType, Decimal128Type, Decimal256Type,
28+
Decimal32Type, Decimal64Type, Float64Type, Int64Type,
2929
};
3030
use arrow::error::ArrowError;
3131
use datafusion_common::types::{NativeType, logical_float64, logical_int64};
@@ -116,7 +116,7 @@ impl PowerFunc {
116116
/// Scale it back to 1: 390625 / 10^4 = 39
117117
fn pow_decimal_int<T>(base: T, scale: i8, exp: i64) -> Result<T, ArrowError>
118118
where
119-
T: From<i32> + ArrowNativeTypeOp + ToPrimitive + NumCast + Copy,
119+
T: ArrowNativeType + ArrowNativeTypeOp + ToPrimitive + NumCast + Copy,
120120
{
121121
// Negative exponent: fall back to float computation
122122
if exp < 0 {
@@ -130,15 +130,15 @@ where
130130
// If scale < 0, 10^scale (e.g., 10^-2 = 0.01) becomes 0 in integer arithmetic.
131131
if exp == 0 {
132132
return if scale >= 0 {
133-
<T as From<i32>>::from(10)
133+
T::usize_as(10)
134134
.pow_checked(scale as u32)
135135
.map_err(|_| {
136136
ArrowError::ArithmeticOverflow(format!(
137137
"Cannot make unscale factor for {scale} and {exp}"
138138
))
139139
})
140140
} else {
141-
Ok(<T as From<i32>>::from(0))
141+
Ok(T::ZERO)
142142
};
143143
}
144144
let powered: T = base.pow_checked(exp).map_err(|_| {
@@ -156,7 +156,7 @@ where
156156
// If mul_exp is positive, we divide (standard case).
157157
// If mul_exp is negative, we multiply (negative scale case).
158158
if mul_exp > 0 {
159-
let div_factor: T = <T as From<i32>>::from(10)
159+
let div_factor: T = T::usize_as(10)
160160
.pow_checked(mul_exp as u32)
161161
.map_err(|_| {
162162
ArrowError::ArithmeticOverflow(format!(
@@ -171,7 +171,7 @@ where
171171
"Overflow while negating scale exponent".to_string(),
172172
)
173173
})?;
174-
let mul_factor: T = <T as From<i32>>::from(10)
174+
let mul_factor: T = T::usize_as(10)
175175
.pow_checked(abs_exp as u32)
176176
.map_err(|_| {
177177
ArrowError::ArithmeticOverflow(format!(
@@ -186,7 +186,7 @@ where
186186
/// for scaled integer types.
187187
fn pow_decimal_float<T>(base: T, scale: i8, exp: f64) -> Result<T, ArrowError>
188188
where
189-
T: From<i32> + ArrowNativeTypeOp + ToPrimitive + NumCast + Copy,
189+
T: ArrowNativeType + ArrowNativeTypeOp + ToPrimitive + NumCast + Copy,
190190
{
191191
if exp.is_finite() && exp.trunc() == exp && exp >= 0f64 && exp < u32::MAX as f64 {
192192
return pow_decimal_int(base, scale, exp as i64);

0 commit comments

Comments
 (0)