From 30decb78c27501b52b3e1dd8d2c6bff9f30ae2a0 Mon Sep 17 00:00:00 2001 From: remzi <13716567376yh@gmail.com> Date: Thu, 11 Aug 2022 09:29:25 +0800 Subject: [PATCH 1/2] add bound Signed-off-by: remzi <13716567376yh@gmail.com> --- arrow/src/array/array_decimal.rs | 2 ++ arrow/src/util/decimal.rs | 8 ++++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/arrow/src/array/array_decimal.rs b/arrow/src/array/array_decimal.rs index 412b74c60a1..747cb11f2a7 100644 --- a/arrow/src/array/array_decimal.rs +++ b/arrow/src/array/array_decimal.rs @@ -123,6 +123,8 @@ impl BasicDecimalArray { self.raw_value_data_ptr().offset(pos as isize), Self::VALUE_LENGTH as usize, ) + .try_into() + .unwrap() }; BasicDecimal::::new(self.precision(), self.scale(), raw_val) } diff --git a/arrow/src/util/decimal.rs b/arrow/src/util/decimal.rs index 10bd13f7e59..d5e62208014 100644 --- a/arrow/src/util/decimal.rs +++ b/arrow/src/util/decimal.rs @@ -114,17 +114,17 @@ impl BasicDecimal { /// Creates a decimal value from precision, scale, and bytes. /// /// Safety: - /// This method doesn't check if the length of bytes is compatible with this decimal. + /// This method doesn't check if the precision and scale are valid. /// Use `try_new_from_bytes` for safe constructor. - pub fn new(precision: usize, scale: usize, bytes: &[u8]) -> Self { + pub fn new(precision: usize, scale: usize, bytes: &[u8; BYTE_WIDTH]) -> Self { Self { precision, scale, - value: bytes.try_into().unwrap(), + value: *bytes, } } /// Returns the raw bytes of the integer representation of the decimal. - pub fn raw_value(&self) -> &[u8] { + pub fn raw_value(&self) -> &[u8; BYTE_WIDTH] { &self.value } From c662207714d2a3df7031cdbeaae60ccf8b05594f Mon Sep 17 00:00:00 2001 From: remzi <13716567376yh@gmail.com> Date: Thu, 11 Aug 2022 09:35:22 +0800 Subject: [PATCH 2/2] update doc Signed-off-by: remzi <13716567376yh@gmail.com> --- arrow/src/util/decimal.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/arrow/src/util/decimal.rs b/arrow/src/util/decimal.rs index d5e62208014..ba93a7ce7cf 100644 --- a/arrow/src/util/decimal.rs +++ b/arrow/src/util/decimal.rs @@ -64,8 +64,7 @@ impl BasicDecimal { Self::MAX_PRECISION_SCALE_CONSTRUCTOR_DEFAULT_TYPE.3; /// Tries to create a decimal value from precision, scale and bytes. - /// If the length of bytes isn't same as the bit width of this decimal, - /// returning an error. The bytes should be stored in little-endian order. + /// The bytes should be stored in little-endian order. /// /// Safety: /// This method doesn't validate if the decimal value represented by the bytes