Skip to content

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

@chrisirhc

Description

@chrisirhc

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 apache/arrow#10972

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions