dgvj-work commented on code in PR #1170:
URL: https://github.com/apache/arrow-go/pull/1170#discussion_r3771433338
##########
arrow/array.go:
##########
@@ -110,6 +110,12 @@ type Array interface {
// ValueStr returns the value at index as a string.
ValueStr(i int) string
+ // ValueAsAny returns the native Go value at index i, or nil if the
slot is null.
+ // Unlike GetOneForMarshal, values are not converted for JSON encoding
+ // (for example int8 stays int8, timestamps stay arrow.Timestamp, and
+ // nested values are []any / map[string]any of native values).
+ ValueAsAny(i int) any
Review Comment:
Moved it off `arrow.Array`. Callers can use `array.ValueAsAny(arr, i)`, and
custom array types can opt in via the optional `ValueAsAnyer` interface.
##########
arrow/array/union.go:
##########
@@ -333,6 +333,19 @@ func (a *SparseUnion) GetOneForMarshal(i int) interface{} {
return []interface{}{typeID, data.GetOneForMarshal(i)}
}
+func (a *SparseUnion) ValueAsAny(i int) any {
+ typeID := a.RawTypeCodes()[i]
+
+ childID := a.ChildID(i)
+ data := a.Field(childID)
+
+ if data.IsNull(i) {
Review Comment:
Updated. A null child now returns `[]any{typeID, nil}` so the union type id
is preserved.
##########
arrow/extensions/variant.go:
##########
@@ -612,6 +612,17 @@ func (v *VariantArray) GetOneForMarshal(i int) any {
return val.Value()
}
+func (v *VariantArray) ValueAsAny(i int) any {
+ if v.IsNull(i) {
+ return nil
+ }
+ val, err := v.Value(i)
+ if err != nil {
Review Comment:
Decode errors are now returned as the `any` value (the `error` itself)
instead of `nil`, so a corrupt non-null slot is distinguishable from an actual
null.
##########
arrow/array/struct.go:
##########
@@ -280,6 +280,18 @@ func (a *Struct) GetOneForMarshal(i int) interface{} {
return tmp
}
+func (a *Struct) ValueAsAny(i int) any {
+ if a.IsNull(i) {
+ return nil
+ }
+ tmp := make(map[string]any)
+ fieldList := a.data.dtype.(*arrow.StructType).Fields()
+ for j, d := range a.fields {
+ tmp[fieldList[j].Name] = d.ValueAsAny(i)
Review Comment:
Structs now return ordered `[name, value]` pairs instead of a map, so field
order and duplicate names are preserved.
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]