pitrou commented on code in PR #37788:
URL: https://github.com/apache/arrow/pull/37788#discussion_r1334790896


##########
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:
   Hmm, but then the `i > 0` test below would be a bit more awkward to spell 
out.



-- 
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]

Reply via email to