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


##########
go/arrow/ipc/writer.go:
##########
@@ -724,6 +796,33 @@ func (w *recordEncoder) getZeroBasedValueOffsets(arr 
arrow.Array) (*memory.Buffe
        return voffsets, nil
 }
 
+func (w *recordEncoder) rebaseDenseUnionValueOffsets(arr *array.DenseUnion, 
offsets, lengths []int32) *memory.Buffer {
+       // this case sucks. Because the offsets are different for each
+       // child array, when we have a sliced array, we need to re-base
+       // the value offsets for each array! ew.
+       unshiftedOffsets := arr.RawValueOffsets()
+       codes := arr.RawTypeCodes()
+
+       shiftedOffsetsBuf := memory.NewResizableBuffer(w.mem)
+       shiftedOffsetsBuf.Resize(arrow.Int32Traits.BytesRequired(arr.Len()))
+       shiftedOffsets := 
arrow.Int32Traits.CastFromBytes(shiftedOffsetsBuf.Bytes())
+
+       // compute shifted offsets by subtracting child offset
+       for i, c := range codes {
+               if offsets[c] == -1 {
+                       // offsets are guaranteed to be increasing according to 
the spec
+                       // so the first offset we find for a child is the 
initial offset
+                       // and will become the "0" for this child.
+                       offsets[c] = unshiftedOffsets[i]
+                       shiftedOffsets[i] = 0
+               } else {
+                       shiftedOffsets[i] = unshiftedOffsets[i] - offsets[c]
+               }
+               lengths[c] = maxI32(lengths[c], shiftedOffsets[i]+1)
+       }

Review Comment:
   Looks great! This may serve as an inspiration for Arrow C++, in turn :-)



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