You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@arrow.apache.org by "chrisirhc (via GitHub)" <gi...@apache.org> on 2023/02/28 05:55:32 UTC

[GitHub] [arrow] chrisirhc opened a new issue, #34377: [Go] enhancement request to expose AnyValue() on Scalar

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

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


-- 
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-unsubscribe@arrow.apache.org.apache.org

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


[GitHub] [arrow] chrisirhc commented on issue #34377: [Go] enhancement request to expose AnyValue() on Scalar

Posted by "chrisirhc (via GitHub)" <gi...@apache.org>.
chrisirhc commented on issue #34377:
URL: https://github.com/apache/arrow/issues/34377#issuecomment-1463212875

   Yep, happy to do so. Thoughts on what to name the method? Does `AnyValue()` work ?  I'd assume `Value()` conflicts or might be confusing since `.Value` is used to access typed scalar value.


-- 
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-unsubscribe@arrow.apache.org

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


[GitHub] [arrow] zeroshade commented on issue #34377: [Go] enhancement request to expose AnyValue() on Scalar

Posted by "zeroshade (via GitHub)" <gi...@apache.org>.
zeroshade commented on issue #34377:
URL: https://github.com/apache/arrow/issues/34377#issuecomment-1448549316

   @chrisirhc Thanks for filing this, I can see the benefit here if that's something people are looking for. Most of the Scalar types already have a `value()` method which returns an `interface{}`, it just isn't publicly available. In theory it should be possible to just make that externally visible to do this. Would you be willing to make the PR for it?


-- 
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-unsubscribe@arrow.apache.org

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


[GitHub] [arrow] zeroshade commented on issue #34377: [Go] enhancement request to expose AnyValue() on Scalar

Posted by "zeroshade (via GitHub)" <gi...@apache.org>.
zeroshade commented on issue #34377:
URL: https://github.com/apache/arrow/issues/34377#issuecomment-1464058380

   We could follow the pattern from the `reflect` package and just call it `.Interface()`? :) 
   
   I'm not fond of `AnyValue()` but `UntypedValue()` would also potentially be fine i think.


-- 
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-unsubscribe@arrow.apache.org

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