emkornfield commented on a change in pull request #11359:
URL: https://github.com/apache/arrow/pull/11359#discussion_r744039785
##########
File path: go/arrow/array/struct.go
##########
@@ -105,6 +107,36 @@ func (a *Struct) setData(data *Data) {
}
}
+func (a *Struct) getOneForMarshal(i int) interface{} {
+ if a.IsNull(i) {
+ return nil
+ }
+
+ tmp := make(map[string]interface{})
+ fieldList := a.data.dtype.(*arrow.StructType).Fields()
+ for j, d := range a.fields {
+ tmp[fieldList[j].Name] = d.getOneForMarshal(i)
+ }
+ return tmp
+}
+
+func (a *Struct) MarshalJSON() ([]byte, error) {
+ var buf bytes.Buffer
+ enc := json.NewEncoder(&buf)
+
+ buf.WriteByte('[')
+ for i := 0; i < a.Len(); i++ {
Review comment:
Yeah, so I think I've come around to how this is implemented. I think
what I was struggling with is an IntArray, gets serialized as `[1,2,3]` but one
could maybe think it should get serialized as something like `[[1],[2],[3]` or
`[{'entry':1}, {'entry':2}, {'entry': 3]` similar to what struct does). I
guess it is good if someone just wants to serialize/deserialize just an array
and not a record batch that it happens as a flat JSON list and the row by row
approach is taken for struct.
--
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]