liukun4515 commented on code in PR #2428:
URL: https://github.com/apache/arrow-rs/pull/2428#discussion_r944345632
##########
arrow/src/array/builder/decimal_builder.rs:
##########
@@ -85,33 +85,14 @@ impl Decimal128Builder {
/// Appends a decimal value into the builder.
#[inline]
pub fn append_value(&mut self, value: impl Into<i128>) -> Result<()> {
- let value = if self.value_validation {
- validate_decimal_precision(value.into(), self.precision)?
- } else {
- value.into()
- };
-
- let value_as_bytes =
- Self::from_i128_to_fixed_size_bytes(value, Self::BYTE_LENGTH as
usize)?;
- if Self::BYTE_LENGTH != value_as_bytes.len() as i32 {
- return Err(ArrowError::InvalidArgumentError(
- "Byte slice does not have the same length as Decimal128Builder
value lengths".to_string()
- ));
+ let value = value.into();
+ if self.value_validation {
+ validate_decimal_precision(value, self.precision)?
}
+ let value_as_bytes: [u8; 16] = value.to_le_bytes();
self.builder.append_value(value_as_bytes.as_slice())
}
- pub(crate) fn from_i128_to_fixed_size_bytes(v: i128, size: usize) ->
Result<Vec<u8>> {
Review Comment:
we can use
https://doc.rust-lang.org/std/primitive.i128.html#method.to_le_bytes directly
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]