zeroshade commented on issue #34334:
URL: https://github.com/apache/arrow/issues/34334#issuecomment-1444126402
for the first question:
```go
case *arrow.ListType:
arr := col.(*array.List)
listVals, offsets := arr.ListValues(), arr.Offsets()
for i := 0; i < arr.Len(); i++ {
// values for list index i are the values of listVals from
// offsets[i] : offsets[i+1]
list := array.NewSlice(listVals, int64(offsets[i]),
int64(offsets[i+1]))
defer list.Release()
// list is now the slice of listVals containing only the values for
the list at index i
// do whatever you like with it
}
```
For another example of iterating a list array, you can look at the docs:
https://pkg.go.dev/github.com/apache/arrow/go/v11/[email protected]#example-package-ListArray
> Also, another question - why not use the native ToString / String in the
conversion here but rather re-implement a custom one in the writer -
https://github.com/apache/arrow/blob/main/go/arrow/csv/writer.go#L100
For the most part: custom null values and other customizations which don't
exist for the standard `String()` conversion but do exist for CSV writing.
There's also the customization of bool formatting.
Secondly, the way that the CSV writer works requires creating a slice of
`[][]string`, whereas the `String()` method on the array produces a Go-like
output of the array similar to what you'd get if it were a slice. i.e.: [0 1 2
3 4 5] as opposed to "0,1,2,3,4,5" which means if we use the standard
`String()` method on the array, we'd have to then re-parse/split the values to
get the `[][]string` that the CSV writer needs. It was easier to have the CSV
writer do its own conversion to string to avoid having to jump through those
hoops and allow possible future changes to the string representation without
risking breaking the CSV writer.
--
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]