Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Go] enhancement request to expose AnyValue() on Scalar #34377

Open
chrisirhc opened this issue Feb 28, 2023 · 3 comments
Open

[Go] enhancement request to expose AnyValue() on Scalar #34377

chrisirhc opened this issue Feb 28, 2023 · 3 comments

Comments

@chrisirhc
Copy link
Contributor

chrisirhc commented Feb 28, 2023

Describe the enhancement requested

I wanted to gauge interest in a method on the Scalar interface to expose the value via any/interface{} like:

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:

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

@zeroshade
Copy link
Member

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

@chrisirhc
Copy link
Contributor Author

chrisirhc commented Mar 10, 2023

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

@zeroshade
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants