zeroshade commented on code in PR #14278:
URL: https://github.com/apache/arrow/pull/14278#discussion_r984052216


##########
go/arrow/csv/writer.go:
##########
@@ -219,6 +219,38 @@ func (w *Writer) Write(record arrow.Record) error {
                                        recs[i][j] = w.nullValue
                                }
                        }
+               case *arrow.Decimal128Type:
+                       fieldType := 
w.schema.Field(j).Type.(*arrow.Decimal128Type)
+                       scale := fieldType.Scale
+                       arr := col.(*array.Decimal128)
+                       for i := 0; i < arr.Len(); i++ {
+                               if arr.IsValid(i) {
+                                       decString := 
arr.Value(i).BigInt().Text(10)
+                                       decimalLocation := len(decString) - 
int(scale)
+                                       if decimalLocation >= 0 && scale > 0 {
+                                               decString = 
decString[:decimalLocation] + "." + decString[decimalLocation:]
+                                       }
+                                       recs[i][j] = decString

Review Comment:
   Any particular reason not to follow the setup used for marshalling to json? 
   
   ```go
   f := (&big.Float{}).SetInt(arr.Value(i).BigInt())
   f.Quo(f, big.NewFloat(math.Pow10(int(scale))))
   recs[i][j] = f.Text('g', int(precision))
   ```
   The same thing works for decimal256



-- 
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: github-unsubscr...@arrow.apache.org

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

Reply via email to