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

   ### Describe the enhancement requested
   
   I wanted to gauge interest in a method on the Scalar interface to expose the 
value via any/interface{} like:
   ```go
   type Scalar interface {
        …
        AnyValue() any
        …
   }
   ```
   
   Usage: This would greatly help scenarios where the user is intentionally 
serializing to another format (e.g. JSON) and would like to incur memory 
overhead.
   For example, creating an array of anys for serialization. I know that 
`String()` can also be used for this, but it doesn't preserve the type.
   
   I'm thinking that this also allows the user to recover the type via casting 
subsequently. However, it allows for handling the scalar value without casting 
of the Scalar value first.
   
   Example usage:
   ```go
   func RecordsToAnyArr(recs []arrow.Record) (rec [][]any, err error) {
        rows := make([][]any, 0)
        for _, rec := range recs {
                for r := 0; r < int(rec.NumRows()); r++ {
                        row := make([]any, rec.NumCols())
                        for c := 0; c < int(rec.NumCols()); c++ {
                                col := rec.Column(c)
                                s, err := scalar.GetScalar(col, r)
                                if err != nil {
                                        return err
                                }
                                row[c] = s.AnyValue()
                        rows = append(rows, row)
                }
        }
   }
   ```
   
   Today, this would large switch case statement to achieve this.
   Let me know if I'm missing something.
   
   ### Component(s)
   
   Go
   
   Related to apache/arrow#10972


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

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

Reply via email to