Open chrisirhc opened 1 year ago
@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?
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.
Alternatives:
UntypedValue()
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.
Describe the enhancement requested
I wanted to gauge interest in a method on the Scalar interface to expose the value via any/interface{} like:
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:
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