HaoYang670 commented on code in PR #2383:
URL: https://github.com/apache/arrow-rs/pull/2383#discussion_r940957037


##########
arrow/src/util/decimal.rs:
##########
@@ -18,21 +18,51 @@
 //! Decimal related utils
 
 use crate::datatypes::{
-    DECIMAL128_MAX_PRECISION, DECIMAL128_MAX_SCALE, DECIMAL256_MAX_PRECISION,
-    DECIMAL256_MAX_SCALE,
+    DataType, DECIMAL128_MAX_PRECISION, DECIMAL128_MAX_SCALE, 
DECIMAL256_MAX_PRECISION,
+    DECIMAL256_MAX_SCALE, DECIMAL_DEFAULT_SCALE,
 };
 use crate::error::{ArrowError, Result};
 use num::bigint::BigInt;
 use num::Signed;
 use std::cmp::{min, Ordering};
 
-pub trait BasicDecimal: PartialOrd + Ord + PartialEq + Eq {
-    /// The bit-width of the internal representation.
-    const BIT_WIDTH: usize;
-    /// The maximum precision.
-    const MAX_PRECISION: usize;
-    /// The maximum scale.
-    const MAX_SCALE: usize;
+#[derive(Debug)]
+pub struct BasicDecimal<const BYTE_WIDTH: usize> {
+    precision: usize,
+    scale: usize,
+    value: [u8; BYTE_WIDTH],
+}
+
+impl<const BYTE_WIDTH: usize> BasicDecimal<BYTE_WIDTH> {
+    #[allow(clippy::type_complexity)]
+    const _MAX_PRECISION_SCALE_CONSTRUCTOR_DEFAULT_TYPE: (
+        usize,
+        usize,
+        fn(usize, usize) -> DataType,
+        DataType,
+    ) = match BYTE_WIDTH {
+        16 => (
+            DECIMAL128_MAX_PRECISION,
+            DECIMAL128_MAX_SCALE,
+            DataType::Decimal128,
+            DataType::Decimal128(DECIMAL128_MAX_PRECISION, 
DECIMAL_DEFAULT_SCALE),
+        ),
+        32 => (
+            DECIMAL256_MAX_PRECISION,
+            DECIMAL256_MAX_SCALE,
+            DataType::Decimal256,
+            DataType::Decimal256(DECIMAL256_MAX_PRECISION, 
DECIMAL_DEFAULT_SCALE),
+        ),
+        _ => panic!("invalid byte width"),

Review Comment:
   We could constrain the byte width here. When compile the constant items, the 
compiler will give error if byte width != 16 or 32.
   @viirya 



-- 
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]

Reply via email to