alamb commented on a change in pull request #406:
URL: https://github.com/apache/arrow-rs/pull/406#discussion_r646114701



##########
File path: arrow/src/util/display.rs
##########
@@ -192,18 +194,34 @@ macro_rules! make_string_from_list {
     }};
 }
 
-macro_rules! make_string_from_decimal {
-    ($array_type: ty, $column: ident, $row: ident, $scale: ident) => {{
-        let array = $column.as_any().downcast_ref::<$array_type>().unwrap();
-        let decimal_string = array.value($row).to_string();
-        let formatted_decimal = if *$scale == 0 {
-            decimal_string
-        } else {
-            let splits = decimal_string.split_at(decimal_string.len() - 
*$scale);
-            format!("{}.{}", splits.0, splits.1)
-        };
-        Ok(formatted_decimal)
-    }};
+#[inline(always)]
+pub fn make_string_from_decimal_value(

Review comment:
       Since `scale` is part of the DataType` you probably don't need to pass 
it in here.
   
   Like you could do something like:
   
   ```
   let scale = if let DataType::Decimal(_, scale) = array.scale()
   ```
   
   It might even be worth putting this function on `DecimalArray` itself 
(something like `DecimalArray::value_as_stiring(offset)` to mirrow the 
`value_as_datetime` et al functions on the `Time*` array types. 
   
   Normally I wouldn't be picky about this but since this is a new public 
function (aka being added to the API) I felt it was worth some extra thought. 

##########
File path: arrow/src/array/array_binary.rs
##########
@@ -1163,17 +1167,16 @@ mod tests {
 
     #[test]
     fn test_decimal_array_fmt_debug() {
-        let values: [u8; 32] = [
-            192, 219, 180, 17, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 64, 36, 75, 
238, 253,
-            255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
-        ];
-        let array_data = ArrayData::builder(DataType::Decimal(23, 6))
-            .len(2)
-            .add_buffer(Buffer::from(&values[..]))
-            .build();
-        let arr = DecimalArray::from(array_data);
+        let values: Vec<i128> = vec![8887000000, -8887000000];
+        let mut decimal_builder = DecimalBuilder::new(3, 23, 6);
+
+        values.iter().for_each(|&value| {
+            decimal_builder.append_value(value).unwrap();
+        });
+        decimal_builder.append_null().unwrap();
+        let arr = decimal_builder.finish();
         assert_eq!(
-            "DecimalArray<23, 6>\n[\n  8887000000,\n  -8887000000,\n]",
+            "DecimalArray<23, 6>\n[\n  8887.000000,\n  -8887.000000,\n  
null,\n]",

Review comment:
       this looks like a significant improvement to me 👍 

##########
File path: arrow/benches/csv_writer.rs
##########
@@ -28,14 +28,14 @@ use arrow::record_batch::RecordBatch;
 use std::fs::File;
 use std::sync::Arc;
 
-fn record_batches_to_csv() {
+fn criterion_benchmark(c: &mut Criterion) {

Review comment:
       what are these changes for?




-- 
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:
[email protected]


Reply via email to