You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2021/01/21 14:58:21 UTC

[GitHub] [arrow] ovr commented on a change in pull request #9232: ARROW-10818: [Rust] Implement DecimalType

ovr commented on a change in pull request #9232:
URL: https://github.com/apache/arrow/pull/9232#discussion_r561946613



##########
File path: rust/arrow/src/datatypes/mod.rs
##########
@@ -199,6 +207,81 @@ pub struct Field {
     metadata: Option<BTreeMap<String, String>>,
 }
 
+// Decimal (precision, scale) = Decimal(1, 2) = 1.00
+pub trait ArrowDecimalType: fmt::Debug + Send + Sync + FromStr + PartialEq {
+    const MAX_DIGITS: usize;
+
+    // fn into_json_value(self) -> Option<Value>;
+
+    fn get_byte_width_for_precision_scale(precision: usize, scale: usize) -> usize;
+
+    // Rescale scale part
+    fn rescale(&mut self, scale: usize);
+
+    // Try to parse string with precision, scale
+    fn parse(
+        string: &str,
+        precision: usize,
+        scale: usize,
+    ) -> std::result::Result<Self, ParseDecimalError>;
+
+    fn to_byte_slice(&self) -> Vec<u8>;
+
+    fn from_bytes_with_precision_scale(
+        bytes: &[u8],
+        precision: usize,
+        scale: usize,
+    ) -> Self;
+}
+
+#[derive(Debug)]
+pub enum DecimalType {

Review comment:
       @alamb @andygrove @Dandandan @nevi-me @jorgecarleitao
   
   I created representations for Decimal as `Int32DecimalType`, `Int64DecimalType`, `Int128DecimalType` or `LargeDecimal`, which uses BigInt.
   
   1. What is the best way in Rust to abstract representations of `DataType::Decimal` in Rust? Enum?
   2. How should I work with `DecimalArray`?  Should make it as generic by passing representation type to it (but how should I detect type, match in everyplace?) or make it generic on top of DecimalType and get byte size from it?
   
   Thanks




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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org