ianmcook opened a new issue, #848:
URL: https://github.com/apache/arrow-go/issues/848

   ### Describe the bug, including details regarding any error messages, 
version, and platform.
   
   Example to reproduce this:
   
   When an `decimal128(5, 2)` array contains the value `19.99`, the underlying 
value is stored as integer `1999` with scale `2`. `ValueStr(0)` formats this 
correctly as `19.99`, but `String()` on the decimal array, and therefore 
`fmt.Println(recordBatch)`, prints the raw `decimal128.Num` value (`{1999 0}`):
   
   ```go
   package main
   
   import (
        "fmt"
        "log"
   
        "github.com/apache/arrow-go/v18/arrow"
        "github.com/apache/arrow-go/v18/arrow/array"
        "github.com/apache/arrow-go/v18/arrow/decimal128"
        "github.com/apache/arrow-go/v18/arrow/memory"
   )
   
   func main() {
        typ := &arrow.Decimal128Type{Precision: 5, Scale: 2}
   
        builder := array.NewDecimal128Builder(memory.DefaultAllocator, typ)
        defer builder.Release()
   
        value, err := decimal128.FromString("19.99", typ.Precision, typ.Scale)
        if err != nil {
                log.Fatal(err)
        }
        builder.Append(value)
   
        decimalArray := builder.NewDecimal128Array()
        defer decimalArray.Release()
   
        fmt.Println("ValueStr:", decimalArray.ValueStr(0))
        fmt.Println("Array String:", decimalArray)
   
        schema := arrow.NewSchema([]arrow.Field{
                {Name: "price", Type: typ},
        }, nil)
        record := array.NewRecordBatch(schema, []arrow.Array{decimalArray}, 1)
        defer record.Release()
   
        fmt.Println(record)
   }
   ```
   
   Actual output:
   
   ```text
   ValueStr: 19.99
   Array String: [{1999 0}]
   record:
     schema:
     fields: 1
       - price: type=decimal(5, 2)
     rows: 1
     col[0][price]: [{1999 0}]
   ```
   
   Expected output would format the decimal using the array type's scale, for 
example `19.99`, as `ValueStr(0)` already does.
   
   Compare to PyArrow, which formats the same logical `decimal128(5, 2)` value 
using the scale metadata:
   
   ```python
   from decimal import Decimal
   
   import pyarrow as pa
   
   table = pa.table({
       "price": pa.array([Decimal("19.99")], type=pa.decimal128(5, 2)),
   })
   
   print(table)
   ```
   
   PyArrow output:
   
   ```text
   pyarrow.Table
   price: decimal128(5, 2)
   ----
   price: [[19.99]]
   ```
   
   ### Component(s)
   
   Other


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