Skip to content

Commit e222986

Browse files
committed
fix erro msg
1 parent 1a34e05 commit e222986

1 file changed

Lines changed: 9 additions & 23 deletions

File tree

arrow-cast/src/cast/decimal.rs

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -920,9 +920,12 @@ where
920920
D: DecimalType + ArrowPrimitiveType,
921921
<D as ArrowPrimitiveType>::Native: ToPrimitive,
922922
{
923-
cast_single_decimal_to_integer::<D, T>(value, div, negative)
924-
.ok()
925-
.flatten()
923+
let v = if negative {
924+
value.mul_checked(div).ok()?
925+
} else {
926+
value.div_checked(div).ok()?
927+
};
928+
T::from::<D::Native>(v)
926929
}
927930

928931
#[inline]
@@ -932,25 +935,6 @@ fn cast_single_decimal_to_integer_result<D, T>(
932935
negative: bool,
933936
type_name: DataType,
934937
) -> Result<T, ArrowError>
935-
where
936-
T: NumCast + ToPrimitive,
937-
D: DecimalType + ArrowPrimitiveType,
938-
<D as ArrowPrimitiveType>::Native: ToPrimitive,
939-
{
940-
cast_single_decimal_to_integer::<D, T>(value, div, negative)?.ok_or_else(|| {
941-
ArrowError::CastError(format!(
942-
"value of {:?} is out of range {:?}",
943-
value, type_name
944-
))
945-
})
946-
}
947-
948-
#[inline]
949-
fn cast_single_decimal_to_integer<D, T>(
950-
value: D::Native,
951-
div: D::Native,
952-
negative: bool,
953-
) -> Result<Option<T>, ArrowError>
954938
where
955939
T: NumCast + ToPrimitive,
956940
D: DecimalType + ArrowPrimitiveType,
@@ -961,7 +945,9 @@ where
961945
} else {
962946
value.div_checked(div)?
963947
};
964-
Ok(T::from::<D::Native>(v))
948+
T::from::<D::Native>(v).ok_or_else(|| {
949+
ArrowError::CastError(format!("value of {:?} is out of range {:?}", v, type_name))
950+
})
965951
}
966952

967953
/// Cast a decimal array to a floating point array.

0 commit comments

Comments
 (0)