zeroshade commented on code in PR #37788:
URL: https://github.com/apache/arrow/pull/37788#discussion_r1334820900
##########
go/arrow/cdata/cdata_exports.go:
##########
@@ -368,34 +368,37 @@ func exportArray(arr arrow.Array, out *CArrowArray,
outSchema *CArrowSchema) {
exportField(arrow.Field{Type: arr.DataType()}, outSchema)
}
+ nbuffers := len(arr.Data().Buffers())
+ buf_offset := 0
+ // Some types don't have validity bitmaps, but we keep them shifted
+ // to make processing easier in other contexts. This means that
+ // we have to adjust when exporting.
+ has_validity_bitmap :=
internal.DefaultHasValidityBitmap(arr.DataType().ID())
+ if nbuffers > 0 && !has_validity_bitmap {
+ nbuffers--
+ buf_offset++
+ }
+
out.dictionary = nil
out.null_count = C.int64_t(arr.NullN())
out.length = C.int64_t(arr.Len())
out.offset = C.int64_t(arr.Data().Offset())
- out.n_buffers = C.int64_t(len(arr.Data().Buffers()))
-
- if out.n_buffers > 0 {
- var (
- nbuffers = len(arr.Data().Buffers())
- bufs = arr.Data().Buffers()
- )
- // unions don't have validity bitmaps, but we keep them shifted
- // to make processing easier in other contexts. This means that
- // we have to adjust for union arrays
- if !internal.DefaultHasValidityBitmap(arr.DataType().ID()) {
- out.n_buffers--
- nbuffers--
- bufs = bufs[1:]
- }
+ out.n_buffers = C.int64_t(nbuffers)
+ out.buffers = nil
+
+ if nbuffers > 0 {
+ bufs := arr.Data().Buffers()
buffers := allocateBufferPtrArr(nbuffers)
- for i := range bufs {
- buf := bufs[i]
+ for i := 0; i < nbuffers; i++ {
Review Comment:
how so? The situations should be equivalent
if `len(bufs)` ==3, `buf_offset` == 1 and `nbuffers` == 2, your iterations
would be:
1. `i` == 0, `buf` == `bufs[1]`
2. `i` == 1, `buf` == `bufs[2]`
which would be the same regardless of if you use `for i := 0; i < nbuffers;
i++` or `for i, buf := range bufs[buf_offset:]`
right? or am i missing something?
--
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]