phillipleblanc commented on code in PR #6606:
URL: https://github.com/apache/arrow-rs/pull/6606#discussion_r1808287639


##########
arrow-json/src/writer/encoder.rs:
##########
@@ -545,3 +555,37 @@ where
         out.push(b'"');
     }
 }
+
+struct Decimal128Encoder<'a> {
+    array: &'a Decimal128Array,
+}
+
+impl<'a> Decimal128Encoder<'a> {
+    fn new(array: &'a Decimal128Array) -> Self {
+        Self { array }
+    }
+}
+
+impl<'a> Encoder for Decimal128Encoder<'a> {
+    fn encode(&mut self, idx: usize, out: &mut Vec<u8>) {
+        let formatted = self.array.value_as_string(idx);

Review Comment:
   I tried this, but it encoded them as strings not numbers, and I don't see 
any option that is relevant.
   
   ```rust
   DataType::Decimal128(_, _) | DataType::Decimal256(_, _)=> {
               let options = FormatOptions::new();
               let formatter = ArrayFormatter::try_new(array, &options)?;
               (Box::new(formatter) as _, array.nulls().cloned())
           }
   ```
   
   ```console
   assertion `left == right` failed
     left: [Some(Object {"decimal": Number(12.34)}), Some(Object {"decimal": 
Number(56.78)}), Some(Object {"decimal": Number(90.12)}), None]
    right: [Some(Object {"decimal": String("12.34")}), Some(Object {"decimal": 
String("56.78")}), Some(Object {"decimal": String("90.12")}), None]
   ```
   
   I'm not sure why though, it seems to call the same `format_decimal` method 
that `value_as_string` does?



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